Skip to content

Commit

Permalink
[Workspace] Add functional test for workspace overview page (#1246)
Browse files Browse the repository at this point in the history
* workspace overview

Signed-off-by: Hailong Cui <[email protected]>

* update create workspace

Signed-off-by: Hailong Cui <[email protected]>

* address review comments

Signed-off-by: Hailong Cui <[email protected]>

* Add assertion

Signed-off-by: Hailong Cui <[email protected]>

* fix workspacd name

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am authored Apr 30, 2024
1 parent c18b673 commit 1b19f50
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
'workspaceForm-workspaceFeatureVisibility-OpenSearch Dashboards'
).check({ force: true });
cy.get('[id$="discover"]').uncheck({ force: true });
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({
force: true,
});

let workspaceId;
cy.wait('@createWorkspaceRequest').then((interception) => {
Expand Down Expand Up @@ -74,7 +76,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({
force: true,
});
cy.contains("Name can't be empty").should('exist');
});

Expand All @@ -85,7 +89,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({
force: true,
});
cy.contains('Invalid workspace name').should('exist');
});

Expand All @@ -96,7 +102,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({
force: true,
});
cy.contains('workspace name has already been used').should('exist');
});

Expand All @@ -107,7 +115,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('./+');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({
force: true,
});
cy.contains('Invalid workspace description').should('exist');
});
});
Expand Down Expand Up @@ -142,7 +152,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId('comboBoxSearchInput')
.last()
.type('test_user_sfslja260');
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({
force: true,
});

let workspaceId;
cy.wait('@createWorkspaceRequest').then((interception) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.deleteAllWorkspaces();

for (const workspaceName of workspaceNames) {
cy.createWorkspace(workspaceName).then((workspaceId) => {
cy.createWorkspace({ name: workspaceName }).then((workspaceId) => {
workspaceNameIdMapping[workspaceName] = workspaceId;
});
}
Expand Down Expand Up @@ -98,10 +98,11 @@ if (Cypress.env('WORKSPACE_ENABLED')) {

// Create 3 more workspaces so that there are more than 5 workspaces in the system
for (const workspaceName of newWorkspaceNames) {
cy.createWorkspace(workspaceName);
cy.createWorkspace({ name: workspaceName });
}

cy.wait(1000);
cy.reload();

cy.getElementByTestId('toggleNavButton').click();
cy.get('#workspaceDropdownMenu').click();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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 currentDate = Date.now();
const workspaceName = 'foo-workspace' + currentDate;
const workspaceDescription = 'foo-workspace-desc' + currentDate;

if (Cypress.env('WORKSPACE_ENABLED')) {
let workspaceId = '';

describe('Workspace overview', () => {
before(() => {
cy.createWorkspace({
name: workspaceName,
description: workspaceDescription,
features: [
'management',
'discover',
'workspace_overview',
'workspace_update',
'dashboards',
'visualize',
],
}).then((id) => {
workspaceId = id;
});
cy.log(`workspace ${workspaceName} create successfully`);
});

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

beforeEach(() => {
// Visit workspace overview page
cy.intercept('GET', `/w/${workspaceId}/api/workspaces/${workspaceId}`).as(
'getWorkspace'
);
miscUtils.visitPage(`/w/${workspaceId}/app/workspace_overview`);
cy.wait('@getWorkspace');
});

it('should successfully load the page', () => {
// workspace name is correctly displayed
cy.contains(workspaceName, { timeout: 60000 }).should('be.visible');
// dashboars and visualization cards are visiable
cy.get('div[data-test-subj="workspaceGetStartCards"')
.as('getStartCards')
.should('be.visible');
cy.get('@getStartCards').contains('with Dashboards').should('be.visible');
cy.get('@getStartCards')
.contains('with Visualizations')
.should('be.visible');

// tabs
cy.getElementByTestId('workspaceTabs')
.find('.euiTab')
.as('tabs')
.should('have.length', 3);
});

it('should collpase start working section when collpase button clicked', () => {
// workspace name is correctly displayed
cy.contains(workspaceName, { timeout: 60000 }).should('be.visible');
// dashboars and visualization cards are visiable
cy.getElementByTestId('workspaceGetStartCards')
.as('getStartCards')
.should('be.visible');
cy.get('@getStartCards').contains('with Dashboards').should('be.visible');
cy.get('@getStartCards')
.contains('with Visualizations')
.should('be.visible');

// click Collpase
cy.getElementByTestId('Collapse').click();
cy.get('@getStartCards').should('not.exist');

// click Expand
cy.getElementByTestId('Expand').click();
cy.get('@getStartCards').should('be.visible');
});

it('should display workspace description correctly in overview tab', () => {
// click on overview tab
cy.get('div[data-test-subj="workspaceTabs"] #overview').click();
cy.contains(workspaceDescription).should('be.visible');
});

it('should redirect to saved objects page when click on library tab', () => {
// click on library tab
cy.get('div[data-test-subj="workspaceTabs"] #library').click();
cy.location('pathname', { timeout: 6000 }).should(
'include',
'app/management/opensearch-dashboards/objects'
);
});

it('should show wokrspace update when click on settings tab', () => {
// click on settings tab
cy.getElementByTestId('workspaceTabs').find('#settings').click();
cy.contains('Workspace Details').should('be.visible');

cy.getElementByTestId('workspaceForm-workspaceDetails-nameInputText')
.clear()
.type(`${workspaceDescription}-updated`);
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({
force: true,
});

// workspace update successfully and overview page refreshed
cy.contains('h1', `${workspaceDescription}-updated`).should('be.visible');
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
describe('Update workspace', () => {
before(() => {
cy.deleteWorkspaceByName(workspaceName);
cy.createWorkspace(workspaceName).then((value) => (workspaceId = value));
cy.createWorkspace({ name: workspaceName }).then(
(value) => (workspaceId = value)
);
});

beforeEach(() => {
Expand Down Expand Up @@ -47,7 +49,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({
force: true,
});
cy.contains("Name can't be empty").should('exist');
});

Expand All @@ -68,7 +72,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('test_workspace_description');
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({
force: true,
});
cy.contains('Invalid workspace name').should('exist');
});

Expand All @@ -81,7 +87,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId(
'workspaceForm-workspaceDetails-descriptionInputText'
).type('./+');
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({
force: true,
});
cy.contains('Invalid workspace description').should('exist');
});
});
Expand Down Expand Up @@ -110,7 +118,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId(
'workspaceForm-workspaceFeatureVisibility-OpenSearch Dashboards'
).check({ force: true });
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({
force: true,
});
cy.wait('@updateWorkspaceRequest').then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
Expand Down Expand Up @@ -169,7 +179,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) {
cy.getElementByTestId('comboBoxSearchInput')
.last()
.type('test_user_Fnxs972xC');
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click();
cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({
force: true,
});
cy.wait('@updateWorkspaceRequest').then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
Expand Down
8 changes: 4 additions & 4 deletions cypress/utils/dashboards/workspace-plugin/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Cypress.Commands.add('deleteWorkspaceByName', (workspaceName) => {
});
});

Cypress.Commands.add('createWorkspace', (workspaceName) => {
Cypress.Commands.add('createWorkspace', (workspace) => {
cy.request({
method: 'POST',
url: `${BASE_PATH}${WORKSPACE_API_PREFIX}`,
Expand All @@ -50,15 +50,15 @@ Cypress.Commands.add('createWorkspace', (workspaceName) => {
},
body: {
attributes: {
name: workspaceName,
description: 'test_description',
...workspace,
description: workspace.description || 'test_description',
},
},
}).then((resp) => {
if (resp && resp.body && resp.body.success) {
return resp.body.result.id;
} else {
throw new Error(`Create workspace ${workspaceName} failed!`);
throw new Error(`Create workspace ${workspace.name} failed!`);
}
});
});
Expand Down

0 comments on commit 1b19f50

Please sign in to comment.