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 functional test for workspace overview page #1246

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
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({
Copy link
Member

Choose a reason for hiding this comment

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

Nit: just curious why we need to add force: true, is it being covered by other elements?

Copy link
Collaborator Author

@Hailong-am Hailong-am Apr 29, 2024

Choose a reason for hiding this comment

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

covered by
image when doing test in local

Copy link
Collaborator

@wanglam wanglam Apr 29, 2024

Choose a reason for hiding this comment

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

Seems the root cause of this toast is CSP restriction. Could we create a separate issue and add related config like OSD cypress workflow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

create a issue #1252 to track this.

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) => {
Hailong-am marked this conversation as resolved.
Show resolved Hide resolved
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.workspaceName} failed!`);
Hailong-am marked this conversation as resolved.
Show resolved Hide resolved
}
});
});
Expand Down
Loading