From b1c51cbe7782826b5088e0bdacb6863b536b4004 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Tue, 22 Oct 2024 14:12:27 -0700 Subject: [PATCH] Add initial query enhancement tests Signed-off-by: Qingyang(Abby) Hu --- .../dataset_navigator.spec.js | 174 ++++++++++++++++++ .../query_enhancement/queries.spec.js | 127 +++++++++++++ .../dashboards/data_explorer/commands.js | 47 +++++ 3 files changed, 348 insertions(+) create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/dataset_navigator.spec.js create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/queries.spec.js diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/dataset_navigator.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/dataset_navigator.spec.js new file mode 100644 index 000000000..0abefa856 --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/dataset_navigator.spec.js @@ -0,0 +1,174 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { + MiscUtils, + TestFixtureHandler, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../../../../utils/commands'; + +const miscUtils = new MiscUtils(cy); +const testFixtureHandler = new TestFixtureHandler( + cy, + Cypress.env('openSearchUrl') +); + +const indexSet = [ + 'logstash-2015.09.22', + 'logstash-2015.09.21', + 'logstash-2015.09.20', +]; + +describe('dataset navigator', { scrollBehavior: false }, () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + cy.fleshTenantSettings(); + cy.deleteAllIndices(); + cy.deleteSavedObjectByType('index-pattern'); + }); + + describe('empty state', () => { + it('no index pattern', function () { + // Go to the Discover page + miscUtils.visitPage( + `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` + ); + + cy.waitForLoaderNewHeader(); + cy.getElementByTestId('discoverNoIndexPatterns'); + }); + }); + + describe('select indices', () => { + before(() => { + // import logstash functional + testFixtureHandler.importJSONDocIfNeeded( + indexSet, + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt', + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt' + ); + + // Go to the Discover page + miscUtils.visitPage( + `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` + ); + }); + + it('with SQL as default language', function () { + cy.get(`[class~="datasetSelector__button"]`).click(); + cy.get(`[class~="datasetSelector__advancedButton"]`).click(); + cy.get(`[title="Indexes"]`).click(); + cy.get(`[title="Default Cluster"]`).click(); + cy.get(`[title="logstash-2015.09.20"]`).click(); + cy.getElementByTestId('datasetSelectorNext').click(); + + cy.get(`[class="euiModalHeader__title"]`).should( + 'contain', + 'Step 2: Configure data' + ); + // should have two options: SQL and PPL + cy.get('option').should('have.length', 2); + cy.getElementByTestId('advancedSelectorConfirmButton').click(); + + cy.waitForLoaderNewHeader(); + + // Selected language should be SQL + cy.getElementByTestId('queryEditorLanguageSelector').should( + 'contain', + 'SQL' + ); + + // The following steps are needed because when selecting SQL, discover loaded with data but the + // multi-line query editor are not loaded properly(it renders a single line query bar) unless we select SQL again + // This bug only exist in cypress test; can not reproduce manually + cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click(); + cy.get(`[class~="languageSelector__menuItem"]`) + .should('have.length', 2) + .eq(1) + .click({ + force: true, + }); + cy.waitForLoaderNewHeader(); + 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.waitForLoaderNewHeader(); + cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible'); + }); + + it('with PPL as default language', function () { + cy.get(`[class~="datasetSelector__button"]`).click(); + cy.get(`[class~="datasetSelector__advancedButton"]`).click(); + cy.get(`[title="Indexes"]`).click(); + cy.get(`[title="Default Cluster"]`).click(); + cy.get(`[title="logstash-2015.09.21"]`).click(); + cy.getElementByTestId('datasetSelectorNext').click(); + + cy.get(`[class="euiModalHeader__title"]`).should( + 'contain', + 'Step 2: Configure data' + ); + // should have two options: SQL and PPL; PPL should be selected + cy.getElementByTestId('advancedSelectorTimeFieldSelect').select( + '@timestamp' + ); + cy.getElementByTestId('advancedSelectorConfirmButton').click(); + + cy.waitForLoaderNewHeader(); + + // Selected language should be PPL + cy.getElementByTestId('queryEditorLanguageSelector').should( + 'contain', + 'PPL' + ); + + cy.waitForLoaderNewHeader(); + cy.getElementByTestId('queryResultCompleteMsg').should('be.visible'); + cy.getElementByTestId('queryEditorFooterTimestamp').should( + 'contain', + '@timestamp' + ); + + // Switch language to SQL + cy.getElementByTestId('queryEditorLanguageSelector').click(); + cy.get(`[class~="languageSelector__menuItem"]`).eq(1).click({ + force: true, + }); + cy.waitForLoaderNewHeader(); + cy.getElementByTestId('queryResultCompleteMsg').should('be.visible'); + cy.getElementByTestId('queryEditorFooterTimestamp').should( + 'contain', + '@timestamp' + ); + }); + }); + + describe('index pattern', () => { + it('create index pattern and select it', function () { + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.json.txt' + ); + + // Go to the Discover page + miscUtils.visitPage( + `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` + ); + + cy.get(`[class~="datasetSelector__button"]`).click(); + cy.getElementByTestId(`datasetOption-logstash-*`).click(); + + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); + cy.verifyHitCount('14,004'); + }); + }); +}); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/queries.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/queries.spec.js new file mode 100644 index 000000000..caffb229a --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/queries.spec.js @@ -0,0 +1,127 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { + MiscUtils, + TestFixtureHandler, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../../../../utils/commands'; + +const miscUtils = new MiscUtils(cy); +const testFixtureHandler = new TestFixtureHandler( + cy, + Cypress.env('openSearchUrl') +); + +const indexSet = [ + 'logstash-2015.09.22', + 'logstash-2015.09.21', + 'logstash-2015.09.20', +]; + +describe('query enhancement queries', { scrollBehavior: false }, () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + cy.fleshTenantSettings(); + cy.deleteAllIndices(); + cy.deleteSavedObjectByType('index-pattern'); + // import logstash functional + testFixtureHandler.importJSONDocIfNeeded( + indexSet, + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt', + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt' + ); + + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.json.txt' + ); + + // miscUtils.visitPage(`app/import_sample_data`); + // cy.getElementByTestId( + // 'addSampleDataSetecommerce' + // ).click(); + // cy.waitForLoaderNewHeader(); + + cy.setAdvancedSetting({ + defaultIndex: 'logstash-*', + }); + + // Go to the Discover page + miscUtils.visitPage( + `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` + ); + + cy.get(`[class~="datasetSelector__button"]`).click(); + cy.get(`[data-test-subj="datasetOption-logstash-*"]`).click(); + + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); + }); + + describe('send queries', () => { + it('with DQL', function () { + const query = `geo.src:FR`; + cy.setSingleLineQueryEditor(query); + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); + cy.verifyHitCount(119); + + //query should persist across refresh + cy.reload(); + cy.verifyHitCount(119); + }); + + it('with Lucene', function () { + cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click(); + cy.get(`[class~="languageSelector__menuItem"]`).eq(1).click({ + force: true, + }); + + const query = `geo.src:FR`; + cy.setSingleLineQueryEditor(query); + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); + cy.verifyHitCount(119); + + //query should persist across refresh + cy.reload(); + cy.verifyHitCount(119); + }); + + it('with PPL', function () { + cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click(); + cy.get(`[class~="languageSelector__menuItem"]`).eq(2).click({ + force: true, + }); + + // default PPL query should be set + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); + cy.verifyHitCount('14,004'); + + //query should persist across refresh + cy.reload(); + cy.verifyHitCount('14,004'); + }); + + it('with SQL', function () { + cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click(); + cy.get(`[class~="languageSelector__menuItem"]`).eq(3).click({ + force: true, + }); + + // default SQL query should be set + cy.waitForLoaderNewHeader(); + cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible'); + + //query should persist across refresh + cy.reload(); + cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible'); + }); + }); +}); diff --git a/cypress/utils/dashboards/data_explorer/commands.js b/cypress/utils/dashboards/data_explorer/commands.js index a0ccff2e2..a5dd70c77 100644 --- a/cypress/utils/dashboards/data_explorer/commands.js +++ b/cypress/utils/dashboards/data_explorer/commands.js @@ -168,3 +168,50 @@ 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); + } +});