From 150d875d304689aa7b457dce8c6e27a837975854 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Tue, 5 Nov 2024 22:53:04 -0800 Subject: [PATCH 1/9] add reload to PPL Signed-off-by: Qingyang(Abby) Hu --- .../apps/query_enhancement/queries.spec.js | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js new file mode 100644 index 000000000..cf214cdca --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js @@ -0,0 +1,126 @@ +/* + * 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'); + + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data_with_index_pattern.json.txt' + ); + + // Go to the Discover page + miscUtils.visitPage(`app/data-explorer/discover#/`); + + cy.setAdvancedSetting({ + defaultIndex: 'timestamp-*', + }); + + // Go to the Discover page + miscUtils.visitPage( + `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2018-09-19T13:31:44.000Z',to:'2019-09-24T01:31:44.000Z'))` + ); + + cy.get(`[class~="datasetSelector__button"]`).click(); + cy.get(`[data-test-subj="datasetOption-timestamp-*"]`).click(); + + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); + }); + + describe('send queries', () => { + it('with DQL', function () { + const query = `_id:1`; + cy.setSingleLineQueryEditor(query); + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); + cy.verifyHitCount(1); + + //query should persist across refresh + cy.reload(); + cy.verifyHitCount(1); + }); + + it('with Lucene', function () { + cy.setQueryLanguage('Lucene'); + + const query = `_id:1`; + cy.setSingleLineQueryEditor(query); + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); + cy.verifyHitCount(1); + + //query should persist across refresh + cy.reload(); + cy.verifyHitCount(1); + }); + + it('with SQL', function () { + cy.setQueryLanguage('OpenSearch SQL'); + + // default SQL query should be set + cy.waitForLoaderNewHeader(); + cy.getElementByTestId(`osdQueryEditor__multiLine`).contains( + `SELECT * FROM timestamp-* LIMIT 10` + ); + cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible'); + + //query should persist across refresh + cy.reload(); + cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible'); + + cy.getElementByTestId(`osdQueryEditor__multiLine`).type(`{backspace}`); + cy.getElementByTestId(`querySubmitButton`).click(); + cy.waitForSearch(); + cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible'); + }); + + it('with PPL', function () { + cy.setQueryLanguage('PPL'); + + // default PPL query should be set + cy.waitForLoaderNewHeader(); + cy.getElementByTestId(`osdQueryEditor__multiLine`).contains( + `source = timestamp-* | head 10` + ); + cy.reload(); + cy.waitForSearch(); + cy.verifyHitCount(4); + + //query should persist across refresh + cy.reload(); + cy.verifyHitCount(4); + + cy.getElementByTestId(`osdQueryEditor__multiLine`).type(`{backspace}`); + cy.getElementByTestId(`querySubmitButton`).click(); + cy.waitForSearch(); + cy.verifyHitCount(1); + }); + }); +}); From 90eed618a30cc06f0610a2e9350474fa5ccb9350 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Tue, 22 Oct 2024 14:12:27 -0700 Subject: [PATCH 2/9] 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); + } +}); From 20c0be6b3a22e51115900078c03f51b2e44b85c5 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Tue, 22 Oct 2024 16:02:21 -0700 Subject: [PATCH 3/9] Add ciGroup10 Signed-off-by: Qingyang(Abby) Hu --- .../query_enhancement/queries.spec.js | 127 ------------------ .../dataset_navigator.spec.js | 2 +- .../apps/query_enhancement/queries.spec.js | 4 +- package.json | 1 + 4 files changed, 5 insertions(+), 129 deletions(-) delete mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/queries.spec.js rename cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/{data_explorer => }/query_enhancement/dataset_navigator.spec.js (98%) 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 deleted file mode 100644 index caffb229a..000000000 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/queries.spec.js +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/dataset_navigator.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/dataset_navigator.spec.js similarity index 98% rename from cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/query_enhancement/dataset_navigator.spec.js rename to cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/dataset_navigator.spec.js index 0abefa856..6cebc3555 100644 --- 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/query_enhancement/dataset_navigator.spec.js @@ -6,7 +6,7 @@ import { MiscUtils, TestFixtureHandler, } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; -import { CURRENT_TENANT } from '../../../../../../utils/commands'; +import { CURRENT_TENANT } from '../../../../../utils/commands'; const miscUtils = new MiscUtils(cy); const testFixtureHandler = new TestFixtureHandler( diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js index cf214cdca..a54924dda 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js @@ -109,8 +109,10 @@ describe('query enhancement queries', { scrollBehavior: false }, () => { cy.getElementByTestId(`osdQueryEditor__multiLine`).contains( `source = timestamp-* | head 10` ); - cy.reload(); cy.waitForSearch(); + cy.reload(); + cy.getElementByTestId('queryResultCompleteMsg').click() + cy.get('[class="euiText euiText--small"]').then((text) => cy.log(text)) cy.verifyHitCount(4); //query should persist across refresh diff --git a/package.json b/package.json index 59d66bc47..d65454e71 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "osd:ciGroup7": "echo apps/data_explorer/aaa_before.spec.js,apps/data_explorer/doc_navigation.spec.js,apps/data_explorer/doc_table.spec.js,apps/data_explorer/errors.spec.js,apps/data_explorer/field_data.spec.js,apps/data_explorer/zzz_after.spec.js", "osd:ciGroup8": "echo apps/data_explorer/aaa_before.spec.js,apps/data_explorer/field_visualize.spec.js,apps/data_explorer/filter_editor.spec.js,apps/data_explorer/index_pattern_with_encoded_id.spec.js,apps/data_explorer/index_pattern_without_field.spec.js,apps/data_explorer/zzz_after.spec.js", "osd:ciGroup9": "echo apps/data_explorer/aaa_before.spec.js,apps/data_explorer/inspector.spec.js,apps/data_explorer/large_string.spec.js,apps/data_explorer/saved_queries.spec.js,apps/data_explorer/shared_links.spec.js,apps/data_explorer/sidebar.spec.js,apps/data_explorer/source_filter.spec.js,apps/data_explorer/zzz_after.spec.js", + "osd:ciGroup10": "echo apps/query_enhancement/*.js", "start-dummy-llm-server": "node ./cypress/support/assistant-dummy-llm.js" }, "repository": { From cf9d7453f06def465be7920c72f16b9e1b110c78 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Fri, 25 Oct 2024 00:46:06 -0700 Subject: [PATCH 4/9] modify queries test Signed-off-by: Qingyang(Abby) Hu --- .../query_enhancement/data.json.txt | 23 ++++ .../data_with_index_pattern.json.txt | 65 ++++++++++ .../query_enhancement/mappings.json.txt | 45 +++++++ .../dataset_navigator.spec.js | 40 +++++-- .../query_enhancement/easy_queries.spec.js | 113 ++++++++++++++++++ 5 files changed, 275 insertions(+), 11 deletions(-) create mode 100644 cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt create mode 100644 cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data_with_index_pattern.json.txt create mode 100644 cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/easy_queries.spec.js diff --git a/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt b/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt new file mode 100644 index 000000000..2cd7ad0d3 --- /dev/null +++ b/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt @@ -0,0 +1,23 @@ +{ + "type": "doc", + "value": { + "id": "3", + "index": "timestamp-nanos", + "source": { + "timestamp": "2019-01-01T12:10:30.123456789Z" + }, + "type": "_doc" + } +} + +{ + "type": "doc", + "value": { + "id": "4", + "index": "timestamp-nanos", + "source": { + "timestamp": "2019-01-01T12:10:30.123498765Z" + }, + "type": "_doc" + } +} diff --git a/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data_with_index_pattern.json.txt b/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data_with_index_pattern.json.txt new file mode 100644 index 000000000..b1284b91f --- /dev/null +++ b/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data_with_index_pattern.json.txt @@ -0,0 +1,65 @@ +{ + "type": "doc", + "value": { + "id": "index-pattern:timestamp-*", + "index": ".kibana", + "source": { + "index-pattern": { + "fields": "[{\"name\":\"_id\",\"type\":\"string\",\"esTypes\":[\"_id\"],\"count\":1,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"_index\",\"type\":\"string\",\"esTypes\":[\"_index\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"_score\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"name\":\"_source\",\"type\":\"_source\",\"esTypes\":[\"_source\"],\"count\":0,\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"name\":\"_type\",\"type\":\"string\",\"esTypes\":[\"_type\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"timestamp\",\"type\":\"date\",\"esTypes\":[\"date\",\"date_nanos\"],\"count\":2,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]", + "timeFieldName": "timestamp", + "title": "timestamp-*", + "fieldFormatMap": "{\"timestamp\":{\"id\":\"date_nanos\"}}" + }, + "type": "index-pattern" + }, + "type": "_doc" + } +} + +{ + "type": "doc", + "value": { + "id": "2", + "index": "timestamp-millis", + "source": { + "timestamp": "2019-01-01T12:10:30.124Z" + }, + "type": "_doc" + } +} + +{ + "type": "doc", + "value": { + "id": "1", + "index": "timestamp-millis", + "source": { + "timestamp": "2019-01-01T12:10:30.123Z" + }, + "type": "_doc" + } +} + +{ + "type": "doc", + "value": { + "id": "3", + "index": "timestamp-nanos", + "source": { + "timestamp": "2019-01-01T12:10:30.123456789Z" + }, + "type": "_doc" + } +} + +{ + "type": "doc", + "value": { + "id": "4", + "index": "timestamp-nanos", + "source": { + "timestamp": "2019-01-02T12:10:30.123498765Z" + }, + "type": "_doc" + } +} diff --git a/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt b/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt new file mode 100644 index 000000000..eaeaeee37 --- /dev/null +++ b/cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt @@ -0,0 +1,45 @@ +{ + "type": "index", + "value": { + "aliases": { + }, + "index": "timestamp-millis", + "mappings": { + "properties": { + "timestamp": { + "type": "date" + } + } + }, + "settings": { + "index": { + "number_of_replicas": "1", + "number_of_shards": "1", + "codec": "best_compression" + } + } + } +} + +{ + "type": "index", + "value": { + "aliases": { + }, + "index": "timestamp-nanos", + "mappings": { + "properties": { + "timestamp": { + "type": "date_nanos" + } + } + }, + "settings": { + "index": { + "number_of_replicas": "1", + "number_of_shards": "1", + "codec": "best_compression" + } + } + } +} 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 6cebc3555..55a2b1a63 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 @@ -56,8 +56,8 @@ describe('dataset navigator', { scrollBehavior: false }, () => { }); it('with SQL as default language', function () { - cy.get(`[class~="datasetSelector__button"]`).click(); - cy.get(`[class~="datasetSelector__advancedButton"]`).click(); + cy.getElementByTestId(`datasetSelectorButton`).click(); + cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Indexes"]`).click(); cy.get(`[title="Default Cluster"]`).click(); cy.get(`[title="logstash-2015.09.20"]`).click(); @@ -68,12 +68,17 @@ describe('dataset navigator', { scrollBehavior: false }, () => { 'Step 2: Configure data' ); // should have two options: SQL and PPL - cy.get('option').should('have.length', 2); + cy.getElementByTestId('advancedSelectorLanguageSelect') + .get('option') + .should('have.length', 2); + + //select SQL + cy.getElementByTestId('advancedSelectorLanguageSelect').select('SQL'); cy.getElementByTestId('advancedSelectorConfirmButton').click(); cy.waitForLoaderNewHeader(); - // Selected language should be SQL + // Selected language in the language picker should be SQL cy.getElementByTestId('queryEditorLanguageSelector').should( 'contain', 'SQL' @@ -102,8 +107,8 @@ describe('dataset navigator', { scrollBehavior: false }, () => { }); it('with PPL as default language', function () { - cy.get(`[class~="datasetSelector__button"]`).click(); - cy.get(`[class~="datasetSelector__advancedButton"]`).click(); + cy.getElementByTestId(`datasetSelectorButton`).click(); + cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Indexes"]`).click(); cy.get(`[title="Default Cluster"]`).click(); cy.get(`[title="logstash-2015.09.21"]`).click(); @@ -113,8 +118,16 @@ describe('dataset navigator', { scrollBehavior: false }, () => { 'contain', 'Step 2: Configure data' ); - // should have two options: SQL and PPL; PPL should be selected - cy.getElementByTestId('advancedSelectorTimeFieldSelect').select( + + // should have two options: SQL and PPL + cy.getElementByTestId('advancedSelectorLanguageSelect') + .get('option') + .should('have.length', 2); + + //select PPL + cy.getElementByTestId('advancedSelectorLanguageSelect').select('PPL'); + + cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select( '@timestamp' ); cy.getElementByTestId('advancedSelectorConfirmButton').click(); @@ -128,6 +141,8 @@ describe('dataset navigator', { scrollBehavior: false }, () => { ); cy.waitForLoaderNewHeader(); + + // Query should finish running with timestamp and finish time in the footer cy.getElementByTestId('queryResultCompleteMsg').should('be.visible'); cy.getElementByTestId('queryEditorFooterTimestamp').should( 'contain', @@ -136,9 +151,12 @@ describe('dataset navigator', { scrollBehavior: false }, () => { // Switch language to SQL cy.getElementByTestId('queryEditorLanguageSelector').click(); - cy.get(`[class~="languageSelector__menuItem"]`).eq(1).click({ - force: true, - }); + cy.get(`[class~="languageSelector__menuItem"]`) + .should('have.length', 2) + .eq(1) + .click({ + force: true, + }); cy.waitForLoaderNewHeader(); cy.getElementByTestId('queryResultCompleteMsg').should('be.visible'); cy.getElementByTestId('queryEditorFooterTimestamp').should( diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/easy_queries.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/easy_queries.spec.js new file mode 100644 index 000000000..51058719d --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/easy_queries.spec.js @@ -0,0 +1,113 @@ +/* + * 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 = ['query-enhance']; + +describe('query enhancement queries', { scrollBehavior: false }, () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + cy.fleshTenantSettings(); + cy.deleteAllIndices(); + cy.deleteSavedObjectByType('index-pattern'); + + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt' + ); + + // Go to the Discover page + miscUtils.visitPage(`app/data-explorer/discover#/`); + + cy.waitForLoaderNewHeader(); + }); + + describe('send queries', () => { + it.skip('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.skip('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 SQL', function () { + cy.getElementByTestId(`datasetSelectorButton`).click(); + cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); + cy.get(`[title="Indexes"]`).click(); + cy.get(`[title="Default Cluster"]`).click(); + cy.get(`[title="timestamp-nanos"]`).click(); + cy.getElementByTestId('datasetSelectorNext').click(); + + cy.get(`[class="euiModalHeader__title"]`).should( + 'contain', + 'Step 2: Configure data' + ); + // should have two options: SQL and PPL + cy.getElementByTestId('advancedSelectorLanguageSelect') + .get('option') + .should('have.length', 2); + + //select SQL + cy.getElementByTestId('advancedSelectorLanguageSelect').select('PPL'); + cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select( + 'timestamp' + ); + cy.getElementByTestId('advancedSelectorConfirmButton').click(); + + cy.waitForLoaderNewHeader(); + cy.reload(); + }); + + it.skip('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'); + }); + }); +}); From 33400f358a5626f3d681eb58c59aac195d370d82 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Fri, 25 Oct 2024 01:25:46 -0700 Subject: [PATCH 5/9] fix tests Signed-off-by: Qingyang(Abby) Hu --- .../dataset_navigator.spec.js | 46 +++---- .../query_enhancement/easy_queries.spec.js | 113 ------------------ 2 files changed, 23 insertions(+), 136 deletions(-) delete mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/easy_queries.spec.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 55a2b1a63..7b75aef35 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 @@ -42,17 +42,18 @@ describe('dataset navigator', { scrollBehavior: false }, () => { 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' + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.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'))` + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt' ); + + // Go to the Discover page + miscUtils.visitPage(`app/data-explorer/discover#/`); + + cy.waitForLoaderNewHeader(); }); it('with SQL as default language', function () { @@ -60,7 +61,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Indexes"]`).click(); cy.get(`[title="Default Cluster"]`).click(); - cy.get(`[title="logstash-2015.09.20"]`).click(); + cy.get(`[title="timestamp-nanos"]`).click(); cy.getElementByTestId('datasetSelectorNext').click(); cy.get(`[class="euiModalHeader__title"]`).should( @@ -79,10 +80,10 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.waitForLoaderNewHeader(); // Selected language in the language picker should be SQL - cy.getElementByTestId('queryEditorLanguageSelector').should( - 'contain', - '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 @@ -111,7 +112,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Indexes"]`).click(); cy.get(`[title="Default Cluster"]`).click(); - cy.get(`[title="logstash-2015.09.21"]`).click(); + cy.get(`[title="timestamp-nanos"]`).click(); cy.getElementByTestId('datasetSelectorNext').click(); cy.get(`[class="euiModalHeader__title"]`).should( @@ -119,16 +120,11 @@ describe('dataset navigator', { scrollBehavior: false }, () => { 'Step 2: Configure data' ); - // should have two options: SQL and PPL - cy.getElementByTestId('advancedSelectorLanguageSelect') - .get('option') - .should('have.length', 2); - //select PPL cy.getElementByTestId('advancedSelectorLanguageSelect').select('PPL'); cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select( - '@timestamp' + 'timestamp' ); cy.getElementByTestId('advancedSelectorConfirmButton').click(); @@ -140,13 +136,17 @@ describe('dataset navigator', { scrollBehavior: false }, () => { 'PPL' ); + const fromTime = 'Sep 19, 2018 @ 00:00:00.000'; + const toTime = 'Sep 21, 2019 @ 00:00:00.000'; + cy.setTopNavDate(fromTime, toTime); + cy.waitForLoaderNewHeader(); // Query should finish running with timestamp and finish time in the footer cy.getElementByTestId('queryResultCompleteMsg').should('be.visible'); cy.getElementByTestId('queryEditorFooterTimestamp').should( 'contain', - '@timestamp' + 'timestamp' ); // Switch language to SQL @@ -161,7 +161,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.getElementByTestId('queryResultCompleteMsg').should('be.visible'); cy.getElementByTestId('queryEditorFooterTimestamp').should( 'contain', - '@timestamp' + 'timestamp' ); }); }); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/easy_queries.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/easy_queries.spec.js deleted file mode 100644 index 51058719d..000000000 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/easy_queries.spec.js +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 = ['query-enhance']; - -describe('query enhancement queries', { scrollBehavior: false }, () => { - before(() => { - CURRENT_TENANT.newTenant = 'global'; - cy.fleshTenantSettings(); - cy.deleteAllIndices(); - cy.deleteSavedObjectByType('index-pattern'); - - testFixtureHandler.importJSONMapping( - 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt' - ); - - testFixtureHandler.importJSONDoc( - 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt' - ); - - // Go to the Discover page - miscUtils.visitPage(`app/data-explorer/discover#/`); - - cy.waitForLoaderNewHeader(); - }); - - describe('send queries', () => { - it.skip('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.skip('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 SQL', function () { - cy.getElementByTestId(`datasetSelectorButton`).click(); - cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); - cy.get(`[title="Indexes"]`).click(); - cy.get(`[title="Default Cluster"]`).click(); - cy.get(`[title="timestamp-nanos"]`).click(); - cy.getElementByTestId('datasetSelectorNext').click(); - - cy.get(`[class="euiModalHeader__title"]`).should( - 'contain', - 'Step 2: Configure data' - ); - // should have two options: SQL and PPL - cy.getElementByTestId('advancedSelectorLanguageSelect') - .get('option') - .should('have.length', 2); - - //select SQL - cy.getElementByTestId('advancedSelectorLanguageSelect').select('PPL'); - cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select( - 'timestamp' - ); - cy.getElementByTestId('advancedSelectorConfirmButton').click(); - - cy.waitForLoaderNewHeader(); - cy.reload(); - }); - - it.skip('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'); - }); - }); -}); From d9dbe42c84944c5164c6a6611e9a59d7b1fce4f8 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Fri, 25 Oct 2024 02:04:29 -0700 Subject: [PATCH 6/9] fix one more test Signed-off-by: Qingyang(Abby) Hu --- .../query_enhancement/dataset_navigator.spec.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 7b75aef35..a1b2065a0 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 @@ -45,14 +45,14 @@ describe('dataset navigator', { scrollBehavior: false }, () => { testFixtureHandler.importJSONMapping( 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt' ); - + testFixtureHandler.importJSONDoc( 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt' ); - + // Go to the Discover page miscUtils.visitPage(`app/data-explorer/discover#/`); - + cy.waitForLoaderNewHeader(); }); @@ -80,14 +80,12 @@ describe('dataset navigator', { scrollBehavior: false }, () => { 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' // ); - // 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) @@ -168,6 +166,12 @@ describe('dataset navigator', { scrollBehavior: false }, () => { describe('index pattern', () => { it('create index pattern and select it', function () { + // 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' ); From 64a54d406b9960ffc4f78e9ed5c3d7c8d67c4228 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Tue, 5 Nov 2024 13:25:21 -0800 Subject: [PATCH 7/9] 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'; From c470b28bcedd523daa0183d439fad753b5dfe1bb Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Thu, 7 Nov 2024 13:57:12 -0800 Subject: [PATCH 8/9] remove deleteAll Signed-off-by: Qingyang(Abby) Hu --- .../dataset_navigator.spec.js | 8 +++++--- .../apps/query_enhancement/queries.spec.js | 18 ++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) 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 899394d2c..a584877d7 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 @@ -25,9 +25,6 @@ describe('dataset navigator', { scrollBehavior: false }, () => { before(() => { CURRENT_TENANT.newTenant = 'global'; cy.fleshTenantSettings(); - cy.deleteAllIndices(); - cy.deleteSavedObjectByType('index-pattern'); - cy.deleteSavedObjectByType('data-source'); }); describe('empty state', () => { @@ -204,4 +201,9 @@ describe('dataset navigator', { scrollBehavior: false }, () => { cy.verifyHitCount('14,004'); }); }); + + after(() => { + cy.deleteIndex('timestamp-nanos'); + cy.deleteSavedObject('data-source', clusterName); + }); }); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js index a54924dda..d8a076c5b 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/queries.spec.js @@ -24,8 +24,6 @@ describe('query enhancement queries', { scrollBehavior: false }, () => { before(() => { CURRENT_TENANT.newTenant = 'global'; cy.fleshTenantSettings(); - cy.deleteAllIndices(); - cy.deleteSavedObjectByType('index-pattern'); testFixtureHandler.importJSONMapping( 'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt' @@ -107,22 +105,22 @@ describe('query enhancement queries', { scrollBehavior: false }, () => { // default PPL query should be set cy.waitForLoaderNewHeader(); cy.getElementByTestId(`osdQueryEditor__multiLine`).contains( - `source = timestamp-* | head 10` + `source = timestamp-*` ); cy.waitForSearch(); - cy.reload(); - cy.getElementByTestId('queryResultCompleteMsg').click() - cy.get('[class="euiText euiText--small"]').then((text) => cy.log(text)) + cy.getElementByTestId('queryResultCompleteMsg').click(); + cy.get('[class="euiText euiText--small"]').then((text) => cy.log(text)); cy.verifyHitCount(4); //query should persist across refresh cy.reload(); cy.verifyHitCount(4); + }); - cy.getElementByTestId(`osdQueryEditor__multiLine`).type(`{backspace}`); - cy.getElementByTestId(`querySubmitButton`).click(); - cy.waitForSearch(); - cy.verifyHitCount(1); + after(() => { + cy.deleteIndex('timestamp-nanos'); + cy.deleteIndex('timestamp-milis'); + cy.deleteSavedObject('index-pattern', 'index-pattern:timestamp-*'); }); }); }); From 27cc91235dcb7579356a9831d69ae77b822c3a62 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Thu, 7 Nov 2024 14:09:16 -0800 Subject: [PATCH 9/9] delete data source connection Signed-off-by: Qingyang(Abby) Hu --- .../apps/query_enhancement/dataset_navigator.spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 a584877d7..71dc1f92a 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 @@ -204,6 +204,10 @@ describe('dataset navigator', { scrollBehavior: false }, () => { after(() => { cy.deleteIndex('timestamp-nanos'); - cy.deleteSavedObject('data-source', clusterName); + // delete the data source connection + miscUtils.visitPage('app/management/opensearch-dashboards/dataSources/'); + cy.get(`[class="euiTableRowCell"]`).contains(clusterName).click(); + cy.getElementByTestId('editDatasourceDeleteIcon').click(); + cy.getElementByTestId('confirmModalConfirmButton').click(); }); });