From 068bda7294dafa88cb0c768e20bdc8b33037f7d6 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:27:42 +0800 Subject: [PATCH] [workspace]Add cypress for breadcrumbs (#1642) (#1650) * imporve link verification to support version Signed-off-by: Hailong Cui * imporve link verification to support version Signed-off-by: Hailong Cui * add breadcrumbs test Signed-off-by: Hailong Cui * add breadcrumbs test Signed-off-by: Hailong Cui * fix link with version Signed-off-by: Hailong Cui * fix test failure Signed-off-by: Hailong Cui * fix lint Signed-off-by: Hailong Cui * fix test Signed-off-by: Hailong Cui * wait for page load complete Signed-off-by: Hailong Cui --------- Signed-off-by: Hailong Cui (cherry picked from commit bd7a18f65f5467a079218e73b02d836fa6d8cbdc) Co-authored-by: Hailong Cui --- .../mds_workspace_analytics_overviews.spec.js | 44 ++--- .../mds_workspace_breadcrumbs.spec.js | 157 ++++++++++++++++++ .../mds_workspace_essential_overviews.spec.js | 33 ++-- .../mds_workspace_initial.spec.js | 14 +- 4 files changed, 209 insertions(+), 39 deletions(-) create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_breadcrumbs.spec.js diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_analytics_overviews.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_analytics_overviews.spec.js index 2f8241a74..67dd454d1 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_analytics_overviews.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_analytics_overviews.spec.js @@ -118,34 +118,38 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.get('.euiLink') .contains('Quickstart guide') .should('be.visible') - .and( - 'have.attr', - 'href', - 'https://opensearch.org/docs/latest/dashboards/quickstart/' - ); + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/quickstart\/$/ + ); + }); cy.get('.euiLink') .contains('Building data visualizations') .should('be.visible') - .and( - 'have.attr', - 'href', - 'https://opensearch.org/docs/latest/dashboards/visualize/viz-index/' - ); + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/visualize\/viz-index\/$/ + ); + }); cy.get('.euiLink') .contains('Creating dashboards') .should('be.visible') - .and( - 'have.attr', - 'href', - 'https://opensearch.org/docs/latest/dashboards/dashboard/index/' - ); + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/dashboard\/index\/$/ + ); + }); cy.contains('Learn more in Documentation') .should('be.visible') - .and( - 'have.attr', - 'href', - 'https://opensearch.org/docs/latest/dashboards/index/' - ); + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/index\/$/ + ); + }); }); }); } diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_breadcrumbs.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_breadcrumbs.spec.js new file mode 100644 index 000000000..8f1ca5002 --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_breadcrumbs.spec.js @@ -0,0 +1,157 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const workspaceName = `test_workspace_analytics_${Math.random() + .toString(36) + .substring(7)}`; +let workspaceDescription = 'This is a analytics workspace description.'; +let workspaceId; +let workspaceFeatures = ['use-case-all']; + +if (Cypress.env('WORKSPACE_ENABLED')) { + const createWorkspace = () => { + cy.createWorkspace({ + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspaceId = value; + }); + }; + + describe('Breadcrumbs in workspace', () => { + before(() => { + cy.deleteWorkspaceByName(workspaceName); + createWorkspace(); + }); + + after(() => { + if (workspaceId) { + cy.deleteWorkspaceById(workspaceId); + } + }); + + it('should show workspace name in breadcrumbs', () => { + miscUtils.visitPage(`w/${workspaceId}/app/objects`); + + // get div with class newTopNavHeader + cy.get('.newTopNavHeader').within(() => { + cy.getElementByTestId('breadcrumb first') + .should('exist') + .within(() => { + // Check for the icon + cy.getElementByTestId(`${workspaceId}-icon`).should('exist'); + // Check for the workspace name + cy.contains(workspaceName).should('exist').click(); + // click on breadcrumbs goes to overview page + cy.url().should('include', `w/${workspaceId}/app/all_overview`); + }); + }); + }); + + it('should show breadcrumbs in recent popover', () => { + miscUtils.visitPage(`w/${workspaceId}/app/workspace_detail`); + // wait for page load + cy.contains('h1', 'Workspace details'); + // waiting for page load completely + cy.getElementByTestId('recentItemsSectionButton').should( + 'not.have.class', + 'headerRecentItemsButton--loadingIndicator', + { + timeout: 10000, + } + ); + cy.wait(1000); + cy.getElementByTestId('recentItemsSectionButton').click({ force: true }); + + cy.get('.euiPopover__panel').within(() => { + cy.getElementByTestId('breadcrumbs').within(() => { + // Check for the icon + cy.getElementByTestId(`${workspaceId}-icon`).should('exist'); + // Check for the workspace name + cy.contains(workspaceName).should('exist'); + // page title exists in breadcrumbs + cy.contains('Workspace details'); + }); + }); + }); + }); + + describe('Breadcrumbs out of workspace', () => { + it('breadcrumbs display correctly in settings and setup', () => { + miscUtils.visitPage('app/workspace_list'); + cy.contains('h1', 'Workspaces'); + + cy.get('.newTopNavHeader').within(() => { + cy.getElementByTestId('breadcrumb first') + .should('exist') + .within(() => { + // Check for the use case name + cy.contains('Settings and setup').click(); + cy.url().should('include', 'app/settings_landing'); + }); + }); + + // check breadcrumbs in recent popover + cy.getElementByTestId('recentItemsSectionButton').should( + 'not.have.class', + 'headerRecentItemsButton--loadingIndicator', + { + timeout: 10000, + } + ); + cy.wait(1000); + cy.getElementByTestId('recentItemsSectionButton').click({ force: true }); + + cy.get('.euiPopover__panel').within(() => { + cy.getElementByTestId('breadcrumbs').within(() => { + cy.contains('Settings and setup'); + cy.contains('Settings and setup overview'); + }); + }); + }); + + it('breadcrumbs display correctly in data administration', () => { + miscUtils.visitPage('app/data_administration_landing'); + cy.contains('h1', 'Data administration overview'); + + cy.get('.newTopNavHeader').within(() => { + cy.getElementByTestId('breadcrumb first') + .should('exist') + .within(() => { + // Check for the use case name + cy.contains('Data administration'); + }); + }); + + // check breadcrumbs in recent popover + cy.getElementByTestId('recentItemsSectionButton').should( + 'not.have.class', + 'headerRecentItemsButton--loadingIndicator', + { + timeout: 10000, + } + ); + cy.wait(1000); + cy.getElementByTestId('recentItemsSectionButton').click({ force: true }); + + cy.get('.euiPopover__panel').within(() => { + cy.getElementByTestId('breadcrumbs').within(() => { + cy.contains('Data administration'); + cy.contains('Data administration overview'); + }); + }); + }); + }); +} diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_essential_overviews.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_essential_overviews.spec.js index 8d24abaf6..45423f564 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_essential_overviews.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_essential_overviews.spec.js @@ -127,27 +127,30 @@ if (Cypress.env('WORKSPACE_ENABLED')) { // get a link with text as Quickstart guide cy.get('a') .contains('Quickstart guide') - .should( - 'have.attr', - 'href', - 'https://opensearch.org/docs/latest/dashboards/quickstart/' - ); + .should('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/quickstart\/$/ + ); + }); cy.get('a') .contains('Building data visualizations') - .should( - 'have.attr', - 'href', - 'https://opensearch.org/docs/latest/dashboards/visualize/viz-index/' - ); + .should('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/visualize\/viz-index\/$/ + ); + }); cy.get('a') .contains('Creating dashboards') - .should( - 'have.attr', - 'href', - 'https://opensearch.org/docs/latest/dashboards/dashboard/index/' - ); + .should('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/dashboard\/index\/$/ + ); + }); }); }); } diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_initial.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_initial.spec.js index 48d7a95ba..be728a0ff 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_initial.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_initial.spec.js @@ -70,10 +70,16 @@ if (Cypress.env('WORKSPACE_ENABLED')) { ).should('not.exist'); // Contain correct link - cy.contains('a', 'Learn more from documentation').should('exist'); - cy.get( - 'a[href="https://opensearch.org/docs/latest/opensearch/index/"]' - ).should('have.attr', 'target', '_blank'); + cy.contains('a', 'Learn more from documentation') + .should('exist') + .should('have.attr', 'target', '_blank') + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/opensearch\/index\/$/ + ); + }); + cy.contains( 'a', 'Explore live demo environment at playground.opensearch.org'