From 64a54d406b9960ffc4f78e9ed5c3d7c8d67c4228 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Tue, 5 Nov 2024 13:25:21 -0800 Subject: [PATCH] address comments Signed-off-by: Qingyang(Abby) Hu --- .../dataset_navigator.spec.js | 69 +++++++++++-------- cypress/utils/dashboards/commands.js | 1 + cypress/utils/dashboards/constants.js | 1 + .../dashboards/data_explorer/commands.js | 47 ------------- .../dashboards/query_enhancement/commands.js | 47 +++++++++++++ .../dashboards/query_enhancement/constants.js | 7 ++ 6 files changed, 96 insertions(+), 76 deletions(-) create mode 100644 cypress/utils/dashboards/query_enhancement/commands.js create mode 100644 cypress/utils/dashboards/query_enhancement/constants.js diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/dataset_navigator.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/dataset_navigator.spec.js index a1b2065a0..899394d2c 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/dataset_navigator.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/dataset_navigator.spec.js @@ -7,6 +7,7 @@ import { TestFixtureHandler, } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; import { CURRENT_TENANT } from '../../../../../utils/commands'; +import { clusterName, clusterConnection } from '../../../../../utils/constants'; const miscUtils = new MiscUtils(cy); const testFixtureHandler = new TestFixtureHandler( @@ -26,6 +27,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.fleshTenantSettings(); cy.deleteAllIndices(); cy.deleteSavedObjectByType('index-pattern'); + cy.deleteSavedObjectByType('data-source'); }); describe('empty state', () => { @@ -50,6 +52,28 @@ describe('dataset navigator', { scrollBehavior: false }, () => { 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt' ); + // Since default cluster is removed, need to create a data source connection + miscUtils.visitPage( + 'app/management/opensearch-dashboards/dataSources/create' + ); + cy.intercept('POST', '/api/saved_objects/data-source').as( + 'createDataSourceRequest' + ); + cy.getElementByTestId(`datasource_card_opensearch`).click(); + cy.get('[name="dataSourceTitle"]').type(clusterName); + cy.get('[name="endpoint"]').type(clusterConnection); + cy.getElementByTestId('createDataSourceFormAuthTypeSelect').click(); + cy.get(`button[id="no_auth"]`).click(); + + cy.getElementByTestId('createDataSourceButton').click(); + cy.wait('@createDataSourceRequest').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.location('pathname', { timeout: 6000 }).should( + 'include', + 'app/management/opensearch-dashboards/dataSources' + ); + // Go to the Discover page miscUtils.visitPage(`app/data-explorer/discover#/`); @@ -60,7 +84,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.getElementByTestId(`datasetSelectorButton`).click(); cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Indexes"]`).click(); - cy.get(`[title="Default Cluster"]`).click(); + cy.get(`[title=${clusterName}]`).click(); cy.get(`[title="timestamp-nanos"]`).click(); cy.getElementByTestId('datasetSelectorNext').click(); @@ -74,33 +98,25 @@ describe('dataset navigator', { scrollBehavior: false }, () => { .should('have.length', 2); //select SQL - cy.getElementByTestId('advancedSelectorLanguageSelect').select('SQL'); + cy.getElementByTestId('advancedSelectorLanguageSelect').select( + 'OpenSearch SQL' + ); cy.getElementByTestId('advancedSelectorConfirmButton').click(); cy.waitForLoaderNewHeader(); - // Selected language in the language picker should be SQL - // bug: SQL won't be selected in cypress; manually click SQL in language selector - // cy.getElementByTestId('queryEditorLanguageSelector').should( - // 'contain', - // 'SQL' - // ); - - cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click(); - cy.get(`[class~="languageSelector__menuItem"]`) - .should('have.length', 2) - .eq(1) - .click({ - force: true, - }); + // SQL should already be selected + cy.getElementByTestId('queryEditorLanguageSelector').should( + 'contain', + 'OpenSearch SQL' + ); cy.waitForLoaderNewHeader(); + + // SQL query should be executed and sending back result cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible'); // Switch language to PPL - cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click(); - cy.get(`[class~="languageSelector__menuItem"]`).eq(0).click({ - force: true, - }); + cy.setQueryLanguage('PPL'); cy.waitForLoaderNewHeader(); cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible'); }); @@ -109,7 +125,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.getElementByTestId(`datasetSelectorButton`).click(); cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Indexes"]`).click(); - cy.get(`[title="Default Cluster"]`).click(); + cy.get(`[title=${clusterName}]`).click(); cy.get(`[title="timestamp-nanos"]`).click(); cy.getElementByTestId('datasetSelectorNext').click(); @@ -128,7 +144,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.waitForLoaderNewHeader(); - // Selected language should be PPL + // PPL should already be selected cy.getElementByTestId('queryEditorLanguageSelector').should( 'contain', 'PPL' @@ -148,13 +164,8 @@ describe('dataset navigator', { scrollBehavior: false }, () => { ); // Switch language to SQL - cy.getElementByTestId('queryEditorLanguageSelector').click(); - cy.get(`[class~="languageSelector__menuItem"]`) - .should('have.length', 2) - .eq(1) - .click({ - force: true, - }); + cy.setQueryLanguage('OpenSearch SQL'); + cy.waitForLoaderNewHeader(); cy.getElementByTestId('queryResultCompleteMsg').should('be.visible'); cy.getElementByTestId('queryEditorFooterTimestamp').should( diff --git a/cypress/utils/dashboards/commands.js b/cypress/utils/dashboards/commands.js index bbabd73f1..fd92e5cd4 100644 --- a/cypress/utils/dashboards/commands.js +++ b/cypress/utils/dashboards/commands.js @@ -9,6 +9,7 @@ import './vis_type_table/commands'; import './vis_type_vega/commands'; import './vis-augmenter/commands'; import './data_explorer/commands'; +import './query_enhancement/commands'; Cypress.Commands.add('waitForLoader', () => { const opts = { log: false }; diff --git a/cypress/utils/dashboards/constants.js b/cypress/utils/dashboards/constants.js index 4079a5235..92e4d3baa 100644 --- a/cypress/utils/dashboards/constants.js +++ b/cypress/utils/dashboards/constants.js @@ -24,3 +24,4 @@ export * from './vis_type_timeline/constants'; export * from './vis-augmenter/constants'; export * from './data_explorer/constants'; export * from './vis_type_vega/constants'; +export * from './query_enhancement/constants'; diff --git a/cypress/utils/dashboards/data_explorer/commands.js b/cypress/utils/dashboards/data_explorer/commands.js index a5dd70c77..a0ccff2e2 100644 --- a/cypress/utils/dashboards/data_explorer/commands.js +++ b/cypress/utils/dashboards/data_explorer/commands.js @@ -168,50 +168,3 @@ function checkForElementVisibility() { } }); } - -Cypress.Commands.add('waitForLoaderNewHeader', () => { - const opts = { log: false }; - - Cypress.log({ - name: 'waitForPageLoad', - displayName: 'wait', - message: 'page load', - }); - cy.wait(Cypress.env('WAIT_FOR_LOADER_BUFFER_MS')); - cy.getElementByTestId('recentItemsSectionButton', opts); -}); - -Cypress.Commands.add('setSingleLineQueryEditor', (value, submit = true) => { - const opts = { log: false }; - - Cypress.log({ - name: 'setSingleLineQueryEditor', - displayName: 'set query', - message: value, - }); - - cy.getElementByTestId('osdQueryEditor__singleLine', opts).type(value, opts); - - if (submit) { - cy.updateTopNav(opts); - } -}); - -Cypress.Commands.add('setMultiLineQueryEditor', (value, submit = true) => { - const opts = { log: false }; - - Cypress.log({ - name: 'setMultiLineQueryEditor', - displayName: 'set query', - message: value, - }); - - cy.getElementByTestId('osdQueryEditor__multiLine', opts) - .clear(opts) - .type(value, opts) - .blur(opts); - - if (submit) { - cy.updateTopNav(opts); - } -}); diff --git a/cypress/utils/dashboards/query_enhancement/commands.js b/cypress/utils/dashboards/query_enhancement/commands.js new file mode 100644 index 000000000..88f852c9b --- /dev/null +++ b/cypress/utils/dashboards/query_enhancement/commands.js @@ -0,0 +1,47 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +Cypress.Commands.add('waitForLoaderNewHeader', () => { + const opts = { log: false }; + + Cypress.log({ + name: 'waitForPageLoad', + displayName: 'wait', + message: 'page load', + }); + cy.wait(Cypress.env('WAIT_FOR_LOADER_BUFFER_MS')); + cy.getElementByTestId('recentItemsSectionButton', opts); +}); + +Cypress.Commands.add('setSingleLineQueryEditor', (value, submit = true) => { + const opts = { log: false }; + + Cypress.log({ + name: 'setSingleLineQueryEditor', + displayName: 'set query', + message: value, + }); + + cy.getElementByTestId('osdQueryEditor__singleLine', opts).type(value, opts); + + if (submit) { + cy.updateTopNav(opts); + } +}); + +Cypress.Commands.add('setQueryLanguage', (value, submit = true) => { + const opts = { log: false }; + + Cypress.log({ + name: 'setQueryLanguage', + displayName: 'set language', + message: value, + }); + + cy.getElementByTestId(`queryEditorLanguageSelector`).click(); + cy.get(`[class~="languageSelector__menuItem"]`).contains(value).click({ + force: true, + }); +}); diff --git a/cypress/utils/dashboards/query_enhancement/constants.js b/cypress/utils/dashboards/query_enhancement/constants.js new file mode 100644 index 000000000..62d6c0ffb --- /dev/null +++ b/cypress/utils/dashboards/query_enhancement/constants.js @@ -0,0 +1,7 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export const clusterName = 'test_cluster'; +export const clusterConnection = 'http://localhost:9200';