From 66331eb0269bb4fce7c49bde674d40c71735bdb7 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Fri, 20 Dec 2024 15:19:47 -0800 Subject: [PATCH] Re-enable dataset_selector.spec.js and queries.spec.js under workspace (#9082) * Re-enable dataset_selector.spec.js and queries.spec.js under workspace Signed-off-by: Anan * fix comment Signed-off-by: Anan * add verifyHitCount for PPL Signed-off-by: Anan * Changeset file for PR #9082 created/updated --------- Signed-off-by: Anan Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/9082.yml | 2 + .../apps/query_enhancements/constants.js | 2 + .../dataset_selector.spec.js | 122 +++++++----------- .../apps/query_enhancements/queries.spec.js | 83 ++++++------ cypress/support/e2e.js | 9 ++ cypress/utils/commands.js | 9 +- cypress/utils/constants.js | 2 +- cypress/utils/dashboards/commands.js | 36 +++--- package.json | 2 +- 9 files changed, 135 insertions(+), 132 deletions(-) create mode 100644 changelogs/fragments/9082.yml diff --git a/changelogs/fragments/9082.yml b/changelogs/fragments/9082.yml new file mode 100644 index 000000000000..407bb11ab705 --- /dev/null +++ b/changelogs/fragments/9082.yml @@ -0,0 +1,2 @@ +test: +- Re-enable dataset_selector.spec.js under workspace in ciGroup10 ([#9082](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9082)) \ No newline at end of file diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/constants.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/constants.js index 746515c5bf0a..b59f85ec4f48 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/constants.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/constants.js @@ -5,3 +5,5 @@ export const DATASOURCE_NAME = 'query-cluster'; export const WORKSPACE_NAME = 'query-workspace'; +export const START_TIME = 'Jan 1, 2020 @ 00:00:00.000'; +export const END_TIME = 'Jan 1, 2024 @ 00:00:00.000'; diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/dataset_selector.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/dataset_selector.spec.js index 38ff03888a2d..cf0144e08b6c 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/dataset_selector.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/dataset_selector.spec.js @@ -2,65 +2,47 @@ * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ -import { - MiscUtils, - TestFixtureHandler, -} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; -import { PATHS, SECONDARY_ENGINE } from '../../../../../utils/constants'; - -const miscUtils = new MiscUtils(cy); -const testFixtureHandler = new TestFixtureHandler(cy, PATHS.ENGINE); - -describe.skip('dataset selector', { scrollBehavior: false }, () => { - 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.waitForLoader(true); - cy.getElementByTestId('discoverNoIndexPatterns'); +import { WORKSPACE_NAME, DATASOURCE_NAME, START_TIME, END_TIME } from './constants'; +import { BASE_PATH, SECONDARY_ENGINE } from '../../../../../utils/constants'; + +describe('dataset selector', { scrollBehavior: false }, () => { + before(() => { + cy.setupTestData( + SECONDARY_ENGINE.url, + ['cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.mapping.json'], + ['cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.data.ndjson'] + ); + + // Add data source + cy.addDataSource({ + name: `${DATASOURCE_NAME}`, + url: `${SECONDARY_ENGINE.url}`, + authType: 'no_auth', }); }); + after(() => { + cy.deleteDataSourceByName(`${DATASOURCE_NAME}`); + cy.deleteIndex('data_logs_small_time_1'); + }); + beforeEach(() => { + // Create workspace + cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`); + cy.visit('/app/home'); + cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${WORKSPACE_NAME}`); + }); - describe('select indices', () => { - before(() => { - testFixtureHandler.importJSONMapping('cypress/fixtures/timestamp/mappings.json.txt'); - - testFixtureHandler.importJSONDoc('cypress/fixtures/timestamp/data.json.txt'); - - // Since default cluster is removed, need to create a data source connection if needed - 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(SECONDARY_ENGINE.name); - cy.get('[name="endpoint"]').type(SECONDARY_ENGINE.url); - 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#/`); - - cy.waitForLoader(true); - }); + afterEach(() => { + cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`); + }); + describe('select indices', () => { it('with SQL as default language', function () { cy.getElementByTestId(`datasetSelectorButton`).click(); cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Indexes"]`).click(); - cy.get(`[title=${SECONDARY_ENGINE.name}]`).click(); - cy.get(`[title="timestamp-nanos"]`).click(); + cy.get(`[title=${DATASOURCE_NAME}]`).click(); + cy.get(`[title="data_logs_small_time_1"]`).click(); // Updated to match loaded data cy.getElementByTestId('datasetSelectorNext').click(); cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data'); @@ -81,9 +63,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => { // Switch language to PPL cy.setQueryLanguage('PPL'); - const fromTime = 'Sep 19, 2018 @ 00:00:00.000'; - const toTime = 'Sep 21, 2019 @ 00:00:00.000'; - cy.setTopNavDate(fromTime, toTime); + cy.setTopNavDate(START_TIME, END_TIME); cy.waitForLoader(true); cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible'); @@ -93,8 +73,8 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => { cy.getElementByTestId(`datasetSelectorButton`).click(); cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Indexes"]`).click(); - cy.get(`[title=${SECONDARY_ENGINE.name}]`).click(); - cy.get(`[title="timestamp-nanos"]`).click(); + cy.get(`[title=${DATASOURCE_NAME}]`).click(); + cy.get(`[title="data_logs_small_time_1"]`).click(); // Updated to match loaded data cy.getElementByTestId('datasetSelectorNext').click(); cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data'); @@ -110,9 +90,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => { // PPL should already be selected cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'PPL'); - const fromTime = 'Sep 19, 2018 @ 00:00:00.000'; - const toTime = 'Sep 21, 2019 @ 00:00:00.000'; - cy.setTopNavDate(fromTime, toTime); + cy.setTopNavDate(START_TIME, END_TIME); cy.waitForLoader(true); @@ -131,30 +109,28 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => { describe('index pattern', () => { it('create index pattern and select it', function () { - testFixtureHandler.importJSONMapping('cypress/fixtures/logstash/mappings.json.txt'); - testFixtureHandler.importJSONDoc('cypress/fixtures/logstash/data.json.txt'); - - testFixtureHandler.importJSONMapping('cypress/fixtures/discover/mappings.json.txt'); - testFixtureHandler.importJSONDoc('cypress/fixtures/discover/data.json.txt'); + // Create and select index pattern for data_logs_small_time_1* + cy.createWorkspaceIndexPatterns({ + url: `${BASE_PATH}`, + workspaceName: `${WORKSPACE_NAME}`, + indexPattern: 'data_logs_small_time_1', + timefieldName: 'timestamp', + indexPatternHasTimefield: true, + dataSource: DATASOURCE_NAME, + isEnhancement: true, + }); - // 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.navigateToWorkSpaceHomePage(`${BASE_PATH}`, `${WORKSPACE_NAME}`); + cy.waitForLoader(true); cy.getElementByTestId(`datasetSelectorButton`).click(); cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); cy.get(`[title="Index Patterns"]`).click(); - cy.get(`[title="logstash-*"]`).click(); - cy.getElementByTestId('datasetSelectorNext').click(); + cy.get(`[title="${DATASOURCE_NAME}::data_logs_small_time_1*"]`).should('exist'); cy.waitForLoader(true); cy.waitForSearch(); cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible'); }); }); - - after(() => { - cy.deleteIndex('timestamp-nanos'); - }); }); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/queries.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/queries.spec.js index d08aa98cb364..343ac1131207 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/queries.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/queries.spec.js @@ -2,49 +2,65 @@ * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ -import { - MiscUtils, - TestFixtureHandler, -} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; -import { PATHS } from '../../../../../utils/constants'; -const miscUtils = new MiscUtils(cy); -const testFixtureHandler = new TestFixtureHandler(cy, PATHS.ENGINE); +import { WORKSPACE_NAME, DATASOURCE_NAME, START_TIME, END_TIME } from './constants'; +import { BASE_PATH, SECONDARY_ENGINE } from '../../../../../utils/constants'; -describe.skip('query enhancement queries', { scrollBehavior: false }, () => { +describe('query enhancement queries', { scrollBehavior: false }, () => { before(() => { - testFixtureHandler.importJSONMapping('cypress/fixtures/timestamp/mappings.json.txt'); - - testFixtureHandler.importJSONDoc('cypress/fixtures/timestamp/data_with_index_pattern.json.txt'); - - // Go to the Discover page - miscUtils.visitPage(`app/data-explorer/discover#/`); + // Load test data + cy.setupTestData( + SECONDARY_ENGINE.url, + ['cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.mapping.json'], + ['cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.data.ndjson'] + ); - cy.setAdvancedSetting({ - defaultIndex: 'timestamp-*', + // Add data source + cy.addDataSource({ + name: `${DATASOURCE_NAME}`, + url: `${SECONDARY_ENGINE.url}`, + authType: 'no_auth', }); - // 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(); + // Create workspace and set up index pattern + cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`); + cy.visit('/app/home'); + cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${WORKSPACE_NAME}`); + + // Create and select index pattern for data_logs_small_time_1* + cy.createWorkspaceIndexPatterns({ + url: `${BASE_PATH}`, + workspaceName: `${WORKSPACE_NAME}`, + indexPattern: 'data_logs_small_time_1', + timefieldName: 'timestamp', + indexPatternHasTimefield: true, + dataSource: DATASOURCE_NAME, + isEnhancement: true, + }); + // Go to workspace home + cy.navigateToWorkSpaceHomePage(`${BASE_PATH}`, `${WORKSPACE_NAME}`); + cy.setTopNavDate(START_TIME, END_TIME); cy.waitForLoader(true); - cy.waitForSearch(); + }); + + after(() => { + cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`); + cy.deleteDataSourceByName(`${DATASOURCE_NAME}`); + cy.deleteIndex('data_logs_small_time_1'); }); describe('send queries', () => { it('with DQL', function () { + cy.setQueryLanguage('DQL'); + const query = `_id:1`; cy.setSingleLineQueryEditor(query); cy.waitForLoader(true); cy.waitForSearch(); cy.verifyHitCount(1); - //query should persist across refresh + // query should persist across refresh cy.reload(); cy.verifyHitCount(1); }); @@ -69,7 +85,7 @@ describe.skip('query enhancement queries', { scrollBehavior: false }, () => { // default SQL query should be set cy.waitForLoader(true); cy.getElementByTestId(`osdQueryEditor__multiLine`).contains( - `SELECT * FROM timestamp-* LIMIT 10` + `SELECT * FROM data_logs_small_time_1* LIMIT 10` ); cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible'); @@ -88,21 +104,16 @@ describe.skip('query enhancement queries', { scrollBehavior: false }, () => { // default PPL query should be set cy.waitForLoader(true); - cy.getElementByTestId(`osdQueryEditor__multiLine`).contains(`source = timestamp-*`); + cy.getElementByTestId(`osdQueryEditor__multiLine`).contains( + `source = data_logs_small_time_1*` + ); cy.waitForSearch(); cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible'); - cy.get('[class="euiText euiText--small"]').then((text) => cy.log(text)); - cy.verifyHitCount(4); //query should persist across refresh cy.reload(); - cy.verifyHitCount(4); - }); - - after(() => { - cy.deleteIndex('timestamp-nanos'); - cy.deleteIndex('timestamp-milis'); - cy.deleteSavedObject('index-pattern', 'index-pattern:timestamp-*'); + cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible'); + cy.verifyHitCount('10,000'); }); }); }); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 9176a4029b6c..b8f16fe07937 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -7,3 +7,12 @@ import '../utils/commands'; import '../utils/apps/commands'; import '../utils/dashboards/workspace-plugin/commands'; import '../utils/dashboards/commands'; + +// TODO: Remove this after https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5476 is resolved +const scopedHistoryNavigationError = /^[^(ScopedHistory instance has fell out of navigation scope)]/; +Cypress.on('uncaught:exception', (err) => { + /* returning false here prevents Cypress from failing the test */ + if (scopedHistoryNavigationError.test(err.message)) { + return false; + } +}); diff --git a/cypress/utils/commands.js b/cypress/utils/commands.js index 93d9d4b3d7d8..7397046a3da5 100644 --- a/cypress/utils/commands.js +++ b/cypress/utils/commands.js @@ -311,13 +311,14 @@ Cypress.Commands.add('createInitialWorkspaceWithDataSource', (dataSourceTitle, w cy.getElementByTestId('workspaceForm-workspaceDetails-nameInputText') .should('be.visible') .type(workspaceName); - cy.getElementByTestId('workspace-creator-dataSources-assign-button').should('be.visible').click(); + cy.getElementByTestId('workspace-creator-dataSources-assign-button') + .scrollIntoView() + .should('be.visible') + .click(); cy.get(`.euiSelectableListItem[title="${dataSourceTitle}"]`) .should('be.visible') .trigger('click'); - cy.getElementByTestId('workspace-detail-dataSources-associateModal-save-button') - .should('be.visible') - .click(); + cy.getElementByTestId('workspace-detail-dataSources-associateModal-save-button').click(); cy.getElementByTestId('workspaceForm-bottomBar-createButton').should('be.visible').click(); cy.contains(/successfully/); }); diff --git a/cypress/utils/constants.js b/cypress/utils/constants.js index 182a9828d36f..f5e809eb0f39 100644 --- a/cypress/utils/constants.js +++ b/cypress/utils/constants.js @@ -5,7 +5,7 @@ export * from './apps/constants'; -export const BASE_PATH = Cypress.env('baseUrl'); +export const BASE_PATH = Cypress.config('baseUrl'); export const BASE_ENGINE = Cypress.env('ENGINE'); export const SECONDARY_ENGINE = Cypress.env('SECONDARY_ENGINE'); diff --git a/cypress/utils/dashboards/commands.js b/cypress/utils/dashboards/commands.js index 72b2fbf3b01b..e6696637f63d 100644 --- a/cypress/utils/dashboards/commands.js +++ b/cypress/utils/dashboards/commands.js @@ -61,33 +61,29 @@ Cypress.Commands.add( 'navigateToWorkSpaceSpecificPage', (opts) => { const { url, workspaceName, page, isEnhancement = false } = opts; - // Navigating to the WorkSpace Home Page cy.navigateToWorkSpaceHomePage(url, workspaceName); + cy.waitForLoader(isEnhancement); - // Opening the side panel - cy.getElementByTestId('toggleNavButton') - .should('be.visible') - .then((ele) => { - if (ele.length > 0) { - ele.first().click(); - } - }); + // Check for toggleNavButton and handle accordingly + // If collapsibleNavShrinkButton is shown which means toggleNavButton is already clicked, try clicking the app link directly + // Using collapsibleNavShrinkButton is more robust than using toggleNavButton due to another toggleNavButton item on discover page + cy.get('body').then(($body) => { + const shrinkButton = $body.find('[data-test-subj="collapsibleNavShrinkButton"]'); - cy.getElementByTestId(`collapsibleNavAppLink-${page}`).should('be.visible').click(); + if (shrinkButton.length === 0) { + cy.get('[data-test-subj="toggleNavButton"]').filter(':visible').first().click(); + } - // wait until page loads and close side panel - cy.waitForLoader(isEnhancement); + cy.getElementByTestId(`collapsibleNavAppLink-${page}`).should('be.visible').click(); + }); - // close the nav menu - if (isEnhancement) { - cy.getElementByTestId('collapsibleNavShrinkButton').should('be.visible').click(); - } + cy.waitForLoader(isEnhancement); } ); Cypress.Commands.add( - // creates an index pattern within the workspace + // Creates an index pattern within the workspace using cluster // Don't use * in the indexPattern it adds it by default at the end of name 'createWorkspaceIndexPatterns', (opts) => { @@ -109,8 +105,14 @@ Cypress.Commands.add( isEnhancement, }); cy.getElementByTestId('createIndexPatternButton').click(); + cy.waitForLoader(isEnhancement); if (dataSource) { + // First select "Use external data source connection" radio button + // Ensure the radio is enabled and need to force click it + // This is due to data-test-subj="createIndexPatternStepDataSourceUseDataSourceRadio") is on the parent div, not on the actual radio input element + cy.get('input#useDataSource').should('not.be.disabled').click({ force: true }); + cy.get('[type="data-source"]').contains(dataSource).click(); } diff --git a/package.json b/package.json index 071853d3de8d..82768f1d5405 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "release_note:generate": "scripts/use_node scripts/generate_release_note", "cypress:run-without-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --env SECURITY_ENABLED=false", "cypress:run-with-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200,WAIT_FOR_LOADER_BUFFER_MS=500", - "osd:ciGroup10": "echo \"cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/a_check.spec.js\"", + "osd:ciGroup10": "echo \"cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/*.js\"", "osd:ciGroup11": "echo \"cypress/integration/dashboard_sanity_test.spec.js\"", "generate:opensearchsqlantlr": "./node_modules/antlr4ng-cli/index.js -Dlanguage=TypeScript -o ./src/plugins/data/public/antlr/opensearch_sql/.generated -visitor -no-listener -Xexact-output-dir ./src/plugins/data/public/antlr/opensearch_sql/grammar/OpenSearchSQLLexer.g4 ./src/plugins/data/public/antlr/opensearch_sql/grammar/OpenSearchSQLParser.g4", "generate:opensearchpplantlr": "./node_modules/antlr4ng-cli/index.js -Dlanguage=TypeScript -o ./src/plugins/data/public/antlr/opensearch_ppl/.generated -visitor -no-listener -Xexact-output-dir ./src/plugins/data/public/antlr/opensearch_ppl/grammar/OpenSearchPPLLexer.g4 ./src/plugins/data/public/antlr/opensearch_ppl/grammar/OpenSearchPPLParser.g4"