-
Notifications
You must be signed in to change notification settings - Fork 115
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
SuZhou-Joe
merged 5 commits into
opensearch-project:main
from
Qxisylolo:add_tests_for_deletion
Nov 18, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
180 changes: 180 additions & 0 deletions
180
...opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* 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(() => { | ||
Cypress.config('defaultCommandTimeout', 60000); | ||
cy.deleteAllWorkspaces(); | ||
}); | ||
beforeEach(() => { | ||
// Visit workspace list page | ||
miscUtils.visitPage(`/app/workspace_list`); | ||
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' | ||
); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.deleteAllWorkspaces(); | ||
}); | ||
|
||
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'); | ||
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'); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not necessary, I will delete it. Thank you