From ec00c93086b85baf23e756783295f54453f3bfe6 Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Fri, 6 Dec 2024 11:21:27 +0800 Subject: [PATCH] Update integration tests with privacy setting features Signed-off-by: Lin Wang --- .../mds_workspace_collaborators.cases.js | 117 ++++++++++++++++ .../test-cases/mds_workspace_create.cases.js | 33 +++++ .../test-cases/mds_workspace_detail.cases.js | 130 ++++++++++++++++-- 3 files changed, 267 insertions(+), 13 deletions(-) diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases.js index 3f17723df..888d83647 100644 --- a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases.js +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases.js @@ -5,6 +5,21 @@ import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +const updatePrivacySetting = (settingId) => { + cy.getElementByTestId('workspaceCollaborators-privacySetting-edit').click(); + cy.getElementByTestId('workspacePrivacySettingSelector').click({ + force: true, + }); + cy.get(`#${settingId}`).click({ force: true }); + cy.getElementByTestId('workspaceCollaborators-privacySetting-save').click({ + force: true, + }); + + cy.getElementByTestId('workspaceCollaborators-privacySetting-save').should( + 'not.exist' + ); +}; + export const WorkspaceCollaboratorsTestCases = () => { const miscUtils = new MiscUtils(cy); const workspaceName = 'test_workspace_collaborators'; @@ -209,6 +224,108 @@ export const WorkspaceCollaboratorsTestCases = () => { }; cy.checkWorkspace(workspaceId, expectedWorkspace); }); + + it('should change to "anyone can read" successfully', () => { + updatePrivacySetting('anyone-can-view'); + + 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 to "anyone can edit" successfully', () => { + updatePrivacySetting('anyone-can-edit'); + + 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 back to "private to collaborators" successfully', () => { + updatePrivacySetting('anyone-can-view'); + cy.checkWorkspace(workspaceId, { + 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', '*'], + }, + }, + }); + + updatePrivacySetting('private-to-collaborators'); + cy.checkWorkspace(workspaceId, { + 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'], + }, + }, + }); + }); }); } }; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases.js index 13879d79f..da2fb42ea 100644 --- a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases.js +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases.js @@ -156,6 +156,37 @@ export const WorkspaceCreateTestCases = () => { cy.deleteWorkspaceByName(workspaceName); inputWorkspaceName(workspaceName); inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('jumpToCollaboratorsCheckbox').click({ + force: true, + }); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click( + { + force: true, + } + ); + + let workspaceId; + cy.wait('@createWorkspaceRequest').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + workspaceId = interception.response.body.result.id; + + cy.location('pathname', { timeout: 6000 }).should( + 'include', + `w/${workspaceId}/app/workspace_collaborators` + ); + }); + }); + + it('should creating a workspace with privacy setting', () => { + cy.deleteWorkspaceByName(workspaceName); + inputWorkspaceName(workspaceName); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.get('#anyone-can-edit').click(); + cy.getElementByTestId('jumpToCollaboratorsCheckbox') + .should('be.enabled') + .click({ + force: true, + }); cy.getElementByTestId('workspaceForm-bottomBar-createButton').click( { force: true, @@ -171,6 +202,8 @@ export const WorkspaceCreateTestCases = () => { 'include', `w/${workspaceId}/app/workspace_collaborators` ); + + cy.contains('Anyone can edit').should('be.exist'); }); }); } diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases.js index aeb72573f..f754dcdae 100644 --- a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases.js +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases.js @@ -18,6 +18,20 @@ export const WorkspaceDetailTestCases = () => { let workspaceDescription = 'This is a workspace description.'; let workspaceId; let workspaceFeatures = ['use-case-observability']; + const workspaceBaseData = { + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + color: '#54B399', + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + library_read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, + read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, + }, + }, + }; if (Cypress.env('WORKSPACE_ENABLED')) { describe('Workspace detail', () => { @@ -34,19 +48,9 @@ export const WorkspaceDetailTestCases = () => { ); } cy.deleteWorkspaceByName(workspaceName); - cy.createWorkspace({ - name: workspaceName, - description: workspaceDescription, - features: workspaceFeatures, - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - library_read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, - read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, - }, - }, - }).then((value) => (workspaceId = value)); + cy.createWorkspace(workspaceBaseData).then( + (value) => (workspaceId = value) + ); }); after(() => { @@ -294,6 +298,106 @@ export const WorkspaceDetailTestCases = () => { }); }); }); + + describe('update with different privacy settings', () => { + before(() => { + // Visit workspace update page + miscUtils.visitPage(`w/${workspaceId}/app/workspace_detail`); + }); + + afterEach(() => { + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-edit' + ).click(); + cy.getElementByTestId('workspacePrivacySettingSelector').click({ + force: true, + }); + cy.get('#private-to-collaborators').click({ force: true }); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click( + { force: true } + ); + cy.getElementByTestId( + 'workspaceForm-bottomBar-updateButton' + ).should('not.exist'); + cy.checkWorkspace(workspaceId, { + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + library_read: { + users: [NONE_DASHBOARDS_ADMIN_USERNAME], + }, + read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, + }, + }); + }); + + it('should able to update privacy setting to anyone can read', () => { + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-edit' + ).click(); + cy.getElementByTestId('workspacePrivacySettingSelector').click({ + force: true, + }); + cy.get('#anyone-can-view').click({ force: true }); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click( + { force: true } + ); + + cy.getElementByTestId( + 'workspaceForm-bottomBar-updateButton' + ).should('not.exist'); + + const expectedWorkspace = { + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + library_read: { + users: [NONE_DASHBOARDS_ADMIN_USERNAME, '*'], + }, + read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME, '*'] }, + }, + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + + it('should able to update privacy setting to anyone can write', () => { + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-edit' + ).click(); + cy.getElementByTestId('workspacePrivacySettingSelector').click({ + force: true, + }); + cy.get('#anyone-can-edit').click({ force: true }); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click( + { force: true } + ); + + cy.getElementByTestId( + 'workspaceForm-bottomBar-updateButton' + ).should('not.exist'); + + const expectedWorkspace = { + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + permissions: { + library_write: { users: ['%me%', '*'] }, + write: { users: ['%me%'] }, + library_read: { + users: [NONE_DASHBOARDS_ADMIN_USERNAME], + }, + read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME, '*'] }, + }, + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + }); } }); }