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

[Workspace] add tests for workspace collaborators page #1632

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add one more test for search and filter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our initial plan is to cover basic tests, let us cover these in the next stage.

Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
* 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')) {
describe('Workspace collaborators', () => {
before(() => {
cy.deleteWorkspaceByName(workspaceName);
cy.createWorkspace({
name: workspaceName,
features: ['use-case-observability'],
settings: {
permissions: {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
},
},
}).then((value) => (workspaceId = value));
});

beforeEach(() => {
// Visit workspace collaborators page
miscUtils.visitPage(`w/${workspaceId}/app/workspace_collaborators`);
});

after(() => {
cy.deleteWorkspaceById(workspaceId);
});

it('should successfully load the page', () => {
if (Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED')) {
raintygao marked this conversation as resolved.
Show resolved Hide resolved
cy.contains('Collaborators', { timeout: 60000 }).should('be.visible');
}
});

if (
Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') &&
Cypress.env('SECURITY_ENABLED')
raintygao marked this conversation as resolved.
Show resolved Hide resolved
) {
describe('Update collaborators', () => {
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(
'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(
'admin_group'
);
cy.get('span[title="Admin"]').click();
cy.get('button[type="submit"]')
.contains('span', 'Add collaborators')
.click();

cy.wait(2000); // Intentional Wait
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about we doing assertion here instead of waiting for 2s, it seems unreliable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mainly used for waiting page load after navigation or wait stored data update after operation.


cy.get('table')
.contains('td', 'read_user')
.parent()
.within(() => {
cy.get('td').eq(3).contains('Read only');
});

cy.get('table')
.contains('td', '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'],
},
write: {
users: [`${Cypress.env('username')}`],
groups: ['admin_group'],
},
library_read: {
users: ['read_user'],
},
read: {
users: ['read_user'],
},
},
};
cy.checkWorkspace(workspaceId, expectedWorkspace);
});

it('should change access level successfully', () => {
raintygao marked this conversation as resolved.
Show resolved Hide resolved
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.wait(2000); // Intentional Wait

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.wait(2000); // Intentional Wait

const expectedWorkspace = {
name: workspaceName,
features: ['use-case-observability'],
description: 'test_description',
permissions: {
library_write: {
users: ['admin'],
},
write: {
users: ['admin'],
},
},
};
cy.checkWorkspace(workspaceId, expectedWorkspace);
});
});
}
});
}
Loading