From 1b19f50aeb58d9479fdf4bbaa07e271e12198b69 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Tue, 30 Apr 2024 15:42:46 +0800 Subject: [PATCH] [Workspace] Add functional test for workspace overview page (#1246) * workspace overview Signed-off-by: Hailong Cui * update create workspace Signed-off-by: Hailong Cui * address review comments Signed-off-by: Hailong Cui * Add assertion Signed-off-by: Hailong Cui * fix workspacd name Signed-off-by: Hailong Cui --------- Signed-off-by: Hailong Cui --- .../workspace-plugin/workspace_create.spec.js | 24 +++- .../workspace_dropdown_menu.spec.js | 5 +- .../workspace_overview.spec.js | 119 ++++++++++++++++++ .../workspace-plugin/workspace_update.spec.js | 24 +++- .../dashboards/workspace-plugin/commands.js | 8 +- 5 files changed, 162 insertions(+), 18 deletions(-) create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_overview.spec.js diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_create.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_create.spec.js index 0b6bcd0af..c8b0471e6 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_create.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_create.spec.js @@ -42,7 +42,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { 'workspaceForm-workspaceFeatureVisibility-OpenSearch Dashboards' ).check({ force: true }); cy.get('[id$="discover"]').uncheck({ force: true }); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); let workspaceId; cy.wait('@createWorkspaceRequest').then((interception) => { @@ -74,7 +76,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); cy.contains("Name can't be empty").should('exist'); }); @@ -85,7 +89,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); cy.contains('Invalid workspace name').should('exist'); }); @@ -96,7 +102,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); cy.contains('workspace name has already been used').should('exist'); }); @@ -107,7 +115,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('./+'); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); cy.contains('Invalid workspace description').should('exist'); }); }); @@ -142,7 +152,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId('comboBoxSearchInput') .last() .type('test_user_sfslja260'); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); let workspaceId; cy.wait('@createWorkspaceRequest').then((interception) => { diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_dropdown_menu.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_dropdown_menu.spec.js index 755c79620..7e8aed992 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_dropdown_menu.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_dropdown_menu.spec.js @@ -20,7 +20,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.deleteAllWorkspaces(); for (const workspaceName of workspaceNames) { - cy.createWorkspace(workspaceName).then((workspaceId) => { + cy.createWorkspace({ name: workspaceName }).then((workspaceId) => { workspaceNameIdMapping[workspaceName] = workspaceId; }); } @@ -98,10 +98,11 @@ if (Cypress.env('WORKSPACE_ENABLED')) { // Create 3 more workspaces so that there are more than 5 workspaces in the system for (const workspaceName of newWorkspaceNames) { - cy.createWorkspace(workspaceName); + cy.createWorkspace({ name: workspaceName }); } cy.wait(1000); + cy.reload(); cy.getElementByTestId('toggleNavButton').click(); cy.get('#workspaceDropdownMenu').click(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_overview.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_overview.spec.js new file mode 100644 index 000000000..7fcbe9c90 --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_overview.spec.js @@ -0,0 +1,119 @@ +/* + * 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 currentDate = Date.now(); +const workspaceName = 'foo-workspace' + currentDate; +const workspaceDescription = 'foo-workspace-desc' + currentDate; + +if (Cypress.env('WORKSPACE_ENABLED')) { + let workspaceId = ''; + + describe('Workspace overview', () => { + before(() => { + cy.createWorkspace({ + name: workspaceName, + description: workspaceDescription, + features: [ + 'management', + 'discover', + 'workspace_overview', + 'workspace_update', + 'dashboards', + 'visualize', + ], + }).then((id) => { + workspaceId = id; + }); + cy.log(`workspace ${workspaceName} create successfully`); + }); + + after(() => { + cy.deleteWorkspaceById(workspaceId); + }); + + beforeEach(() => { + // Visit workspace overview page + cy.intercept('GET', `/w/${workspaceId}/api/workspaces/${workspaceId}`).as( + 'getWorkspace' + ); + miscUtils.visitPage(`/w/${workspaceId}/app/workspace_overview`); + cy.wait('@getWorkspace'); + }); + + it('should successfully load the page', () => { + // workspace name is correctly displayed + cy.contains(workspaceName, { timeout: 60000 }).should('be.visible'); + // dashboars and visualization cards are visiable + cy.get('div[data-test-subj="workspaceGetStartCards"') + .as('getStartCards') + .should('be.visible'); + cy.get('@getStartCards').contains('with Dashboards').should('be.visible'); + cy.get('@getStartCards') + .contains('with Visualizations') + .should('be.visible'); + + // tabs + cy.getElementByTestId('workspaceTabs') + .find('.euiTab') + .as('tabs') + .should('have.length', 3); + }); + + it('should collpase start working section when collpase button clicked', () => { + // workspace name is correctly displayed + cy.contains(workspaceName, { timeout: 60000 }).should('be.visible'); + // dashboars and visualization cards are visiable + cy.getElementByTestId('workspaceGetStartCards') + .as('getStartCards') + .should('be.visible'); + cy.get('@getStartCards').contains('with Dashboards').should('be.visible'); + cy.get('@getStartCards') + .contains('with Visualizations') + .should('be.visible'); + + // click Collpase + cy.getElementByTestId('Collapse').click(); + cy.get('@getStartCards').should('not.exist'); + + // click Expand + cy.getElementByTestId('Expand').click(); + cy.get('@getStartCards').should('be.visible'); + }); + + it('should display workspace description correctly in overview tab', () => { + // click on overview tab + cy.get('div[data-test-subj="workspaceTabs"] #overview').click(); + cy.contains(workspaceDescription).should('be.visible'); + }); + + it('should redirect to saved objects page when click on library tab', () => { + // click on library tab + cy.get('div[data-test-subj="workspaceTabs"] #library').click(); + cy.location('pathname', { timeout: 6000 }).should( + 'include', + 'app/management/opensearch-dashboards/objects' + ); + }); + + it('should show wokrspace update when click on settings tab', () => { + // click on settings tab + cy.getElementByTestId('workspaceTabs').find('#settings').click(); + cy.contains('Workspace Details').should('be.visible'); + + cy.getElementByTestId('workspaceForm-workspaceDetails-nameInputText') + .clear() + .type(`${workspaceDescription}-updated`); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ + force: true, + }); + + // workspace update successfully and overview page refreshed + cy.contains('h1', `${workspaceDescription}-updated`).should('be.visible'); + }); + }); +} diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_update.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_update.spec.js index 4e8fb489f..be67609a6 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_update.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/workspace_update.spec.js @@ -12,7 +12,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { describe('Update workspace', () => { before(() => { cy.deleteWorkspaceByName(workspaceName); - cy.createWorkspace(workspaceName).then((value) => (workspaceId = value)); + cy.createWorkspace({ name: workspaceName }).then( + (value) => (workspaceId = value) + ); }); beforeEach(() => { @@ -47,7 +49,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ + force: true, + }); cy.contains("Name can't be empty").should('exist'); }); @@ -68,7 +72,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ + force: true, + }); cy.contains('Invalid workspace name').should('exist'); }); @@ -81,7 +87,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('./+'); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ + force: true, + }); cy.contains('Invalid workspace description').should('exist'); }); }); @@ -110,7 +118,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'workspaceForm-workspaceFeatureVisibility-OpenSearch Dashboards' ).check({ force: true }); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ + force: true, + }); cy.wait('@updateWorkspaceRequest').then((interception) => { expect(interception.response.statusCode).to.equal(200); }); @@ -169,7 +179,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId('comboBoxSearchInput') .last() .type('test_user_Fnxs972xC'); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click(); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ + force: true, + }); cy.wait('@updateWorkspaceRequest').then((interception) => { expect(interception.response.statusCode).to.equal(200); }); diff --git a/cypress/utils/dashboards/workspace-plugin/commands.js b/cypress/utils/dashboards/workspace-plugin/commands.js index ecb085d1c..fcdb11d3f 100644 --- a/cypress/utils/dashboards/workspace-plugin/commands.js +++ b/cypress/utils/dashboards/workspace-plugin/commands.js @@ -41,7 +41,7 @@ Cypress.Commands.add('deleteWorkspaceByName', (workspaceName) => { }); }); -Cypress.Commands.add('createWorkspace', (workspaceName) => { +Cypress.Commands.add('createWorkspace', (workspace) => { cy.request({ method: 'POST', url: `${BASE_PATH}${WORKSPACE_API_PREFIX}`, @@ -50,15 +50,15 @@ Cypress.Commands.add('createWorkspace', (workspaceName) => { }, body: { attributes: { - name: workspaceName, - description: 'test_description', + ...workspace, + description: workspace.description || 'test_description', }, }, }).then((resp) => { if (resp && resp.body && resp.body.success) { return resp.body.result.id; } else { - throw new Error(`Create workspace ${workspaceName} failed!`); + throw new Error(`Create workspace ${workspace.name} failed!`); } }); });