Skip to content

Commit

Permalink
workspace overview
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Apr 29, 2024
1 parent f4ae3df commit 2666392
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 16 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
@@ -0,0 +1,115 @@
/*
* 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({
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 });
// dashboars and visualization cards are visiable
cy.get('div[data-test-subj="workspaceGetStartCards"')
.as('getStartCards')
.should('be.visible');
cy.get('@getStartCards').contains('with Dashboards');
cy.get('@getStartCards').contains('with Visualizations');

// 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 });
// dashboars and visualization cards are visiable
cy.getElementByTestId('workspaceGetStartCards')
.as('getStartCards')
.should('be.visible');
cy.get('@getStartCards').contains('with Dashboards');
cy.get('@getStartCards').contains('with Visualizations');

// 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);
});

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');

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`);
});
});
}
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({ 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
9 changes: 5 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,16 @@ Cypress.Commands.add('createWorkspace', (workspaceName) => {
},
body: {
attributes: {
name: workspaceName,
description: 'test_description',
name: workspace.workspaceName,
description: workspace.description || 'test_description',
features: workspace.features,
},
},
}).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.workspaceName} failed!`);
}
});
});
Expand Down

0 comments on commit 2666392

Please sign in to comment.