-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workspace] add tests for workspace collaborators page (#1632)
* add tests for collaborators page Signed-off-by: tygao <[email protected]> * update Signed-off-by: tygao <[email protected]> * use add instead of update Signed-off-by: tygao <[email protected]> * remove wait Signed-off-by: tygao <[email protected]> * add assert for collaborators not exist Signed-off-by: tygao <[email protected]> --------- Signed-off-by: tygao <[email protected]> (cherry picked from commit 5a6faae)
- Loading branch information
1 parent
9faba32
commit 6c31ec2
Showing
1 changed file
with
211 additions
and
0 deletions.
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
...rch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_collaborators.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,211 @@ | ||
/* | ||
* 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_collaborators'; | ||
let workspaceId; | ||
|
||
if ( | ||
Cypress.env('WORKSPACE_ENABLED') && | ||
Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && | ||
Cypress.env('SECURITY_ENABLED') | ||
) { | ||
describe('Workspace collaborators', () => { | ||
beforeEach(() => { | ||
cy.deleteWorkspaceByName(workspaceName); | ||
//Create a workspace before each test | ||
cy.createWorkspace({ | ||
name: workspaceName, | ||
features: ['use-case-observability'], | ||
settings: { | ||
permissions: { | ||
library_write: { | ||
users: [`${Cypress.env('username')}`], | ||
groups: ['admin_group'], | ||
}, | ||
write: { | ||
users: [`${Cypress.env('username')}`], | ||
groups: ['admin_group'], | ||
}, | ||
library_read: { | ||
users: ['read_user'], | ||
}, | ||
read: { | ||
users: ['read_user'], | ||
}, | ||
}, | ||
}, | ||
}).then((value) => { | ||
workspaceId = value; | ||
miscUtils.visitPage(`w/${value}/app/workspace_collaborators`); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.deleteWorkspaceById(workspaceId); | ||
}); | ||
|
||
it('should add user and group collaborators successfully', () => { | ||
//Add user | ||
cy.getElementByTestId('add-collaborator-popover').click(); | ||
cy.get('button[id="user"]').click(); | ||
cy.contains('Add Users').should('be.visible'); | ||
cy.getElementByTestId('workspaceCollaboratorIdInput-0').type( | ||
'new_read_user' | ||
); | ||
cy.get('button[type="submit"]') | ||
.contains('span', 'Add collaborators') | ||
.click(); | ||
|
||
//Add group | ||
cy.getElementByTestId('add-collaborator-popover').click(); | ||
cy.get('button[id="group"]').click(); | ||
cy.contains('Add Groups').should('be.visible'); | ||
cy.getElementByTestId('workspaceCollaboratorIdInput-0').type( | ||
'new_admin_group' | ||
); | ||
cy.get('span[title="Admin"]').click(); | ||
cy.get('button[type="submit"]') | ||
.contains('span', 'Add collaborators') | ||
.click(); | ||
|
||
cy.contains('new_read_user'); | ||
|
||
cy.get('table') | ||
.contains('td', 'new_read_user') | ||
.parent() | ||
.within(() => { | ||
cy.get('td').eq(3).contains('Read only'); | ||
}); | ||
|
||
cy.get('table') | ||
.contains('td', 'new_admin_group') | ||
.parent() | ||
.within(() => { | ||
cy.get('td').eq(3).contains('Admin'); | ||
}); | ||
const expectedWorkspace = { | ||
name: workspaceName, | ||
features: ['use-case-observability'], | ||
description: 'test_description', | ||
permissions: { | ||
library_write: { | ||
users: [`${Cypress.env('username')}`], | ||
groups: ['admin_group', 'new_admin_group'], | ||
}, | ||
write: { | ||
users: [`${Cypress.env('username')}`], | ||
groups: ['admin_group', 'new_admin_group'], | ||
}, | ||
library_read: { | ||
users: ['read_user', 'new_read_user'], | ||
}, | ||
read: { | ||
users: ['read_user', 'new_read_user'], | ||
}, | ||
}, | ||
}; | ||
cy.checkWorkspace(workspaceId, expectedWorkspace); | ||
}); | ||
|
||
it('should change access level successfully', () => { | ||
cy.get('table') | ||
.contains('td', 'read_user') | ||
.parent('tr') | ||
.within(() => { | ||
cy.get('input[type="checkbox"]').check(); | ||
}); | ||
cy.get('table') | ||
.contains('td', 'admin_group') | ||
.parent('tr') | ||
.within(() => { | ||
cy.get('input[type="checkbox"]').check(); | ||
}); | ||
|
||
cy.getElementByTestId( | ||
'workspace-detail-collaborator-table-actions' | ||
).click(); | ||
cy.get('div[role="dialog"]') | ||
.find('span') | ||
.contains('Change access level') | ||
.click(); | ||
cy.get('div[role="dialog"]') | ||
.find('span') | ||
.contains('Read and write') | ||
.click(); | ||
cy.getElementByTestId('confirmModalConfirmButton').click(); | ||
|
||
cy.contains('read_user'); | ||
|
||
cy.get('table') | ||
.contains('td', 'read_user') | ||
.parent() | ||
.within(() => { | ||
cy.get('td').eq(3).contains('Read and write'); | ||
}); | ||
cy.get('table') | ||
.contains('td', 'admin_group') | ||
.parent() | ||
.within(() => { | ||
cy.get('td').eq(3).contains('Read and write'); | ||
}); | ||
const expectedWorkspace = { | ||
name: workspaceName, | ||
features: ['use-case-observability'], | ||
description: 'test_description', | ||
permissions: { | ||
library_write: { | ||
users: [`${Cypress.env('username')}`, 'read_user'], | ||
groups: ['admin_group'], | ||
}, | ||
write: { | ||
users: [`${Cypress.env('username')}`], | ||
}, | ||
read: { | ||
groups: ['admin_group'], | ||
users: ['read_user'], | ||
}, | ||
}, | ||
}; | ||
cy.checkWorkspace(workspaceId, expectedWorkspace); | ||
}); | ||
|
||
it('should delete collaborators successfully', () => { | ||
cy.get('table') | ||
.contains('td', 'read_user') | ||
.parent('tr') | ||
.within(() => { | ||
cy.get('input[type="checkbox"]').check(); | ||
}); | ||
cy.get('table') | ||
.contains('td', 'admin_group') | ||
.parent('tr') | ||
.within(() => { | ||
cy.get('input[type="checkbox"]').check(); | ||
}); | ||
|
||
cy.getElementByTestId('confirm-delete-button').click(); | ||
cy.getElementByTestId('confirmModalConfirmButton').click(); | ||
|
||
cy.contains('read_user').should('not.exist'); | ||
cy.contains('admin_group').should('not.exist'); | ||
const expectedWorkspace = { | ||
name: workspaceName, | ||
features: ['use-case-observability'], | ||
description: 'test_description', | ||
permissions: { | ||
library_write: { | ||
users: ['admin'], | ||
}, | ||
write: { | ||
users: ['admin'], | ||
}, | ||
}, | ||
}; | ||
cy.checkWorkspace(workspaceId, expectedWorkspace); | ||
}); | ||
}); | ||
} |