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

[Backport 2.x] Add workspace initial page functional tests #1641

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,17 @@
{
"cluster_permissions": ["*"],
"index_permissions": [
{
"index_patterns": ["*"],
"fls": [],
"masked_fields": [],
"allowed_actions": ["*"]
}
],
"tenant_permissions": [
{
"tenant_patterns": ["*"],
"allowed_actions": ["kibana_all_write"]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"users": ["workspace-test"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"password": "testUserPassword123"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { ADMIN_AUTH } from '../../../../utils/commands';
import workspaceTestUser from '../../../../fixtures/dashboard/opensearch_dashboards/workspace/workspaceTestUser.json';
import workspaceTestRole from '../../../../fixtures/dashboard/opensearch_dashboards/workspace/workspaceTestRole.json';
import workspaceTestRoleMapping from '../../../../fixtures/dashboard/opensearch_dashboards/workspace/workspaceTestRoleMapping.json';

const miscUtils = new MiscUtils(cy);
const workspaceName = 'test_workspace';
let workspaceId;
let workspaceFeatures = ['use-case-observability'];
const NONE_DASHBOARDS_ADMIN_USERNAME = 'workspace-test';
const WORKSPACE_TEST_ROLE_NAME = 'workspace-test-role';

if (Cypress.env('WORKSPACE_ENABLED')) {
describe('Workspace initial', () => {
describe('OSD admin user visits workspace initial page', () => {
before(() => {
cy.deleteWorkspaceByName(workspaceName);
cy.createWorkspace({
name: workspaceName,
features: workspaceFeatures,
settings: {
permissions: {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
},
},
}).then((value) => (workspaceId = value));
});

beforeEach(() => {
// Visit workspace initial page
miscUtils.visitPage(`/app/home`);
});

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

it('should contain correct content', () => {
// Contain initial page title and description
cy.contains('Welcome to OpenSearch').should('exist');
cy.contains('My workspaces').should('exist');
cy.contains(
'Collaborate on use-case based projects with workspaces. Select a workspace to get started.'
).should('exist');

// Contain five use case title
cy.contains('Observability').should('exist');
cy.contains('Security Analytics').should('exist');
cy.contains('Search').should('exist');
cy.contains('Essentials').should('exist');
cy.contains('Analytics').should('exist');

// Contain no workspace message
cy.contains('No workspaces').should('exist');
cy.contains(
'Create a workspace or request a workspace owner to add you as a collaborator.'
).should('exist');

// Contain created workspaces
cy.contains(workspaceName).should('exist');
cy.contains(
'Gain visibility into system health, performance, and reliability through monitoring of logs, metrics and traces.'
).should('not.exist');

// Contain correct link
cy.contains('a', 'Learn more from documentation').should('exist');
cy.get(
'a[href="https://opensearch.org/docs/latest/opensearch/index/"]'
).should('have.attr', 'target', '_blank');
cy.contains(
'a',
'Explore live demo environment at playground.opensearch.org'
).should('exist');
cy.get('a[href="https://playground.opensearch.org/"]').should(
'have.attr',
'target',
'_blank'
);

// Contain left bottom button
cy.get('[id$="popoverForSettingsIcon"]').should('exist');
cy.getElementByTestId('openDevToolsModal').should('exist');
if (Cypress.env('SECURITY_ENABLED')) {
cy.getElementByTestId('account-popover').should('exist');
}
});

it('should show correct use case information', () => {
cy.getElementByTestId(
'workspace-initial-useCaseCard-observability-button-information'
).click();
cy.contains('Use cases').should('exist');
cy.contains(
'Gain visibility into system health, performance, and reliability through monitoring of logs, metrics and traces.'
).should('exist');
});

it('should navigate to the workspace', () => {
cy.contains(workspaceName).click();

cy.location('pathname', { timeout: 6000 }).should(
'include',
`/w/${workspaceId}/app/`
);
});

it('should return user to homepage when clicking home icon and show correct recent access message', () => {
cy.contains(workspaceName).click();
cy.location('pathname', { timeout: 6000 }).should(
'include',
`/w/${workspaceId}/app/`
);
cy.get('button[aria-label="go-to-home"]').click();
cy.location('pathname', { timeout: 6000 }).should(
'include',
`/app/home`
);

cy.contains('Viewed a few seconds ago');
});

it('should click create button and navigate to workspace create page', () => {
// Click the create button at the upper right corner
cy.getElementByTestId(
'workspace-initial-card-createWorkspace-button'
).click();

cy.getElementByTestId(
'workspace-initial-button-create-essentials-workspace'
).click();
cy.location('pathname', { timeout: 6000 }).should(
'include',
`/app/workspace_create`
);
cy.location('hash').should('include', 'useCase=Essentials');

cy.getElementByTestId('workspaceUseCase-essentials')
.get(`input[type="radio"]`)
.should('be.checked');

miscUtils.visitPage(`/app/home`);
// Click the use case create icon button
cy.getElementByTestId(
'workspace-initial-useCaseCard-observability-button-createWorkspace'
).click();

cy.location('pathname', { timeout: 6000 }).should(
'include',
`/app/workspace_create`
);
cy.location('hash').should('include', 'useCase=Observability');

cy.getElementByTestId('workspaceUseCase-observability')
.get(`input[type="radio"]`)
.should('be.checked');

miscUtils.visitPage(`/app/home`);
// Click the create button in no workspace message
cy.getElementByTestId(
'workspace-initial-useCaseCard-search-button-createWorkspace'
).click();

cy.location('pathname', { timeout: 6000 }).should(
'include',
`/app/workspace_create`
);
cy.location('hash').should('include', 'useCase=Search');

cy.getElementByTestId('workspaceUseCase-search')
.get(`input[type="radio"]`)
.should('be.checked');
});

it('should navigate to workspace list page with use case filter', () => {
// Click will all button in the use case card
cy.getElementByTestId(
'workspace-initial-useCaseCard-observability-button-view'
).click();
cy.location('pathname', { timeout: 6000 }).should(
'include',
`/app/workspace_list`
);
cy.location('hash').should('include', 'useCase=Observability');
cy.contains(workspaceName).should('exist');

// Default filtering based on use cases
cy.get('input[type="search"]').should(
'have.value',
'useCase:"Observability"'
);

miscUtils.visitPage(`/app/home`);
// Click will all workspace button
cy.contains('View all workspaces').click();
cy.location('pathname', { timeout: 6000 }).should(
'include',
`/app/workspace_list`
);

cy.contains(workspaceName).should('exist');
cy.get('input[type="search"]').should('have.value', '');
});
});

if (Cypress.env('SECURITY_ENABLED')) {
describe('Non OSD admin user visits workspace initial page', () => {
const originalUser = ADMIN_AUTH.username;
const originalPassword = ADMIN_AUTH.password;
before(() => {
cy.createInternalUser(
NONE_DASHBOARDS_ADMIN_USERNAME,
workspaceTestUser
);
cy.createRole(WORKSPACE_TEST_ROLE_NAME, workspaceTestRole);
cy.createRoleMapping(
WORKSPACE_TEST_ROLE_NAME,
workspaceTestRoleMapping
);
});
beforeEach(() => {
// Login as non OSD admin user
ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USERNAME;
ADMIN_AUTH.newPassword = workspaceTestUser.password;
// Visit workspace initial page
miscUtils.visitPage(`/app/home`);
});
after(() => {
ADMIN_AUTH.newUser = originalUser;
ADMIN_AUTH.newPassword = originalPassword;
cy.deleteRoleMapping(WORKSPACE_TEST_ROLE_NAME);
cy.deleteInternalUser(NONE_DASHBOARDS_ADMIN_USERNAME);
cy.deleteRole(WORKSPACE_TEST_ROLE_NAME);
});

it('should show correct no workspaces content', () => {
cy.contains('Welcome to OpenSearch').should('exist');

// Contain correct no workspaces message
cy.contains('No workspaces').should('exist');
cy.contains(
'Request a workspace owner to add you as a collaborator.'
).should('exist');

// Not contain the create buttons
cy.getElementByTestId(
'workspace-initial-card-createWorkspace-button'
).should('not.exist');
cy.getElementByTestId(
'workspace-initial-useCaseCard-observability-button-createWorkspace'
).should('not.exist');
cy.getElementByTestId(
'workspace-initial-useCaseCard-search-button-createWorkspace'
).should('not.exist');
});
});
}
});
}
24 changes: 24 additions & 0 deletions cypress/utils/plugins/security-dashboards-plugin/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Cypress.Commands.add('createInternalUser', (userID, userJson) => {
cy.wait(10000);
});

Cypress.Commands.add('deleteInternalUser', (userID) => {
cy.request(
'DELETE',
`${Cypress.env('openSearchUrl')}${SEC_API.INTERNALUSERS_BASE}/${userID}`
);
cy.wait(10000);
});

Cypress.Commands.add('createRole', (roleID, roleJson) => {
cy.request(
'PUT',
Expand All @@ -38,6 +46,14 @@ Cypress.Commands.add('createRole', (roleID, roleJson) => {
cy.wait(10000);
});

Cypress.Commands.add('deleteRole', (roleID) => {
cy.request(
'DELETE',
`${Cypress.env('openSearchUrl')}${SEC_API.ROLE_BASE}/${roleID}`
);
cy.wait(10000);
});

Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => {
cy.request(
'PUT',
Expand All @@ -46,3 +62,11 @@ Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => {
);
cy.wait(10000);
});

Cypress.Commands.add('deleteRoleMapping', (roleID) => {
cy.request(
'DELETE',
`${Cypress.env('openSearchUrl')}${SEC_API.ROLE_MAPPING_BASE}/${roleID}`
);
cy.wait(10000);
});
Loading