From 37544c3e3aa249b77104a3681aa25f6775350307 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:33:28 -0700 Subject: [PATCH] Add basic test cases for dev tool console (#1204) (#1205) * Add basic test cases for console plugin Signed-off-by: Zhongnan Su * fix typo Signed-off-by: Zhongnan Su --------- Signed-off-by: Zhongnan Su (cherry picked from commit aa41ad40e7e88278f7745791caca60fefdfa35ad) Co-authored-by: Zhongnan Su --- .../console-plugin/console.spec.js | 84 +++++++++++++++++++ cypress/support/index.js | 1 + cypress/utils/dashboards/console/commands.js | 24 ++++++ .../utils/dashboards/vis_builder/commands.js | 2 +- 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/console-plugin/console.spec.js create mode 100644 cypress/utils/dashboards/console/commands.js diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/console-plugin/console.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/console-plugin/console.spec.js new file mode 100644 index 000000000..f6407432d --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/console-plugin/console.spec.js @@ -0,0 +1,84 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); + +describe('console app', () => { + const DEFAULT_REQUEST = `GET _search +{ + "query": { + "match_all": {} + } +}`.trim(); + + beforeEach(() => { + // Navigate to the console page before each test + miscUtils.visitPage('/app/dev_tools#/console'); + // Assuming there's a method to collapse the help pane in your page objects or you directly use a command here + cy.getElementByTestId('help-close-button').click({ force: true }); + cy.wait(1000); + }); + + it('should show the default request', () => { + // Get the request text and assert it matches the default request + // Adjust the selector to target the element containing the request + cy.getVisibleTextFromAceEditor('request-editor').should( + 'eq', + DEFAULT_REQUEST + ); + }); + + it('default request response should include `"timed_out" : false`', () => { + // Click the "Play" button to submit the request + // Adjust the selector as needed + cy.getElementByTestId('sendRequestButton').click(); + + // Check the response for the expected text + // Adjust the selector to target the element containing the response + cy.getElementByTestId('response-editor').should( + 'contain', + '"timed_out": false,' + ); + }); + + it('settings should allow changing the text size', () => { + // Navigate to settings and change the font size, then verify the change + // This assumes you have a way to navigate to settings and change them, possibly abstracted in commands + cy.changeConsoleFontSize(20); + cy.getElementByTestId('request-editor').should( + 'have.css', + 'font-size', + '20px' + ); + + cy.changeConsoleFontSize(24); + cy.getElementByTestId('request-editor').should( + 'have.css', + 'font-size', + '24px' + ); + }); + + it('should resize the editor', () => { + // Set initial window size + cy.viewport(1300, 1100); + + // Capture initial size + let initialWidth; + cy.get('.conApp').then(($editor) => { + initialWidth = $editor.width(); + }); + + // Change window size + cy.viewport(1000, 1100); + + // Assert that the editor width has decreased + cy.get('.conApp').should(($editor) => { + expect($editor.width()).to.be.lessThan(initialWidth); + }); + }); +}); diff --git a/cypress/support/index.js b/cypress/support/index.js index ef28be2d7..1a9f69562 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -31,6 +31,7 @@ import '../utils/plugins/security-analytics-dashboards-plugin/commands'; import '../utils/plugins/ml-commons-dashboards/commands'; import '../utils/plugins/notifications-dashboards/commands'; import '../utils/plugins/dashboards-assistant/commands'; +import '../utils/dashboards/console/commands'; import 'cypress-real-events'; diff --git a/cypress/utils/dashboards/console/commands.js b/cypress/utils/dashboards/console/commands.js new file mode 100644 index 000000000..35bab5cc8 --- /dev/null +++ b/cypress/utils/dashboards/console/commands.js @@ -0,0 +1,24 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +Cypress.Commands.add('getVisibleTextFromAceEditor', (editorSelector) => { + return cy + .getElementByTestId(editorSelector) + .find('.ace_line_group') + .then((lines) => { + const linesText = [...lines].map((line) => line.innerText); + return linesText.join('\n'); + }); +}); + +Cypress.Commands.add('changeConsoleFontSize', (size) => { + cy.getElementByTestId('consoleSettingsButton').click({ force: true }); + // Ensure the settings panel is open and ready + cy.getElementByTestId('setting-font-size-input', { timeout: 1000 }) + .type('{selectall}') + .type(size) + .should('have.value', size); + cy.get('[data-test-subj="settings-save-button"]').click(); +}); diff --git a/cypress/utils/dashboards/vis_builder/commands.js b/cypress/utils/dashboards/vis_builder/commands.js index fa2f74afe..9ab77ee3d 100644 --- a/cypress/utils/dashboards/vis_builder/commands.js +++ b/cypress/utils/dashboards/vis_builder/commands.js @@ -44,7 +44,7 @@ Cypress.Commands.add('vbEditAgg', (fields = []) => { }); fields.forEach(({ testSubj, type, value }) => { - // TODO: Impliment controls for other input types + // TODO: Implement controls for other input types switch (type) { case 'input': cy.getElementByTestId(testSubj)