From b14148a02a54c0bca7224a8abf72bfdf0d74f7bd Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:44:55 +0800 Subject: [PATCH] Add tests for workspace deletion (#1631) (#1651) * add tests for deletion Signed-off-by: Qxisylolo * resolve comments Signed-off-by: Qxisylolo * new update Signed-off-by: Qxisylolo * new update Signed-off-by: Qxisylolo * revert lines Signed-off-by: Qxisylolo --------- Signed-off-by: Qxisylolo (cherry picked from commit 976f2ba78b5259fe04a4e12a5f0826b26bda6d41) Co-authored-by: Qxisylolo --- .../mds_workspace_delete.spec.js | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js new file mode 100644 index 000000000..0358f9b20 --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js @@ -0,0 +1,182 @@ +/* + * 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 workspace1Name = 'test_workspace_320sdfouAz'; +let workspace1Description = 'This is a workspace1 description.'; +const workspace2Name = 'test_workspace_321sdfouAz'; +let workspace2Description = 'This is a workspace2 description.'; + +let workspace1Id; +let workspace2Id; + +if (Cypress.env('WORKSPACE_ENABLED')) { + describe('Delete Workspace(s) in 2 ways in workspace list page', () => { + before(() => { + cy.deleteWorkspaceByName(workspace1Name); + cy.deleteWorkspaceByName(workspace2Name); + }); + beforeEach(() => { + cy.createWorkspace({ + name: workspace1Name, + description: workspace1Description, + features: ['use-case-observability'], + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspace1Id = value; + cy.intercept('DELETE', `/api/workspaces/${workspace1Id}`).as( + 'deleteWorkspace1Request' + ); + }); + + cy.createWorkspace({ + name: workspace2Name, + description: workspace2Description, + features: ['use-case-search'], + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspace2Id = value; + cy.intercept('DELETE', `/api/workspaces/${workspace2Id}`).as( + 'deleteWorkspace2Request' + ); + }); + // Visit workspace list page + miscUtils.visitPage(`/app/workspace_list`); + }); + + afterEach(() => { + cy.deleteWorkspaceByName(workspace1Name); + cy.deleteWorkspaceByName(workspace2Name); + }); + + describe('delete a workspace successfully using action buttons', () => { + it('should successfully load delete button and show delete modal when clicking action button', () => { + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId(`checkboxSelectRow-${workspace1Id}`) + .parents('tr') + .within(() => { + cy.getElementByTestId('euiCollapsedItemActionsButton').click(); + }); + cy.getElementByTestId('workspace-list-delete-icon').should( + 'be.visible' + ); + cy.getElementByTestId('workspace-list-delete-icon').click(); + cy.contains('Delete workspace').should('be.visible'); + cy.contains( + 'The following workspace will be permanently deleted. This action cannot be undone' + ).should('be.visible'); + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId('delete-workspace-modal-input').type('delete'); + cy.getElementByTestId('delete-workspace-modal-confirm').click(); + cy.wait('@deleteWorkspace1Request').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.location('pathname').should('include', 'app/workspace_list'); + cy.contains('Delete workspace successfully').should('be.visible'); + cy.contains(workspace1Name).should('not.exist'); + }); + }); + + describe('delete workspace(s) successfully using multi-deletion button', () => { + it('should successfully show multi-deletion button and perform deletion when choosing one workspace', () => { + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId(`checkboxSelectRow-${workspace1Id}`).click(); + cy.getElementByTestId('multi-deletion-button').should('be.visible'); + cy.getElementByTestId('multi-deletion-button').click(); + cy.contains('Delete workspace').should('be.visible'); + cy.contains( + 'The following workspace will be permanently deleted. This action cannot be undone' + ).should('be.visible'); + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId('delete-workspace-modal-input').type('delete'); + cy.getElementByTestId('delete-workspace-modal-confirm').click(); + cy.wait('@deleteWorkspace1Request').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.location('pathname').should('include', 'app/workspace_list'); + cy.contains('Delete workspace successfully').should('be.visible'); + cy.contains(workspace1Name).should('not.exist'); + }); + + it('should successfully delete all', () => { + cy.contains(workspace1Name).should('be.visible'); + cy.contains(workspace2Name).should('be.visible'); + cy.getElementByTestId('checkboxSelectAll').click(); + cy.getElementByTestId('multi-deletion-button').should('be.visible'); + cy.getElementByTestId('multi-deletion-button').click(); + cy.contains('Delete workspace').should('be.visible'); + cy.contains( + 'The following workspace will be permanently deleted. This action cannot be undone' + ).should('be.visible'); + cy.contains(workspace1Name).should('be.visible'); + cy.contains(workspace2Name).should('be.visible'); + cy.getElementByTestId('delete-workspace-modal-input').type('delete'); + cy.getElementByTestId('delete-workspace-modal-confirm').click(); + cy.wait('@deleteWorkspace1Request').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.location('pathname').should('include', 'app/workspace_list'); + cy.contains('Delete workspace successfully').should('be.visible'); + cy.contains(workspace1Name).should('not.exist'); + cy.contains(workspace2Name).should('not.exist'); + }); + }); + }); + + describe('Workspace deletion in workspace detail page', () => { + before(() => { + cy.deleteWorkspaceByName(workspace1Name); + cy.createWorkspace({ + name: workspace1Name, + description: workspace1Description, + features: ['use-case-observability'], + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspace1Id = value; + }); + }); + + beforeEach(() => { + cy.intercept( + 'DELETE', + `/w/${workspace1Id}/api/workspaces/${workspace1Id}` + ).as('deleteWorkspace1Request'); + // Visit workspace detail page + miscUtils.visitPage(`w/${workspace1Id}/app/workspace_detail`); + }); + + it('should delete workspace in workspace detail page', () => { + cy.getElementByTestId('workspace-detail-delete-button').click(); + cy.contains('Delete workspace').should('be.visible'); + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId('delete-workspace-modal-input').type( + workspace1Name + ); + cy.getElementByTestId('delete-workspace-modal-confirm').click(); + cy.wait('@deleteWorkspace1Request').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.contains('Delete workspace successfully').should('be.visible'); + cy.location('pathname').should('include', 'app/workspace_list'); + cy.contains(workspace1Name).should('not.exist'); + }); + }); +}