From b60a34330d61a291e03e77a3a4fe3c9a8395d078 Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Mon, 6 Jan 2025 18:15:43 +0800 Subject: [PATCH] Improve workspace import sample data tests (#1671) * Improve workspace import sample data tests Signed-off-by: Lin Wang * Fix artifact upload failed for bundle snapshot Signed-off-by: Lin Wang --------- Signed-off-by: Lin Wang (cherry picked from commit af6f753ef1fb9238d427d7efe97094ef485cb0dd) --- ...cypress-workflow-bundle-snapshot-based.yml | 2 + ...s_workspace_import_sample_data_to.cases.js | 197 ++++++++---------- 2 files changed, 90 insertions(+), 109 deletions(-) diff --git a/.github/workflows/cypress-workflow-bundle-snapshot-based.yml b/.github/workflows/cypress-workflow-bundle-snapshot-based.yml index edfe7e832..45a127dbd 100644 --- a/.github/workflows/cypress-workflow-bundle-snapshot-based.yml +++ b/.github/workflows/cypress-workflow-bundle-snapshot-based.yml @@ -20,6 +20,7 @@ jobs: test-name: Core Dashboards using Bundle Snapshot test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_UIMETRIC_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js' osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --vis_builder.enabled=true --ml_commons_dashboards.enabled=true --usageCollection.uiMetric.enabled=true + artifact-name-suffix: '-with-security' tests-without-security: uses: ./.github/workflows/release-e2e-workflow-template.yml @@ -28,3 +29,4 @@ jobs: test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_UIMETRIC_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js' osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --vis_builder.enabled=true --ml_commons_dashboards.enabled=true --usageCollection.uiMetric.enabled=true security-enabled: false + artifact-name-suffix: '-without-security' diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases.js index ea5aec66b..7f48dd409 100644 --- a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases.js +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases.js @@ -7,7 +7,7 @@ const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); export const WorkspaceImportSampleDataTestCases = () => { if (Cypress.env('WORKSPACE_ENABLED')) { - describe('import sample data to workspace', () => { + describe('workspace import sample data', () => { let workspaceId; let dataSourceId; let dataSourceTitle; @@ -58,117 +58,96 @@ export const WorkspaceImportSampleDataTestCases = () => { } }); - beforeEach(() => { - cy.visit(`/w/${workspaceId}/app/import_sample_data`); - if (MDSEnabled) { - cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); - } - }); - - it('should show Add data buttons if sample data not installed', () => { - cy.getElementByTestId('addSampleDataSetecommerce').should('be.visible'); - cy.getElementByTestId('addSampleDataSetflights').should('be.visible'); - cy.getElementByTestId('addSampleDataSetlogs').should('be.visible'); - }); - - it('should show remove buttons after sample data installed', () => { - cy.getElementByTestId('addSampleDataSetecommerce').click(); - cy.getElementByTestId('addSampleDataSetflights').click(); - cy.getElementByTestId('addSampleDataSetlogs').click(); - - cy.getElementByTestId('removeSampleDataSetecommerce').should( - 'be.visible' - ); - cy.getElementByTestId('removeSampleDataSetflights').should( - 'be.visible' - ); - cy.getElementByTestId('removeSampleDataSetlogs').should('be.visible'); - - cy.getElementByTestId('removeSampleDataSetecommerce').click(); - cy.getElementByTestId('removeSampleDataSetflights').click(); - cy.getElementByTestId('removeSampleDataSetlogs').click(); + describe('add and remove buttons', () => { + beforeEach(() => { + cy.visit(`/w/${workspaceId}/app/import_sample_data`); + if (MDSEnabled) { + cy.selectTopRightNavigationDataSource( + dataSourceTitle, + dataSourceId + ); + } + }); + + it('should show Add data buttons if sample data not installed', () => { + cy.getElementByTestId('addSampleDataSetecommerce').should( + 'be.visible' + ); + cy.getElementByTestId('addSampleDataSetflights').should('be.visible'); + cy.getElementByTestId('addSampleDataSetlogs').should('be.visible'); + }); + + it('should show remove buttons after sample data installed', () => { + cy.intercept( + { + pathname: '/w/**/api/sample_data/**', + times: 3, + }, + { + statusCode: 200, + } + ).as('importSampleData'); + cy.getElementByTestId('addSampleDataSetecommerce').click(); + cy.wait('@importSampleData') + .its('request.url') + .should('include', 'ecommerce'); + + cy.getElementByTestId('addSampleDataSetflights').click(); + cy.wait('@importSampleData') + .its('request.url') + .should('include', 'flights'); + + cy.getElementByTestId('addSampleDataSetlogs').click(); + cy.wait('@importSampleData') + .its('request.url') + .should('include', 'logs'); + + cy.getElementByTestId('removeSampleDataSetecommerce').should( + 'be.visible' + ); + cy.getElementByTestId('removeSampleDataSetflights').should( + 'be.visible' + ); + cy.getElementByTestId('removeSampleDataSetlogs').should('be.visible'); + }); }); it('should be able to visit ecommerce dashboard', () => { - cy.getElementByTestId('addSampleDataSetecommerce').click(); - - cy.getElementByTestId('launchSampleDataSetecommerce') - .should('be.visible') - .click(); - - cy.location('href').should( - 'include', - `/w/${workspaceId}/app/dashboards` - ); - cy.getElementByTestId('headerAppActionMenu').should( - 'contain', - getTitleWithDataSource('[eCommerce] Revenue Dashboard') - ); - cy.get( - `[data-title="${getTitleWithDataSource( - '[eCommerce] Total Revenue' - )}"]` - ).should('not.contain', 'No results found'); - cy.visit(`/w/${workspaceId}/app/import_sample_data`); - - if (MDSEnabled) { - cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); - } - cy.getElementByTestId('removeSampleDataSetecommerce').click(); - }); - - it('should be able to visit flights dashboards', () => { - cy.getElementByTestId('addSampleDataSetflights').click(); - - cy.getElementByTestId('launchSampleDataSetflights') - .should('be.visible') - .click(); - - cy.location('href').should( - 'include', - `/w/${workspaceId}/app/dashboards` - ); - cy.getElementByTestId('headerAppActionMenu').should( - 'contain', - getTitleWithDataSource('[Flights] Global Flight Dashboard') - ); - cy.get( - `[data-title="${getTitleWithDataSource('[Flights] Flight Delays')}"]` - ).should('not.contain', 'No results found'); - cy.visit(`/w/${workspaceId}/app/import_sample_data`); - - if (MDSEnabled) { - cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); - } - cy.getElementByTestId('removeSampleDataSetflights').click(); - }); - - it('should be able to visit logs dashboards', () => { - cy.getElementByTestId('addSampleDataSetlogs').click(); - - cy.getElementByTestId('launchSampleDataSetlogs') - .should('be.visible') - .click(); - - cy.location('href').should( - 'include', - `/w/${workspaceId}/app/dashboards` - ); - cy.getElementByTestId('headerAppActionMenu').should( - 'contain', - getTitleWithDataSource('[Logs] Web Traffic') - ); - cy.get( - `[data-title="${getTitleWithDataSource( - '[Logs] Unique Visitors vs. Average Bytes' - )}"]` - ).should('not.contain', 'No results found'); - cy.visit(`/w/${workspaceId}/app/import_sample_data`); - - if (MDSEnabled) { - cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); - } - cy.getElementByTestId('removeSampleDataSetlogs').click(); + cy.loadSampleDataForWorkspace('ecommerce', workspaceId, dataSourceId) + .then(() => { + cy.visit(`/w/${workspaceId}/app/import_sample_data`); + if (MDSEnabled) { + cy.selectTopRightNavigationDataSource( + dataSourceTitle, + dataSourceId + ); + } + + cy.getElementByTestId('launchSampleDataSetecommerce') + .should('be.visible') + .click(); + + cy.location('href').should( + 'include', + `/w/${workspaceId}/app/dashboards` + ); + cy.getElementByTestId('headerAppActionMenu').should( + 'contain', + getTitleWithDataSource('[eCommerce] Revenue Dashboard') + ); + cy.get( + `[data-title="${getTitleWithDataSource( + '[eCommerce] Total Revenue' + )}"]` + ).should('not.contain', 'No results found'); + }) + .then(() => { + cy.removeSampleDataForWorkspace( + 'ecommerce', + workspaceId, + dataSourceId + ); + }); }); }); }