Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for workspace deletion #1631

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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');
});
});
}
Loading