Skip to content

Commit

Permalink
[Workspace] Add functional tests for create/update workspace page (#1221
Browse files Browse the repository at this point in the history
)

* Test creating and updating workspace

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Format the code

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Format the code

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Optimize the code

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Enable acl

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Optimize some code

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Refine error message

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Small change

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Fix typo and add some comments

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Fix test failure

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Fix test failure

Signed-off-by: gaobinlong <gbinlong@amazon.com>

---------

Signed-off-by: gaobinlong <gbinlong@amazon.com>
Co-authored-by: Yulong Ruan <ruanyl@amazon.com>
  • Loading branch information
gaobinlong and ruanyl authored Apr 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7680793 commit f4ae3df
Showing 7 changed files with 557 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workspace-release-e2e-workflow.yml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ jobs:
uses: ./.github/workflows/release-e2e-workflow-template.yml
with:
test-name: dashboards workspace
test-command: env CYPRESS_WORKSPACE_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/*'
test-command: env CYPRESS_WORKSPACE_ENABLED=true CYPRESS_SAVED_OBJECTS_PERMISSION_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/*'
osd-serve-args: --workspace.enabled=true --savedObjects.permission.enabled=true --opensearch_security.multitenancy.enabled=false
tests-without-security:
needs: changes
@@ -31,4 +31,4 @@ jobs:
test-name: dashboards workspace
test-command: env CYPRESS_WORKSPACE_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/*'
osd-serve-args: --workspace.enabled=true --savedObjects.permission.enabled=false
security-enabled: false
security-enabled: false
3 changes: 2 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
"ML_COMMONS_DASHBOARDS_ENABLED": true,
"WAIT_FOR_LOADER_BUFFER_MS": 0,
"DASHBOARDS_ASSISTANT_ENABLED": false,
"WORKSPACE_ENABLED": false
"WORKSPACE_ENABLED": false,
"SAVED_OBJECTS_PERMISSION_ENABLED": false
}
}
Original file line number Diff line number Diff line change
@@ -3,41 +3,183 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { BASE_PATH } from '../../../../utils/constants';

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
const miscUtils = new MiscUtils(cy);
const workspaceName = 'test_workspace_az3RBx6cE';
if (Cypress.env('WORKSPACE_ENABLED')) {
let workspaceId;
describe('Workspace CRUD APIs', () => {
describe('Create a workspace', () => {
it('should successfully create a worksapce', () => {
const body = {
attributes: {
name: 'test_workspace',
describe('Create workspace', () => {
before(() => {
cy.deleteWorkspaceByName(workspaceName);
});

beforeEach(() => {
// Visit workspace create page
miscUtils.visitPage('app/workspace_create');

cy.intercept('POST', '/api/workspaces').as('createWorkspaceRequest');
});

after(() => {
cy.deleteWorkspaceByName(workspaceName);
});

it('should successfully load the page', () => {
cy.contains('Create Workspace', { timeout: 60000 });
});

describe('Create a workspace successfully', () => {
it('should successfully create a workspace', () => {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-nameInputText'
).type(workspaceName);
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId(
'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker'
).type('#000000');
cy.getElementByTestId(
'workspaceForm-workspaceFeatureVisibility-OpenSearch Dashboards'
).check({ force: true });
cy.get('[id$="discover"]').uncheck({ force: true });
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();

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',
'app/workspace_overview'
);

const expectedWorkspace = {
name: workspaceName,
description: 'test_workspace_description',
},
};
cy.request({
method: 'POST',
url: `${BASE_PATH}/api/workspaces`,
headers: {
'osd-xsrf': true,
},
body: body,
}).as('createWorkspace');
cy.get('@createWorkspace').should((res) => {
workspaceId = res.body.result.id;
expect(res.body.success).to.eql(true);
features: [
'dashboards',
'visualize',
'workspace_update',
'workspace_overview',
],
};
cy.checkWorkspace(workspaceId, expectedWorkspace);
});
});
});
after(() => {
cy.request({
method: 'DELETE',
url: `${BASE_PATH}/api/workspaces/${workspaceId}`,
headers: {
'osd-xsrf': true,
},

describe('Validate workspace name and description', () => {
it('workspace name is required', () => {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.contains("Name can't be empty").should('exist');
});

it('workspace name is not valid', () => {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-nameInputText'
).type('./+');
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.contains('Invalid workspace name').should('exist');
});

it('workspace name cannot use an existing name', () => {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-nameInputText'
).type(workspaceName);
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.contains('workspace name has already been used').should('exist');
});

it('workspace description is not valid', () => {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-nameInputText'
).type(workspaceName);
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('./+');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.contains('Invalid workspace description').should('exist');
});
});

if (
Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') &&
Cypress.env('SECURITY_ENABLED')
) {
describe('Create a workspace with permissions successfully', () => {
before(() => {
cy.deleteWorkspaceByName(workspaceName);
});

it('should successfully create a workspace with permissions', () => {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-nameInputText'
).type(workspaceName);
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId(
'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker'
).type('#000000');
cy.getElementByTestId(
'workspaceForm-workspaceFeatureVisibility-OpenSearch Dashboards'
).check({ force: true });
cy.get('[id$="discover"]').uncheck({ force: true });
cy.get('button').contains('Users & Permissions').click();
cy.getElementByTestId(
'workspaceForm-permissionSettingPanel-user-addNew'
).click();
cy.getElementByTestId('comboBoxSearchInput')
.last()
.type('test_user_sfslja260');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();

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',
'app/workspace_overview'
);
const expectedWorkspace = {
name: workspaceName,
description: 'test_workspace_description',
features: [
'dashboards',
'visualize',
'workspace_update',
'workspace_overview',
],
permissions: {
read: {
users: ['test_user_sfslja260'],
},
library_read: {
users: ['test_user_sfslja260'],
},
write: {
users: [`${Cypress.env('username')}`],
},
library_write: {
users: [`${Cypress.env('username')}`],
},
},
};
cy.checkWorkspace(workspaceId, expectedWorkspace);
});
});
});
}
});
}
Loading

0 comments on commit f4ae3df

Please sign in to comment.