From 0ae4c07951e4e57023fb2b033fc206539894f686 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 27 Nov 2024 17:54:42 +0800 Subject: [PATCH] refactor: use function to make test cases reusable (#1659) Signed-off-by: SuZhou-Joe --- .../mds_workspace_acl.spec.js | 228 +----------- .../mds_workspace_analytics_overviews.spec.js | 151 +------- .../mds_workspace_assets.spec.js | 180 +--------- .../mds_workspace_association.spec.js | 75 +--- .../mds_workspace_breadcrumbs.spec.js | 153 +------- .../mds_workspace_collaborators.spec.js | 207 +---------- .../mds_workspace_create.spec.js | 320 +---------------- .../mds_workspace_delete.spec.js | 178 +--------- .../mds_workspace_detail.spec.js | 280 +-------------- .../mds_workspace_essential_overviews.spec.js | 152 +------- ...ds_workspace_import_sample_data_to.spec.js | 156 +------- .../mds_workspace_initial.spec.js | 267 +------------- .../mds_workspace_search_overviews.spec.js | 88 +---- .../test-cases/mds_workspace_acl.cases.js | 236 +++++++++++++ ...mds_workspace_analytics_overviews.cases.js | 163 +++++++++ .../test-cases/mds_workspace_assets.cases.js | 191 ++++++++++ .../mds_workspace_association.cases.js | 86 +++++ .../mds_workspace_breadcrumbs.cases.js | 165 +++++++++ .../mds_workspace_collaborators.cases.js | 214 +++++++++++ .../test-cases/mds_workspace_create.cases.js | 334 ++++++++++++++++++ .../test-cases/mds_workspace_delete.cases.js | 185 ++++++++++ .../test-cases/mds_workspace_detail.cases.js | 300 ++++++++++++++++ ...mds_workspace_essential_overviews.cases.js | 164 +++++++++ ...s_workspace_import_sample_data_to.cases.js | 175 +++++++++ .../test-cases/mds_workspace_initial.cases.js | 273 ++++++++++++++ .../mds_workspace_search_overviews.cases.js | 94 +++++ 26 files changed, 2606 insertions(+), 2409 deletions(-) create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_acl.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_analytics_overviews.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_assets.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_association.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_breadcrumbs.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_delete.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_essential_overviews.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_initial.cases.js create mode 100644 cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_search_overviews.cases.js diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_acl.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_acl.spec.js index 86c03c4e6..fd9fdd400 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_acl.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_acl.spec.js @@ -3,230 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { BASE_PATH } from '../../../../utils/base_constants'; -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 { WORKSPACE_API_PREFIX } from '../../../../utils/dashboards/workspace-plugin/constants'; +import { WorkspaceACLTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_acl.cases'; -let noPermissionWorkspaceName = 'acl_no_permission_workspace'; -let readOnlyWorkspaceName = 'acl_readonly_workspace'; -let libraryWriteWorkspaceName = 'acl_library_write_workspace'; -let ownerWorkspaceName = 'acl_owner_workspace'; - -let noPermissionWorkspaceId = ''; -let readOnlyWorkspaceId = ''; -let libraryWriteWorkspaceId = ''; -let ownerWorkspaceId = ''; -let datasourceId = ''; - -const getPolicy = (permission, userName) => ({ - [permission]: { - users: [userName], - }, -}); - -const NON_DASHBOARDS_ADMIN_USERNAME = 'workspace-acl-test'; -const WORKSPACE_TEST_ROLE_NAME = 'workspace-acl-test-role'; - -const ACLPolicyMap = { - [noPermissionWorkspaceName]: {}, - [readOnlyWorkspaceName]: { - ...getPolicy('read', NON_DASHBOARDS_ADMIN_USERNAME), - ...getPolicy('library_read', NON_DASHBOARDS_ADMIN_USERNAME), - }, - [libraryWriteWorkspaceName]: { - ...getPolicy('read', NON_DASHBOARDS_ADMIN_USERNAME), - ...getPolicy('library_write', NON_DASHBOARDS_ADMIN_USERNAME), - }, - [ownerWorkspaceName]: { - ...getPolicy('write', NON_DASHBOARDS_ADMIN_USERNAME), - ...getPolicy('library_write', NON_DASHBOARDS_ADMIN_USERNAME), - }, -}; - -const setupWorkspace = (workspaceName, datasourceId) => { - return cy - .createWorkspace({ - name: workspaceName, - settings: { - ...(datasourceId ? { dataSources: [datasourceId] } : {}), - permissions: ACLPolicyMap[workspaceName], - }, - }) - .then((value) => { - // load sample data - cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId); - cy.wrap(value); - }); -}; - -const setupAllTheWorkspaces = () => { - setupWorkspace(noPermissionWorkspaceName, datasourceId).then( - (value) => (noPermissionWorkspaceId = value) - ); - setupWorkspace(readOnlyWorkspaceName, datasourceId).then( - (value) => (readOnlyWorkspaceId = value) - ); - setupWorkspace(libraryWriteWorkspaceName, datasourceId).then( - (value) => (libraryWriteWorkspaceId = value) - ); - setupWorkspace(ownerWorkspaceName, datasourceId).then( - (value) => (ownerWorkspaceId = value) - ); -}; - -if ( - Cypress.env('WORKSPACE_ENABLED') && - Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && - Cypress.env('SECURITY_ENABLED') -) { - describe('Workspace ACL', () => { - const originalUser = ADMIN_AUTH.username; - const originalPassword = ADMIN_AUTH.password; - before(() => { - cy.deleteWorkspaceByName(noPermissionWorkspaceName); - cy.deleteWorkspaceByName(readOnlyWorkspaceName); - cy.deleteWorkspaceByName(libraryWriteWorkspaceName); - cy.deleteWorkspaceByName(ownerWorkspaceName); - - cy.createInternalUser(NON_DASHBOARDS_ADMIN_USERNAME, workspaceTestUser); - cy.createRole(WORKSPACE_TEST_ROLE_NAME, workspaceTestRole); - cy.createRoleMapping(WORKSPACE_TEST_ROLE_NAME, { - users: [NON_DASHBOARDS_ADMIN_USERNAME], - }); - - if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { - cy.createDataSourceNoAuth().then((result) => { - datasourceId = result[0]; - expect(datasourceId).to.be.a('string').that.is.not.empty; - setupAllTheWorkspaces(datasourceId); - }); - } else { - setupAllTheWorkspaces(datasourceId); - } - }); - - after(() => { - ADMIN_AUTH.newUser = originalUser; - ADMIN_AUTH.newPassword = originalPassword; - cy.removeSampleDataForWorkspace( - 'ecommerce', - ownerWorkspaceId, - datasourceId - ); - cy.deleteWorkspaceByName(noPermissionWorkspaceName); - cy.deleteWorkspaceByName(readOnlyWorkspaceName); - cy.deleteWorkspaceByName(libraryWriteWorkspaceName); - cy.deleteWorkspaceByName(ownerWorkspaceName); - if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { - cy.deleteDataSource(datasourceId); - } - readOnlyWorkspaceId = ''; - libraryWriteWorkspaceId = ''; - - cy.deleteRoleMapping(WORKSPACE_TEST_ROLE_NAME); - cy.deleteInternalUser(NON_DASHBOARDS_ADMIN_USERNAME); - cy.deleteRole(WORKSPACE_TEST_ROLE_NAME); - }); - - describe('Normal user', () => { - beforeEach(() => { - ADMIN_AUTH.newUser = NON_DASHBOARDS_ADMIN_USERNAME; - ADMIN_AUTH.newPassword = workspaceTestUser.password; - }); - - it('Normal user should not be able to create workspace', () => { - cy.request({ - method: 'POST', - url: `${BASE_PATH}${WORKSPACE_API_PREFIX}`, - headers: { - 'osd-xsrf': true, - }, - body: { - attributes: { - name: 'test_workspace', - features: ['use-case-observability'], - description: 'test_description', - }, - }, - failOnStatusCode: false, - }).then((resp) => - cy - .wrap(resp.body.error) - .should('equal', 'Invalid permission, please contact OSD admin') - ); - }); - - it('Normal users should only see the workspaces they have permission with', () => { - cy.visit(`${BASE_PATH}/app/home`); - cy.contains(readOnlyWorkspaceName); - cy.contains(noPermissionWorkspaceName).should('not.exist'); - }); - - it('Readonly users should not be allowed to update dashboards/visualizations within the workspace', () => { - cy.visit(`${BASE_PATH}/w/${readOnlyWorkspaceId}/app/visualize`); - cy.contains(/\[eCommerce\] Markdown/).click(); - cy.getElementByTestId('visualizeSaveButton').click(); - cy.getElementByTestId('confirmSaveSavedObjectButton').click(); - cy.contains('Forbidden'); - }); - - it('Normal users should not be allowed to visit workspace he/she has no permission', () => { - cy.visit(`${BASE_PATH}/w/${noPermissionWorkspaceId}/app/objects`); - cy.contains('Invalid saved objects permission'); - }); - - it('Normal users should only see the workspaces he has library_write permission in the target workspaces list of duplicate modal', () => { - cy.visit(`${BASE_PATH}/w/${readOnlyWorkspaceId}/app/objects`); - cy.getElementByTestId('savedObjectsTableRowTitle').should('exist'); - cy.getElementByTestId('duplicateObjects') - .click() - .getElementByTestId('savedObjectsDuplicateModal') - .find('[data-test-subj="comboBoxInput"]') - .click(); - - cy.contains(libraryWriteWorkspaceName); - cy.contains(ownerWorkspaceName); - cy.contains(noPermissionWorkspaceName).should('not.exist'); - }); - - it('Users should not be able to update default index pattern / default data source if he/she is not the workspace owner', () => { - cy.visit(`${BASE_PATH}/w/${libraryWriteWorkspaceId}/app/indexPatterns`); - cy.contains('opensearch_dashboards_sample_data_ecommerce').click(); - cy.getElementByTestId('setDefaultIndexPatternButton').click(); - cy.contains('Unable to update UI setting'); - }); - - it('Normal users should not be able to find objects from other workspaces when inside a workspace', () => { - cy.visit(`${BASE_PATH}/w/${readOnlyWorkspaceId}/app/objects`); - cy.getElementByTestId('savedObjectsTableRowTitle').should('exist'); - cy.getElementByTestId( - 'savedObjectsTableColumn-workspace_column' - ).should('not.exist'); - cy.contains('opensearch_dashboards_sample_data_ecommerce'); - // Electron old version may not support search event, so we manually trigger a search event - cy.getElementByTestId('savedObjectSearchBar') - .type('opensearch_dashboards_sample_data_ecommerce{enter}') - .trigger('search'); - cy.getElementByTestId('savedObjectsTableRowTitle').should( - 'have.length', - 1 - ); - }); - - if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { - it('Normal users should not be able to associate / dissociate data sources from workspace.', () => { - cy.visit(`${BASE_PATH}/w/${ownerWorkspaceId}/app/dataSources`); - cy.contains('Data sources'); - cy.getElementByTestId('workspaceAssociateDataSourceButton').should( - 'not.exist' - ); - cy.getElementByTestId( - 'dataSourcesManagement-dataSourceTable-dissociateButton' - ).should('not.exist'); - }); - } - }); - }); -} +WorkspaceACLTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_analytics_overviews.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_analytics_overviews.spec.js index 67dd454d1..15dbe1715 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_analytics_overviews.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_analytics_overviews.spec.js @@ -3,153 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { WorkspaceAnalyticsOverviewTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_analytics_overviews.cases'; -const miscUtils = new MiscUtils(cy); -const workspaceName = `test_workspace_analytics_${Math.random() - .toString(36) - .substring(7)}`; -let workspaceDescription = 'This is a analytics workspace description.'; -let workspaceId; -let datasourceId; -let workspaceFeatures = ['use-case-all']; - -const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); - -if (Cypress.env('WORKSPACE_ENABLED')) { - const createWorkspace = (dsId) => { - cy.createWorkspace({ - name: workspaceName, - description: workspaceDescription, - features: workspaceFeatures, - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - }, - ...(dsId ? { dataSources: [dsId] } : {}), - }, - }).then((value) => { - workspaceId = value; - // load sample data - cy.loadSampleDataForWorkspace('ecommerce', value, dsId); - }); - }; - - describe('Analytics workspace overview', () => { - before(() => { - cy.deleteWorkspaceByName(workspaceName); - if (MDSEnabled) { - cy.deleteAllDataSources(); - cy.createDataSourceNoAuth().then((result) => { - datasourceId = result[0]; - expect(datasourceId).to.be.a('string').that.is.not.empty; - createWorkspace(datasourceId); - }); - } else { - createWorkspace(); - } - }); - - after(() => { - if (workspaceId) { - cy.removeSampleDataForWorkspace('ecommerce', workspaceId, datasourceId); - cy.deleteWorkspaceById(workspaceId); - } - cy.deleteAllDataSources(); - }); - - beforeEach(() => { - // Visit workspace update page - miscUtils.visitPage(`w/${workspaceId}/app/all_overview`); - // wait for page load - cy.contains('h1', 'Overview'); - }); - - it('should display get started sections', () => { - cy.get('.euiCard__footer').contains('Observability').should('be.visible'); - // this is depends on observability plugin been installed - // cy.url().should('include', 'app/observability-overview'); - - cy.get('.euiCard__footer') - .contains('Security Analytics') - .should('be.visible'); - // this is depends on security analytics plugin been installed - // cy.url().should('include', 'app/sa_overview'); - - cy.get('.euiCard__footer') - .contains('Search') - .should('be.visible') - .click(); - cy.url().should('include', 'app/search_overview'); - }); - - it('should display asset section correctly', () => { - // no recently view assets - cy.contains('No assets to display'); - - // recentlyCard - cy.contains('Recently updated').should('be.visible').click(); - // should have 6 elements - cy.getElementByTestId('recentlyCard').should('have.length', 6); - - // filter by dashboard - cy.getElementByTestId('comboBoxInput').click(); - cy.get('span.euiComboBoxOption__content').contains('dashboard').click(); - - // click dashboard card - cy.getElementByTestId('recentlyCard').first().click(); - - // verify url has /app/dashboards - cy.url().should('include', 'app/dashboards'); - - cy.go('back'); - - // view all - cy.contains('View all').click(); - // verify url has /app/objects - cy.url().should('include', 'app/objects'); - }); - - // Alerts and threat Alerts cards are depends on plugins - - it('should display OpenSearch Documentation panel', () => { - cy.contains('OpenSearch Documentation').should('be.visible'); - cy.get('.euiLink') - .contains('Quickstart guide') - .should('be.visible') - .and('have.attr', 'href') - .and((href) => { - expect(href).to.match( - /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/quickstart\/$/ - ); - }); - cy.get('.euiLink') - .contains('Building data visualizations') - .should('be.visible') - .and('have.attr', 'href') - .and((href) => { - expect(href).to.match( - /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/visualize\/viz-index\/$/ - ); - }); - cy.get('.euiLink') - .contains('Creating dashboards') - .should('be.visible') - .and('have.attr', 'href') - .and((href) => { - expect(href).to.match( - /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/dashboard\/index\/$/ - ); - }); - cy.contains('Learn more in Documentation') - .should('be.visible') - .and('have.attr', 'href') - .and((href) => { - expect(href).to.match( - /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/index\/$/ - ); - }); - }); - }); -} +WorkspaceAnalyticsOverviewTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_assets.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_assets.spec.js index d371d79c8..f1fa0dff1 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_assets.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_assets.spec.js @@ -3,182 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { BASE_PATH } from '../../../../utils/base_constants'; +import { WorkspaceAssetsTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_assets.cases'; -let sourceWorkspaceName = 'test_source_workspace'; -let targetWorkspaceName = 'test_target_workspace'; - -let sourceWorkspaceId = ''; -let targetWorkspaceId = ''; -let datasourceId = ''; - -const setupWorkspace = (workspaceName, datasourceId) => { - return cy - .createWorkspace({ - name: workspaceName, - settings: { - ...(datasourceId ? { dataSources: [datasourceId] } : {}), - }, - }) - .then((value) => { - // load sample data - cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId); - cy.wrap(value); - }); -}; - -if (Cypress.env('WORKSPACE_ENABLED')) { - describe('Workspace assets', () => { - before(() => { - cy.deleteWorkspaceByName(sourceWorkspaceName); - cy.deleteWorkspaceByName(targetWorkspaceName); - if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { - cy.createDataSourceNoAuth().then((result) => { - datasourceId = result[0]; - expect(datasourceId).to.be.a('string').that.is.not.empty; - setupWorkspace(sourceWorkspaceName, datasourceId).then( - (value) => (sourceWorkspaceId = value) - ); - setupWorkspace(targetWorkspaceName, datasourceId).then( - (value) => (targetWorkspaceId = value) - ); - }); - } else { - setupWorkspace(sourceWorkspaceName).then( - (value) => (sourceWorkspaceId = value) - ); - setupWorkspace(targetWorkspaceName).then( - (value) => (targetWorkspaceId = value) - ); - } - }); - - after(() => { - // Uninstallation will delete the data index - // and workspace deletion will remove all the saved objects within the workspace, - // so calling `removeSampleDataForWorkspace` once is good enough. - cy.removeSampleDataForWorkspace( - 'ecommerce', - sourceWorkspaceId, - datasourceId - ); - cy.deleteWorkspaceByName(sourceWorkspaceName); - cy.deleteWorkspaceByName(targetWorkspaceName); - if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { - cy.deleteDataSource(datasourceId); - } - sourceWorkspaceId = ''; - targetWorkspaceId = ''; - }); - - it('Should not list assets from other workspace and generate correct url for inspect url inside a workspace', () => { - cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/objects`); - cy.getElementByTestId('savedObjectsTableRowTitle').should('exist'); - cy.getElementByTestId('savedObjectsTableColumn-workspace_column').should( - 'not.exist' - ); - cy.contains('opensearch_dashboards_sample_data_ecommerce'); - // Electron old version may not support search event, so we manually trigger a search event - cy.getElementByTestId('savedObjectSearchBar') - .type('opensearch_dashboards_sample_data_ecommerce{enter}') - .trigger('search'); - cy.getElementByTestId('savedObjectsTableRowTitle').should( - 'have.length', - 1 - ); - - // Click more -> inspect - cy.getElementByTestId('euiCollapsedItemActionsButton') - .click() - .getElementByTestId('savedObjectsTableAction-inspect') - .click(); - cy.location('pathname').should( - 'include', - `/w/${sourceWorkspaceId}/app/indexPatterns` - ); - }); - - it('Should list assets from workspaces with permission and generate correct url for inspect url outside workspace', () => { - cy.visit(`${BASE_PATH}/app/objects`); - cy.getElementByTestId('savedObjectsTableColumn-workspace_column').should( - 'exist' - ); - // Electron old version may not support search event, so we manually trigger a search event - cy.getElementByTestId('savedObjectSearchBar') - .type('opensearch_dashboards_sample_data_ecommerce{enter}') - .trigger('search'); - cy.getElementByTestId('savedObjectsTableRowTitle').should( - 'have.length', - 2 - ); - - // Find the row belong to the target workspace - cy.contains(targetWorkspaceName) - .parents('.euiTableRow') - // Click more -> inspect - .find('[data-test-subj="euiCollapsedItemActionsButton"]') - .click() - .getElementByTestId('savedObjectsTableAction-inspect') - .click(); - cy.location('pathname').should( - 'include', - `/w/${targetWorkspaceId}/app/indexPatterns` - ); - }); - - // TODO: this test case should be removed once index pattern access outside of workspace being blocked in the future. - it('Should not show set as default button when outside workspace', () => { - cy.request({ - url: `${BASE_PATH}/api/opensearch-dashboards/management/saved_objects/_find?workspaces=${targetWorkspaceId}&page=1&type=index-pattern`, - headers: { - 'Osd-Xsrf': 'osd-fetch', - }, - }) - .then((resp) => { - cy.wrap(resp.body.saved_objects).should('have.length', 1); - cy.wrap(resp.body.saved_objects[0].id); - }) - .then((indexPatternId) => { - cy.visit(`${BASE_PATH}/app/indexPatterns/patterns/${indexPatternId}`); - cy.contains('opensearch_dashboards_sample_data_ecommerce'); - cy.getElementByTestId('setDefaultIndexPatternButton').should( - 'not.exist' - ); - }); - }); - - it('Short url should be able to be generated multiple times and preserve workspace info', () => { - cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/visualize`); - cy.contains(/\[eCommerce\] Markdown/).click(); - cy.getElementByTestId('shareTopNavButton') - .click() - .getElementByTestId('sharePanel-Permalinks') - .click() - .getElementByTestId('useShortUrl') - .as('generateShortUrlButton') - .click(); - - // Should generate successfully - cy.getElementByTestId('copyShareUrlButton') - .invoke('attr', 'data-share-url') - .should('include', `${BASE_PATH}/goto`); - - // Regeneration should work without error - cy.get('@generateShortUrlButton').click(); - cy.getElementByTestId('copyShareUrlButton') - .invoke('attr', 'data-share-url') - .should('include', `${BASE_PATH}/w/${sourceWorkspaceId}`); - cy.get('@generateShortUrlButton').click(); - cy.getElementByTestId('copyShareUrlButton') - .invoke('attr', 'data-share-url') - .then((shortUrl) => { - cy.wrap(shortUrl).should('include', `${BASE_PATH}/goto`); - cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/objects`); - cy.contains('Workspace assets'); - cy.visit(shortUrl); - cy.location('pathname').should('include', `/w/${sourceWorkspaceId}`); - cy.contains(/\[eCommerce\] Markdown/); - }); - }); - }); -} +WorkspaceAssetsTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_association.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_association.spec.js index 453a5ab3d..9f68d4685 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_association.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_association.spec.js @@ -3,77 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; -const miscUtils = new MiscUtils(cy); -const workspaceName = 'test_workspace_collaborators'; -let workspaceId; -let dataSourceTitle1 = 'no_auth_data_source_title_1'; -let dataSourceTitle2 = 'no_auth_data_source_title_2'; -let dataSourceId1; -let dataSourceId2; -if ( - Cypress.env('WORKSPACE_ENABLED') && - Cypress.env('DATASOURCE_MANAGEMENT_ENABLED') -) { - describe('Workspace association data source', () => { - before(() => { - cy.createDataSourceNoAuth({ title: dataSourceTitle1 }).then((result) => { - dataSourceId1 = result[0]; - }); - cy.createDataSourceNoAuth({ title: dataSourceTitle2 }).then((result) => { - dataSourceId2 = result[0]; - }); - }); - beforeEach(() => { - cy.deleteWorkspaceByName(workspaceName); - //Create a workspace before each test - cy.createWorkspace({ - name: workspaceName, - features: ['use-case-observability'], - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - }, - }, - }).then((value) => { - workspaceId = value; - }); - }); +import { WorkspaceAssociationTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_association.cases'; - after(() => { - cy.deleteDataSource(dataSourceId1); - cy.deleteDataSource(dataSourceId2); - }); - afterEach(() => { - cy.deleteWorkspaceById(workspaceId); - }); - - it('should associate and dissociate data source successfully', () => { - miscUtils.visitPage(`w/${workspaceId}/app/dataSources`); - - cy.getElementByTestId('workspaceAssociateDataSourceButton').click(); - cy.contains('OpenSearch data sources').click(); - cy.contains(dataSourceTitle1, { - withinSubject: parent.document.body, - }).click({ force: true }); - cy.contains(dataSourceTitle2, { - withinSubject: parent.document.body, - }).click({ force: true }); - cy.getElementByTestId( - 'workspace-detail-dataSources-associateModal-save-button' - ).click(); - - // The table is updated after successful association - cy.contains('table', dataSourceTitle1); - cy.contains('table', dataSourceTitle2); - - // The table is updated after successful dissociation - cy.getElementByTestId('checkboxSelectAll').check(); - cy.getElementByTestId('dissociateSelectedDataSources').click(); - cy.getElementByTestId('confirmModalConfirmButton').click(); - cy.contains('table', dataSourceTitle1).should('not.exist'); - cy.contains('table', dataSourceTitle2).should('not.exist'); - }); - }); -} +WorkspaceAssociationTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_breadcrumbs.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_breadcrumbs.spec.js index 8f1ca5002..3af0cb8b0 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_breadcrumbs.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_breadcrumbs.spec.js @@ -3,155 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { WorkspaceBreadcrumbsTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_breadcrumbs.cases'; -const miscUtils = new MiscUtils(cy); -const workspaceName = `test_workspace_analytics_${Math.random() - .toString(36) - .substring(7)}`; -let workspaceDescription = 'This is a analytics workspace description.'; -let workspaceId; -let workspaceFeatures = ['use-case-all']; - -if (Cypress.env('WORKSPACE_ENABLED')) { - const createWorkspace = () => { - cy.createWorkspace({ - name: workspaceName, - description: workspaceDescription, - features: workspaceFeatures, - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - }, - }, - }).then((value) => { - workspaceId = value; - }); - }; - - describe('Breadcrumbs in workspace', () => { - before(() => { - cy.deleteWorkspaceByName(workspaceName); - createWorkspace(); - }); - - after(() => { - if (workspaceId) { - cy.deleteWorkspaceById(workspaceId); - } - }); - - it('should show workspace name in breadcrumbs', () => { - miscUtils.visitPage(`w/${workspaceId}/app/objects`); - - // get div with class newTopNavHeader - cy.get('.newTopNavHeader').within(() => { - cy.getElementByTestId('breadcrumb first') - .should('exist') - .within(() => { - // Check for the icon - cy.getElementByTestId(`${workspaceId}-icon`).should('exist'); - // Check for the workspace name - cy.contains(workspaceName).should('exist').click(); - // click on breadcrumbs goes to overview page - cy.url().should('include', `w/${workspaceId}/app/all_overview`); - }); - }); - }); - - it('should show breadcrumbs in recent popover', () => { - miscUtils.visitPage(`w/${workspaceId}/app/workspace_detail`); - // wait for page load - cy.contains('h1', 'Workspace details'); - // waiting for page load completely - cy.getElementByTestId('recentItemsSectionButton').should( - 'not.have.class', - 'headerRecentItemsButton--loadingIndicator', - { - timeout: 10000, - } - ); - cy.wait(1000); - cy.getElementByTestId('recentItemsSectionButton').click({ force: true }); - - cy.get('.euiPopover__panel').within(() => { - cy.getElementByTestId('breadcrumbs').within(() => { - // Check for the icon - cy.getElementByTestId(`${workspaceId}-icon`).should('exist'); - // Check for the workspace name - cy.contains(workspaceName).should('exist'); - // page title exists in breadcrumbs - cy.contains('Workspace details'); - }); - }); - }); - }); - - describe('Breadcrumbs out of workspace', () => { - it('breadcrumbs display correctly in settings and setup', () => { - miscUtils.visitPage('app/workspace_list'); - cy.contains('h1', 'Workspaces'); - - cy.get('.newTopNavHeader').within(() => { - cy.getElementByTestId('breadcrumb first') - .should('exist') - .within(() => { - // Check for the use case name - cy.contains('Settings and setup').click(); - cy.url().should('include', 'app/settings_landing'); - }); - }); - - // check breadcrumbs in recent popover - cy.getElementByTestId('recentItemsSectionButton').should( - 'not.have.class', - 'headerRecentItemsButton--loadingIndicator', - { - timeout: 10000, - } - ); - cy.wait(1000); - cy.getElementByTestId('recentItemsSectionButton').click({ force: true }); - - cy.get('.euiPopover__panel').within(() => { - cy.getElementByTestId('breadcrumbs').within(() => { - cy.contains('Settings and setup'); - cy.contains('Settings and setup overview'); - }); - }); - }); - - it('breadcrumbs display correctly in data administration', () => { - miscUtils.visitPage('app/data_administration_landing'); - cy.contains('h1', 'Data administration overview'); - - cy.get('.newTopNavHeader').within(() => { - cy.getElementByTestId('breadcrumb first') - .should('exist') - .within(() => { - // Check for the use case name - cy.contains('Data administration'); - }); - }); - - // check breadcrumbs in recent popover - cy.getElementByTestId('recentItemsSectionButton').should( - 'not.have.class', - 'headerRecentItemsButton--loadingIndicator', - { - timeout: 10000, - } - ); - cy.wait(1000); - cy.getElementByTestId('recentItemsSectionButton').click({ force: true }); - - cy.get('.euiPopover__panel').within(() => { - cy.getElementByTestId('breadcrumbs').within(() => { - cy.contains('Data administration'); - cy.contains('Data administration overview'); - }); - }); - }); - }); -} +WorkspaceBreadcrumbsTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_collaborators.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_collaborators.spec.js index 1350790fa..e74ccec28 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_collaborators.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_collaborators.spec.js @@ -3,209 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; -const miscUtils = new MiscUtils(cy); -const workspaceName = 'test_workspace_collaborators'; -let workspaceId; +import { WorkspaceCollaboratorsTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases'; -if ( - Cypress.env('WORKSPACE_ENABLED') && - Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && - Cypress.env('SECURITY_ENABLED') -) { - describe('Workspace collaborators', () => { - beforeEach(() => { - cy.deleteWorkspaceByName(workspaceName); - //Create a workspace before each test - cy.createWorkspace({ - name: workspaceName, - features: ['use-case-observability'], - settings: { - permissions: { - library_write: { - users: [`${Cypress.env('username')}`], - groups: ['admin_group'], - }, - write: { - users: [`${Cypress.env('username')}`], - groups: ['admin_group'], - }, - library_read: { - users: ['read_user'], - }, - read: { - users: ['read_user'], - }, - }, - }, - }).then((value) => { - workspaceId = value; - miscUtils.visitPage(`w/${value}/app/workspace_collaborators`); - }); - }); - - afterEach(() => { - cy.deleteWorkspaceById(workspaceId); - }); - - it('should add user and group collaborators successfully', () => { - //Add user - cy.getElementByTestId('add-collaborator-popover').click(); - cy.get('button[id="user"]').click(); - cy.contains('Add Users').should('be.visible'); - cy.getElementByTestId('workspaceCollaboratorIdInput-0').type( - 'new_read_user' - ); - cy.get('button[type="submit"]') - .contains('span', 'Add collaborators') - .click(); - - //Add group - cy.getElementByTestId('add-collaborator-popover').click(); - cy.get('button[id="group"]').click(); - cy.contains('Add Groups').should('be.visible'); - cy.getElementByTestId('workspaceCollaboratorIdInput-0').type( - 'new_admin_group' - ); - cy.get('span[title="Admin"]').click(); - cy.get('button[type="submit"]') - .contains('span', 'Add collaborators') - .click(); - - cy.contains('new_read_user'); - - cy.get('table') - .contains('td', 'new_read_user') - .parent() - .within(() => { - cy.get('td').eq(3).contains('Read only'); - }); - - cy.get('table') - .contains('td', 'new_admin_group') - .parent() - .within(() => { - cy.get('td').eq(3).contains('Admin'); - }); - const expectedWorkspace = { - name: workspaceName, - features: ['use-case-observability'], - description: 'test_description', - permissions: { - library_write: { - users: [`${Cypress.env('username')}`], - groups: ['admin_group', 'new_admin_group'], - }, - write: { - users: [`${Cypress.env('username')}`], - groups: ['admin_group', 'new_admin_group'], - }, - library_read: { - users: ['read_user', 'new_read_user'], - }, - read: { - users: ['read_user', 'new_read_user'], - }, - }, - }; - cy.checkWorkspace(workspaceId, expectedWorkspace); - }); - - it('should change access level successfully', () => { - cy.get('table') - .contains('td', 'read_user') - .parent('tr') - .within(() => { - cy.get('input[type="checkbox"]').check(); - }); - cy.get('table') - .contains('td', 'admin_group') - .parent('tr') - .within(() => { - cy.get('input[type="checkbox"]').check(); - }); - - cy.getElementByTestId( - 'workspace-detail-collaborator-table-actions' - ).click(); - cy.get('div[role="dialog"]') - .find('span') - .contains('Change access level') - .click(); - cy.get('div[role="dialog"]') - .find('span') - .contains('Read and write') - .click(); - cy.getElementByTestId('confirmModalConfirmButton').click(); - - cy.contains('read_user'); - - cy.get('table') - .contains('td', 'read_user') - .parent() - .within(() => { - cy.get('td').eq(3).contains('Read and write'); - }); - cy.get('table') - .contains('td', 'admin_group') - .parent() - .within(() => { - cy.get('td').eq(3).contains('Read and write'); - }); - const expectedWorkspace = { - name: workspaceName, - features: ['use-case-observability'], - description: 'test_description', - permissions: { - library_write: { - users: [`${Cypress.env('username')}`, 'read_user'], - groups: ['admin_group'], - }, - write: { - users: [`${Cypress.env('username')}`], - }, - read: { - groups: ['admin_group'], - users: ['read_user'], - }, - }, - }; - cy.checkWorkspace(workspaceId, expectedWorkspace); - }); - - it('should delete collaborators successfully', () => { - cy.get('table') - .contains('td', 'read_user') - .parent('tr') - .within(() => { - cy.get('input[type="checkbox"]').check(); - }); - cy.get('table') - .contains('td', 'admin_group') - .parent('tr') - .within(() => { - cy.get('input[type="checkbox"]').check(); - }); - - cy.getElementByTestId('confirm-delete-button').click(); - cy.getElementByTestId('confirmModalConfirmButton').click(); - - cy.contains('read_user').should('not.exist'); - cy.contains('admin_group').should('not.exist'); - const expectedWorkspace = { - name: workspaceName, - features: ['use-case-observability'], - description: 'test_description', - permissions: { - library_write: { - users: ['admin'], - }, - write: { - users: ['admin'], - }, - }, - }; - cy.checkWorkspace(workspaceId, expectedWorkspace); - }); - }); -} +WorkspaceCollaboratorsTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_create.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_create.spec.js index c133bdc65..29e4c0e6e 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_create.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_create.spec.js @@ -3,322 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { WorkspaceCreateTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases'; -const miscUtils = new MiscUtils(cy); -const workspaceName = 'test_workspace_az3RBx6cE'; -const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); - -const inputWorkspaceName = (workspaceName) => { - const nameInputTestId = 'workspaceForm-workspaceDetails-nameInputText'; - cy.getElementByTestId(nameInputTestId).clear(); - cy.getElementByTestId(nameInputTestId).type(workspaceName); -}; - -const inputDataSourceWhenMDSEnabled = (dataSourceTitle) => { - if (!MDSEnabled) { - return; - } - cy.getElementByTestId('workspace-creator-dataSources-assign-button').click(); - - cy.get(`li[title="${dataSourceTitle}"]`).click(); - - cy.getElementByTestId( - 'workspace-detail-dataSources-associateModal-save-button' - ).click(); -}; - -if (Cypress.env('WORKSPACE_ENABLED')) { - describe('Create workspace', () => { - let dataSourceTitle; - before(() => { - cy.deleteWorkspaceByName(workspaceName); - if (MDSEnabled) { - cy.deleteAllDataSources(); - cy.createDataSourceNoAuth().then((result) => { - dataSourceTitle = result[1]; - }); - } - }); - - beforeEach(() => { - // Visit workspace create page - miscUtils.visitPage('app/workspace_create'); - - cy.intercept('POST', '/api/workspaces').as('createWorkspaceRequest'); - }); - - after(() => { - cy.deleteWorkspaceByName(workspaceName); - if (MDSEnabled) { - cy.deleteAllDataSources(); - } - }); - - it('should successfully load the page', () => { - cy.contains('Create a workspace', { timeout: 60000 }); - }); - - describe('Create a workspace successfully', () => { - it('should successfully create a workspace', () => { - inputWorkspaceName(workspaceName); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description.+~!'); - cy.getElementByTestId('workspaceUseCase-observability').click({ - force: true, - }); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, - }); - - 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', - `w/${workspaceId}/app` - ); - - const expectedWorkspace = { - name: workspaceName, - description: 'test_workspace_description.+~!', - features: ['use-case-observability'], - }; - cy.checkWorkspace(workspaceId, expectedWorkspace); - }); - }); - - it('should successfully create a workspace from home page', () => { - cy.deleteWorkspaceByName(workspaceName); - miscUtils.visitPage('app/workspace_initial'); - cy.getElementByTestId( - 'workspace-initial-card-createWorkspace-button' - ).click({ - force: true, - }); - cy.getElementByTestId( - 'workspace-initial-button-create-observability-workspace' - ).click({ - force: true, - }); - cy.contains('Observability') - .first() - .closest('.euiCheckableCard-isChecked') - .should('exist'); - - miscUtils.visitPage('app/workspace_initial'); - cy.getElementByTestId( - 'workspace-initial-useCaseCard-security-analytics-button-createWorkspace' - ).click({ - force: true, - }); - cy.contains('Security Analytics') - .first() - .closest('.euiCheckableCard-isChecked') - .should('exist'); - - inputWorkspaceName(workspaceName); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, - }); - - 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', - `w/${workspaceId}/app` - ); - - const expectedWorkspace = { - name: workspaceName, - features: ['use-case-security-analytics'], - }; - cy.checkWorkspace(workspaceId, expectedWorkspace); - }); - }); - - if ( - Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && - Cypress.env('SECURITY_ENABLED') - ) { - it('should successfully jump to collaborators page after creating a workspace', () => { - cy.deleteWorkspaceByName(workspaceName); - inputWorkspaceName(workspaceName); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, - }); - - 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', - `w/${workspaceId}/app/workspace_collaborators` - ); - }); - }); - } - - it('should correctly display the summary card', () => { - inputWorkspaceName(workspaceName); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description.+~!'); - cy.getElementByTestId('workspaceUseCase-essentials').click({ - force: true, - }); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.get('.workspaceCreateRightSidebar').within(() => { - cy.contains(workspaceName).should('exist'); - cy.contains('test_workspace_description.+~!').should('exist'); - cy.contains('Essentials').should('exist'); - if (MDSEnabled) { - cy.contains(dataSourceTitle).should('exist'); - } - }); - }); - }); - - describe('Validate workspace name and description', () => { - it('workspace name is required', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).clear(); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, - }); - cy.contains('Enter a name.').should('exist'); - }); - - it('workspace name is not valid', () => { - inputWorkspaceName('./+'); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description'); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, - }); - cy.contains('Enter a valid name.').should('exist'); - }); - - it('workspace name cannot use an existing name', () => { - cy.deleteWorkspaceByName(workspaceName); - cy.createWorkspace({ - name: workspaceName, - features: ['use-case-observability'], - }); - inputWorkspaceName(workspaceName); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description'); - cy.getElementByTestId('workspaceUseCase-observability').click({ - force: true, - }); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, - }); - cy.contains('workspace name has already been used').should('exist'); - }); - }); - - if (MDSEnabled) { - describe('Create a workspace with associated data sources', () => { - before(() => { - cy.deleteWorkspaceByName(workspaceName); - }); - - it('should be exists inside workspace data source list', () => { - inputWorkspaceName(workspaceName); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description'); - cy.getElementByTestId('workspaceUseCase-observability').click({ - force: true, - }); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, - }); - - cy.wait('@createWorkspaceRequest') - .then((interception) => { - expect(interception.response.statusCode).to.equal(200); - return interception.response.body.result.id; - }) - .then((workspaceId) => { - const dataSourcePathname = `w/${workspaceId}/app/dataSources`; - miscUtils.visitPage(dataSourcePathname); - cy.location('pathname', { timeout: 6000 }).should( - 'include', - dataSourcePathname - ); - cy.contains(dataSourceTitle).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', () => { - inputWorkspaceName(workspaceName); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description'); - cy.getElementByTestId('workspaceUseCase-observability').click({ - force: true, - }); - inputDataSourceWhenMDSEnabled(dataSourceTitle); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, - }); - - 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', - `w/${workspaceId}/app` - ); - const expectedWorkspace = { - name: workspaceName, - description: 'test_workspace_description', - features: ['use-case-observability'], - permissions: { - write: { - users: [`${Cypress.env('username')}`], - }, - library_write: { - users: [`${Cypress.env('username')}`], - }, - }, - }; - cy.checkWorkspace(workspaceId, expectedWorkspace); - }); - }); - }); - } - }); -} +WorkspaceCreateTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js index 0358f9b20..624a545d1 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_delete.spec.js @@ -3,180 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; -const miscUtils = new MiscUtils(cy); -const workspace1Name = 'test_workspace_320sdfouAz'; -let workspace1Description = 'This is a workspace1 description.'; -const workspace2Name = 'test_workspace_321sdfouAz'; -let workspace2Description = 'This is a workspace2 description.'; +import { WorkspaceDeleteTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_delete.cases'; -let workspace1Id; -let workspace2Id; - -if (Cypress.env('WORKSPACE_ENABLED')) { - describe('Delete Workspace(s) in 2 ways in workspace list page', () => { - before(() => { - cy.deleteWorkspaceByName(workspace1Name); - cy.deleteWorkspaceByName(workspace2Name); - }); - beforeEach(() => { - cy.createWorkspace({ - name: workspace1Name, - description: workspace1Description, - features: ['use-case-observability'], - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - }, - }, - }).then((value) => { - workspace1Id = value; - cy.intercept('DELETE', `/api/workspaces/${workspace1Id}`).as( - 'deleteWorkspace1Request' - ); - }); - - cy.createWorkspace({ - name: workspace2Name, - description: workspace2Description, - features: ['use-case-search'], - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - }, - }, - }).then((value) => { - workspace2Id = value; - cy.intercept('DELETE', `/api/workspaces/${workspace2Id}`).as( - 'deleteWorkspace2Request' - ); - }); - // Visit workspace list page - miscUtils.visitPage(`/app/workspace_list`); - }); - - afterEach(() => { - cy.deleteWorkspaceByName(workspace1Name); - cy.deleteWorkspaceByName(workspace2Name); - }); - - describe('delete a workspace successfully using action buttons', () => { - it('should successfully load delete button and show delete modal when clicking action button', () => { - cy.contains(workspace1Name).should('be.visible'); - cy.getElementByTestId(`checkboxSelectRow-${workspace1Id}`) - .parents('tr') - .within(() => { - cy.getElementByTestId('euiCollapsedItemActionsButton').click(); - }); - cy.getElementByTestId('workspace-list-delete-icon').should( - 'be.visible' - ); - cy.getElementByTestId('workspace-list-delete-icon').click(); - cy.contains('Delete workspace').should('be.visible'); - cy.contains( - 'The following workspace will be permanently deleted. This action cannot be undone' - ).should('be.visible'); - cy.contains(workspace1Name).should('be.visible'); - cy.getElementByTestId('delete-workspace-modal-input').type('delete'); - cy.getElementByTestId('delete-workspace-modal-confirm').click(); - cy.wait('@deleteWorkspace1Request').then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); - cy.location('pathname').should('include', 'app/workspace_list'); - cy.contains('Delete workspace successfully').should('be.visible'); - cy.contains(workspace1Name).should('not.exist'); - }); - }); - - describe('delete workspace(s) successfully using multi-deletion button', () => { - it('should successfully show multi-deletion button and perform deletion when choosing one workspace', () => { - cy.contains(workspace1Name).should('be.visible'); - cy.getElementByTestId(`checkboxSelectRow-${workspace1Id}`).click(); - cy.getElementByTestId('multi-deletion-button').should('be.visible'); - cy.getElementByTestId('multi-deletion-button').click(); - cy.contains('Delete workspace').should('be.visible'); - cy.contains( - 'The following workspace will be permanently deleted. This action cannot be undone' - ).should('be.visible'); - cy.contains(workspace1Name).should('be.visible'); - cy.getElementByTestId('delete-workspace-modal-input').type('delete'); - cy.getElementByTestId('delete-workspace-modal-confirm').click(); - cy.wait('@deleteWorkspace1Request').then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); - cy.location('pathname').should('include', 'app/workspace_list'); - cy.contains('Delete workspace successfully').should('be.visible'); - cy.contains(workspace1Name).should('not.exist'); - }); - - it('should successfully delete all', () => { - cy.contains(workspace1Name).should('be.visible'); - cy.contains(workspace2Name).should('be.visible'); - cy.getElementByTestId('checkboxSelectAll').click(); - cy.getElementByTestId('multi-deletion-button').should('be.visible'); - cy.getElementByTestId('multi-deletion-button').click(); - cy.contains('Delete workspace').should('be.visible'); - cy.contains( - 'The following workspace will be permanently deleted. This action cannot be undone' - ).should('be.visible'); - cy.contains(workspace1Name).should('be.visible'); - cy.contains(workspace2Name).should('be.visible'); - cy.getElementByTestId('delete-workspace-modal-input').type('delete'); - cy.getElementByTestId('delete-workspace-modal-confirm').click(); - cy.wait('@deleteWorkspace1Request').then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); - cy.location('pathname').should('include', 'app/workspace_list'); - cy.contains('Delete workspace successfully').should('be.visible'); - cy.contains(workspace1Name).should('not.exist'); - cy.contains(workspace2Name).should('not.exist'); - }); - }); - }); - - describe('Workspace deletion in workspace detail page', () => { - before(() => { - cy.deleteWorkspaceByName(workspace1Name); - cy.createWorkspace({ - name: workspace1Name, - description: workspace1Description, - features: ['use-case-observability'], - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - }, - }, - }).then((value) => { - workspace1Id = value; - }); - }); - - beforeEach(() => { - cy.intercept( - 'DELETE', - `/w/${workspace1Id}/api/workspaces/${workspace1Id}` - ).as('deleteWorkspace1Request'); - // Visit workspace detail page - miscUtils.visitPage(`w/${workspace1Id}/app/workspace_detail`); - }); - - it('should delete workspace in workspace detail page', () => { - cy.getElementByTestId('workspace-detail-delete-button').click(); - cy.contains('Delete workspace').should('be.visible'); - cy.contains(workspace1Name).should('be.visible'); - cy.getElementByTestId('delete-workspace-modal-input').type( - workspace1Name - ); - cy.getElementByTestId('delete-workspace-modal-confirm').click(); - cy.wait('@deleteWorkspace1Request').then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); - cy.contains('Delete workspace successfully').should('be.visible'); - cy.location('pathname').should('include', 'app/workspace_list'); - cy.contains(workspace1Name).should('not.exist'); - }); - }); -} +WorkspaceDeleteTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_detail.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_detail.spec.js index 911f5cc15..29541f4a0 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_detail.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_detail.spec.js @@ -3,282 +3,6 @@ * 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'; +import { WorkspaceDetailTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases'; -const NONE_DASHBOARDS_ADMIN_USERNAME = 'workspace-test'; -const WORKSPACE_TEST_ROLE_NAME = 'workspace-test-role'; - -const miscUtils = new MiscUtils(cy); -const workspaceName = 'test_workspace_320sdfouAz'; -let workspaceDescription = 'This is a workspace description.'; -let workspaceId; -let workspaceFeatures = ['use-case-observability']; - -if (Cypress.env('WORKSPACE_ENABLED')) { - describe('Workspace detail', () => { - before(() => { - if (Cypress.env('SECURITY_ENABLED')) { - cy.createInternalUser( - NONE_DASHBOARDS_ADMIN_USERNAME, - workspaceTestUser - ); - cy.createRole(WORKSPACE_TEST_ROLE_NAME, workspaceTestRole); - cy.createRoleMapping( - WORKSPACE_TEST_ROLE_NAME, - workspaceTestRoleMapping - ); - } - cy.deleteWorkspaceByName(workspaceName); - cy.createWorkspace({ - name: workspaceName, - description: workspaceDescription, - features: workspaceFeatures, - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - library_read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, - read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, - }, - }, - }).then((value) => (workspaceId = value)); - }); - - after(() => { - cy.deleteWorkspaceById(workspaceId); - if (Cypress.env('SECURITY_ENABLED')) { - cy.deleteRoleMapping(WORKSPACE_TEST_ROLE_NAME); - cy.deleteInternalUser(NONE_DASHBOARDS_ADMIN_USERNAME); - cy.deleteRole(WORKSPACE_TEST_ROLE_NAME); - } - }); - - describe('workspace details', () => { - beforeEach(() => { - // Visit workspace update page - miscUtils.visitPage(`w/${workspaceId}/app/workspace_detail`); - - cy.intercept( - 'PUT', - `/w/${workspaceId}/api/workspaces/${workspaceId}` - ).as('updateWorkspaceRequest'); - cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); - }); - - describe('Validate workspace name and description', () => { - it('workspace name is required', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).clear({ - force: true, - }); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).clear({ - force: true, - }); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description'); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ - force: true, - }); - cy.contains('Enter a name.').should('exist'); - }); - - it('workspace name is not valid', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).clear({ - force: true, - }); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).clear({ - force: true, - }); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).type('./+'); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description'); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ - force: true, - }); - cy.contains('Enter a valid name.').should('exist'); - }); - }); - - describe('Update a workspace successfully', () => { - it('should successfully update a workspace', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).clear({ - force: true, - }); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).clear({ - force: true, - }); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).type(workspaceName); - workspaceDescription = 'test_workspace_description.+~!'; - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type(workspaceDescription); - cy.getElementByTestId( - 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' - ).click(); - cy.get('button[aria-label="Select #6092C0 as the color"]').click(); - cy.get('button.euiSuperSelectControl') - .contains('Observability') - .click({ - force: true, - }); - cy.get('button.euiSuperSelect__item').contains('Analytics').click({ - force: true, - }); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ - force: true, - }); - cy.wait('@updateWorkspaceRequest').then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); - cy.location('pathname', { timeout: 6000 }).should( - 'include', - 'app/workspace_detail' - ); - const expectedWorkspace = { - name: workspaceName, - description: 'test_workspace_description.+~!', - color: '#6092C0', - features: ['use-case-all'], - }; - cy.checkWorkspace(workspaceId, expectedWorkspace); - // Update features after updated - workspaceFeatures = expectedWorkspace.features; - }); - }); - }); - - if ( - Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && - Cypress.env('SECURITY_ENABLED') - ) { - describe('update with different workspace access level', () => { - const originalUser = ADMIN_AUTH.username; - const originalPassword = ADMIN_AUTH.password; - beforeEach(() => { - ADMIN_AUTH.username = originalUser; - ADMIN_AUTH.password = originalPassword; - }); - after(() => { - ADMIN_AUTH.newUser = originalUser; - ADMIN_AUTH.newPassword = originalPassword; - }); - it('should not able to update workspace meta for non workspace admin', () => { - ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USERNAME; - ADMIN_AUTH.newPassword = workspaceTestUser.password; - - // Visit workspace list page - miscUtils.visitPage(`/app/workspace_list`); - - cy.getElementByTestId('headerApplicationTitle') - .contains('Workspaces') - .should('be.exist'); - - cy.get('[role="main"]').contains(workspaceName).should('be.exist'); - - cy.get(`#${workspaceId}-actions`).click(); - cy.getElementByTestId('workspace-list-edit-icon').click(); - - cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); - - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).clear({ - force: true, - }); - - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ - force: true, - }); - cy.getElementByTestId('globalToastList') - .contains('Invalid workspace permission') - .should('be.exist'); - }); - - it('should able to update workspace meta for workspace admin', () => { - const kibanaServerAdminWorkspace = { - name: 'kibana-server-workspace-admin', - features: ['use-case-all'], - settings: { - permissions: { - library_write: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, - write: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, - }, - }, - }; - cy.deleteWorkspaceByName(kibanaServerAdminWorkspace.name); - cy.createWorkspace(kibanaServerAdminWorkspace) - .as('adminWorkspaceId') - .then(() => { - ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USERNAME; - ADMIN_AUTH.newPassword = workspaceTestUser.password; - }); - - // Visit workspace list page - miscUtils.visitPage(`/app/workspace_list`); - - cy.getElementByTestId('headerApplicationTitle') - .contains('Workspaces') - .should('be.exist'); - - cy.get('[role="main"]') - .contains(kibanaServerAdminWorkspace.name) - .should('be.exist'); - - cy.get('@adminWorkspaceId').then((adminWorkspaceId) => { - cy.get(`#${adminWorkspaceId}-actions`).click(); - }); - cy.getElementByTestId('workspace-list-edit-icon').click(); - - cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); - - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).clear({ - force: true, - }); - - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('This is a new workspace description.'); - - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ - force: true, - }); - cy.getElementByTestId('globalToastList') - .contains('Update workspace successfully') - .should('be.exist'); - - cy.get('@adminWorkspaceId').then((adminWorkspaceId) => { - const expectedWorkspace = { - ...kibanaServerAdminWorkspace, - description: 'This is a new workspace description.', - }; - cy.checkWorkspace(adminWorkspaceId, expectedWorkspace); - cy.deleteWorkspaceById(adminWorkspaceId); - }); - }); - }); - } - }); -} +WorkspaceDetailTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_essential_overviews.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_essential_overviews.spec.js index 45423f564..b6297ed97 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_essential_overviews.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_essential_overviews.spec.js @@ -3,154 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { WorkspaceEssentialOverviewTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_essential_overviews.cases'; -const miscUtils = new MiscUtils(cy); -const workspaceName = `test_workspace_${Math.random() - .toString(36) - .substring(7)}`; -let workspaceDescription = 'This is a workspace description.'; -let workspaceId; -let datasourceId; -let workspaceFeatures = ['use-case-essentials']; - -const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); - -if (Cypress.env('WORKSPACE_ENABLED')) { - const createWorkspace = (datasourceId) => { - cy.createWorkspace({ - name: workspaceName, - description: workspaceDescription, - features: workspaceFeatures, - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - }, - ...(datasourceId ? { dataSources: [datasourceId] } : {}), - }, - }).then((value) => { - workspaceId = value; - // load sample data - cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId); - }); - }; - - describe('Essential workspace overview', () => { - before(() => { - cy.deleteWorkspaceByName(workspaceName); - if (MDSEnabled) { - cy.deleteAllDataSources(); - cy.createDataSourceNoAuth().then((result) => { - datasourceId = result[0]; - expect(datasourceId).to.be.a('string').that.is.not.empty; - createWorkspace(datasourceId); - }); - } else { - createWorkspace(); - } - }); - - after(() => { - if (workspaceId) { - cy.removeSampleDataForWorkspace('ecommerce', workspaceId, datasourceId); - cy.deleteWorkspaceById(workspaceId); - } - cy.deleteAllDataSources(); - }); - - beforeEach(() => { - // Visit workspace update page - miscUtils.visitPage(`w/${workspaceId}/app/essentials_overview`); - // wait for page load - cy.contains('h1', 'Overview'); - }); - - it('Get started cards display correctly', () => { - // verify four get started cards exist - cy.contains('Install sample data to experiment with OpenSearch.').click(); - // verify url has app/import_sample_data - cy.url().should('include', 'app/import_sample_data'); - - // browser back - cy.go('back'); - cy.contains('Explore data to uncover and discover insights.').click(); - // verify url has app/data-explorer/discover - cy.url().should('include', 'app/data-explorer/discover'); - - // browser back - cy.go('back'); - cy.contains( - 'Gain deeper insights by visualizing and aggregating your data.' - ).click(); - // verify url has app/visualize - cy.url().should('include', 'app/visualize'); - - cy.go('back'); - cy.contains( - 'Monitor and explore your data using dynamic data visualization tools.' - ).click(); - // verify url has app/dashboards - cy.url().should('include', 'app/dashboards'); - }); - - it('Assets cards display correctly', () => { - // no recently view assets - cy.contains('No assets to display'); - - // recentlyCard - cy.contains('Recently updated').should('be.visible').click(); - // should have 6 elements - cy.getElementByTestId('recentlyCard').should('have.length', 6); - - // filter by dashboard - cy.getElementByTestId('comboBoxInput').click(); - cy.get('span.euiComboBoxOption__content').contains('dashboard').click(); - - // click dashboard card - cy.getElementByTestId('recentlyCard').first().click(); - - // verify url has /app/dashboards - cy.url().should('include', 'app/dashboards'); - - cy.go('back'); - - // view all - cy.contains('View all').click(); - // verify url has /app/objects - cy.url().should('include', 'app/objects'); - }); - - it('Opensearch documentation cards display correctly', () => { - cy.contains('OpenSearch Documentation'); - - // get a link with text as Quickstart guide - cy.get('a') - .contains('Quickstart guide') - .should('have.attr', 'href') - .and((href) => { - expect(href).to.match( - /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/quickstart\/$/ - ); - }); - - cy.get('a') - .contains('Building data visualizations') - .should('have.attr', 'href') - .and((href) => { - expect(href).to.match( - /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/visualize\/viz-index\/$/ - ); - }); - - cy.get('a') - .contains('Creating dashboards') - .should('have.attr', 'href') - .and((href) => { - expect(href).to.match( - /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/dashboard\/index\/$/ - ); - }); - }); - }); -} +WorkspaceEssentialOverviewTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_import_sample_data_to.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_import_sample_data_to.spec.js index ea477fbb2..e666b82fd 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_import_sample_data_to.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_import_sample_data_to.spec.js @@ -3,158 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); +import { WorkspaceImportSampleDataTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases'; -if (Cypress.env('WORKSPACE_ENABLED')) { - describe('import sample data to workspace', () => { - let workspaceId; - let dataSourceId; - let dataSourceTitle; - const workspaceName = `workspace-${new Date().getTime()}`; - - const getTitleWithDataSource = (title) => { - if (!dataSourceTitle) { - return title; - } - return `${title}_${dataSourceTitle}`; - }; - - before(() => { - if (MDSEnabled) { - cy.createDataSourceNoAuth() - .then((result) => { - dataSourceId = result[0]; - dataSourceTitle = result[1]; - return result; - }) - .then((result) => { - cy.createWorkspace({ - name: workspaceName, - settings: MDSEnabled - ? { - dataSources: [result[0]], - } - : undefined, - }).then((id) => { - workspaceId = id; - }); - }); - } else { - cy.createWorkspace({ - name: workspaceName, - }).then((id) => { - workspaceId = id; - }); - } - }); - - after(() => { - if (workspaceId) { - cy.deleteWorkspaceById(workspaceId); - } - if (MDSEnabled) { - cy.deleteAllDataSources(); - } - }); - - beforeEach(() => { - cy.visit(`/w/${workspaceId}/app/import_sample_data`); - if (MDSEnabled) { - cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); - } - }); - - it('should show Add data buttons if sample data not installed', () => { - cy.getElementByTestId('addSampleDataSetecommerce').should('be.visible'); - cy.getElementByTestId('addSampleDataSetflights').should('be.visible'); - cy.getElementByTestId('addSampleDataSetlogs').should('be.visible'); - }); - - it('should show remove buttons after sample data installed', () => { - cy.getElementByTestId('addSampleDataSetecommerce').click(); - cy.getElementByTestId('addSampleDataSetflights').click(); - cy.getElementByTestId('addSampleDataSetlogs').click(); - - cy.getElementByTestId('removeSampleDataSetecommerce').should( - 'be.visible' - ); - cy.getElementByTestId('removeSampleDataSetflights').should('be.visible'); - cy.getElementByTestId('removeSampleDataSetlogs').should('be.visible'); - - cy.getElementByTestId('removeSampleDataSetecommerce').click(); - cy.getElementByTestId('removeSampleDataSetflights').click(); - cy.getElementByTestId('removeSampleDataSetlogs').click(); - }); - - it('should be able to visit ecommerce dashboard', () => { - cy.getElementByTestId('addSampleDataSetecommerce').click(); - - cy.getElementByTestId('launchSampleDataSetecommerce') - .should('be.visible') - .click(); - - cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`); - cy.getElementByTestId('headerAppActionMenu').should( - 'contain', - getTitleWithDataSource('[eCommerce] Revenue Dashboard') - ); - cy.get( - `[data-title="${getTitleWithDataSource('[eCommerce] Total Revenue')}"]` - ).should('not.contain', 'No results found'); - cy.visit(`/w/${workspaceId}/app/import_sample_data`); - - if (MDSEnabled) { - cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); - } - cy.getElementByTestId('removeSampleDataSetecommerce').click(); - }); - - it('should be able to visit flights dashboards', () => { - cy.getElementByTestId('addSampleDataSetflights').click(); - - cy.getElementByTestId('launchSampleDataSetflights') - .should('be.visible') - .click(); - - cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`); - cy.getElementByTestId('headerAppActionMenu').should( - 'contain', - getTitleWithDataSource('[Flights] Global Flight Dashboard') - ); - cy.get( - `[data-title="${getTitleWithDataSource('[Flights] Flight Delays')}"]` - ).should('not.contain', 'No results found'); - cy.visit(`/w/${workspaceId}/app/import_sample_data`); - - if (MDSEnabled) { - cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); - } - cy.getElementByTestId('removeSampleDataSetflights').click(); - }); - - it('should be able to visit logs dashboards', () => { - cy.getElementByTestId('addSampleDataSetlogs').click(); - - cy.getElementByTestId('launchSampleDataSetlogs') - .should('be.visible') - .click(); - - cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`); - cy.getElementByTestId('headerAppActionMenu').should( - 'contain', - getTitleWithDataSource('[Logs] Web Traffic') - ); - cy.get( - `[data-title="${getTitleWithDataSource( - '[Logs] Unique Visitors vs. Average Bytes' - )}"]` - ).should('not.contain', 'No results found'); - cy.visit(`/w/${workspaceId}/app/import_sample_data`); - - if (MDSEnabled) { - cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); - } - cy.getElementByTestId('removeSampleDataSetlogs').click(); - }); - }); -} +WorkspaceImportSampleDataTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_initial.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_initial.spec.js index be728a0ff..4e15d9afa 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_initial.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_initial.spec.js @@ -3,269 +3,6 @@ * 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'; +import { WorkspaceInitialTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_initial.cases'; -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') - .should('have.attr', 'target', '_blank') - .and('have.attr', 'href') - .and((href) => { - expect(href).to.match( - /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/opensearch\/index\/$/ - ); - }); - - 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'); - }); - }); - } - }); -} +WorkspaceInitialTestCases(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_search_overviews.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_search_overviews.spec.js index 8199eba07..f7435d36d 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_search_overviews.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_search_overviews.spec.js @@ -3,90 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { WorkspaceSearchOverviewTestCases } from '../../../../utils/dashboards/workspace-plugin/test-cases/mds_workspace_search_overviews.cases'; -const miscUtils = new MiscUtils(cy); -const workspaceName = `test_workspace_search_${Math.random() - .toString(36) - .substring(7)}`; -let workspaceDescription = 'This is a search workspace description.'; -let workspaceId; -let datasourceId; -let workspaceFeatures = ['use-case-search']; - -const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); - -if (Cypress.env('WORKSPACE_ENABLED')) { - const createWorkspace = (datasourceId) => { - cy.createWorkspace({ - name: workspaceName, - description: workspaceDescription, - features: workspaceFeatures, - settings: { - permissions: { - library_write: { users: ['%me%'] }, - write: { users: ['%me%'] }, - }, - ...(datasourceId ? { dataSources: [datasourceId] } : {}), - }, - }).then((value) => { - workspaceId = value; - }); - }; - - describe('Search workspace overview', () => { - before(() => { - cy.deleteWorkspaceByName(workspaceName); - if (MDSEnabled) { - cy.deleteAllDataSources(); - cy.createDataSourceNoAuth().then((result) => { - datasourceId = result[0]; - expect(datasourceId).to.be.a('string').that.is.not.empty; - createWorkspace(datasourceId); - }); - } else { - createWorkspace(); - } - }); - - after(() => { - if (workspaceId) { - cy.deleteWorkspaceById(workspaceId); - } - cy.deleteAllDataSources(); - }); - - beforeEach(() => { - // Visit workspace update page - miscUtils.visitPage(`w/${workspaceId}/app/search_overview`); - // wait for page load - cy.contains('h1', 'Overview'); - }); - - it('Set up search cards display correctly', () => { - cy.contains( - 'Explore search capabilities and functionality of OpenSearch.' - ); - cy.contains( - 'Create a document collection (an index) to query your data.' - ); - - cy.contains('Explore data to uncover and discover insights.').click(); - // verify url has app/data-explorer/discover - cy.url().should('include', 'app/data-explorer/discover'); - }); - - it('Different search techniques section display correctly', () => { - cy.contains('h3', 'Text search').should('be.visible'); - cy.contains('h3', 'Analyzers').should('be.visible'); - cy.contains('h3', 'Semantic vector search').should('be.visible'); - cy.contains('h3', 'Neural sparse search').should('be.visible'); - cy.contains('h3', 'Hybrid search').should('be.visible'); - }); - - it('Configure and evaluate search cards display correctly', () => { - cy.contains('Compare search results').should('be.visible').click(); - cy.url().should('contains', 'app/searchRelevance'); - }); - }); -} +WorkspaceSearchOverviewTestCases(); diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_acl.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_acl.cases.js new file mode 100644 index 000000000..e1a933b03 --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_acl.cases.js @@ -0,0 +1,236 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { BASE_PATH } from '../../../base_constants'; +import { ADMIN_AUTH } from '../../../commands'; +import workspaceTestUser from '../../../../fixtures/dashboard/opensearch_dashboards/workspace/workspaceTestUser.json'; +import workspaceTestRole from '../../../../fixtures/dashboard/opensearch_dashboards/workspace/workspaceTestRole.json'; +import { WORKSPACE_API_PREFIX } from '../constants'; + +export const WorkspaceACLTestCases = () => { + let noPermissionWorkspaceName = 'acl_no_permission_workspace'; + let readOnlyWorkspaceName = 'acl_readonly_workspace'; + let libraryWriteWorkspaceName = 'acl_library_write_workspace'; + let ownerWorkspaceName = 'acl_owner_workspace'; + + let noPermissionWorkspaceId = ''; + let readOnlyWorkspaceId = ''; + let libraryWriteWorkspaceId = ''; + let ownerWorkspaceId = ''; + let datasourceId = ''; + + const getPolicy = (permission, userName) => ({ + [permission]: { + users: [userName], + }, + }); + + const NON_DASHBOARDS_ADMIN_USERNAME = 'workspace-acl-test'; + const WORKSPACE_TEST_ROLE_NAME = 'workspace-acl-test-role'; + + const ACLPolicyMap = { + [noPermissionWorkspaceName]: {}, + [readOnlyWorkspaceName]: { + ...getPolicy('read', NON_DASHBOARDS_ADMIN_USERNAME), + ...getPolicy('library_read', NON_DASHBOARDS_ADMIN_USERNAME), + }, + [libraryWriteWorkspaceName]: { + ...getPolicy('read', NON_DASHBOARDS_ADMIN_USERNAME), + ...getPolicy('library_write', NON_DASHBOARDS_ADMIN_USERNAME), + }, + [ownerWorkspaceName]: { + ...getPolicy('write', NON_DASHBOARDS_ADMIN_USERNAME), + ...getPolicy('library_write', NON_DASHBOARDS_ADMIN_USERNAME), + }, + }; + + const setupWorkspace = (workspaceName, datasourceId) => { + return cy + .createWorkspace({ + name: workspaceName, + settings: { + ...(datasourceId ? { dataSources: [datasourceId] } : {}), + permissions: ACLPolicyMap[workspaceName], + }, + }) + .then((value) => { + // load sample data + cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId); + cy.wrap(value); + }); + }; + + const setupAllTheWorkspaces = () => { + setupWorkspace(noPermissionWorkspaceName, datasourceId).then( + (value) => (noPermissionWorkspaceId = value) + ); + setupWorkspace(readOnlyWorkspaceName, datasourceId).then( + (value) => (readOnlyWorkspaceId = value) + ); + setupWorkspace(libraryWriteWorkspaceName, datasourceId).then( + (value) => (libraryWriteWorkspaceId = value) + ); + setupWorkspace(ownerWorkspaceName, datasourceId).then( + (value) => (ownerWorkspaceId = value) + ); + }; + + if ( + Cypress.env('WORKSPACE_ENABLED') && + Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && + Cypress.env('SECURITY_ENABLED') + ) { + describe('Workspace ACL', () => { + const originalUser = ADMIN_AUTH.username; + const originalPassword = ADMIN_AUTH.password; + before(() => { + cy.deleteWorkspaceByName(noPermissionWorkspaceName); + cy.deleteWorkspaceByName(readOnlyWorkspaceName); + cy.deleteWorkspaceByName(libraryWriteWorkspaceName); + cy.deleteWorkspaceByName(ownerWorkspaceName); + + cy.createInternalUser(NON_DASHBOARDS_ADMIN_USERNAME, workspaceTestUser); + cy.createRole(WORKSPACE_TEST_ROLE_NAME, workspaceTestRole); + cy.createRoleMapping(WORKSPACE_TEST_ROLE_NAME, { + users: [NON_DASHBOARDS_ADMIN_USERNAME], + }); + + if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { + cy.createDataSourceNoAuth().then((result) => { + datasourceId = result[0]; + expect(datasourceId).to.be.a('string').that.is.not.empty; + setupAllTheWorkspaces(datasourceId); + }); + } else { + setupAllTheWorkspaces(datasourceId); + } + }); + + after(() => { + ADMIN_AUTH.newUser = originalUser; + ADMIN_AUTH.newPassword = originalPassword; + cy.removeSampleDataForWorkspace( + 'ecommerce', + ownerWorkspaceId, + datasourceId + ); + cy.deleteWorkspaceByName(noPermissionWorkspaceName); + cy.deleteWorkspaceByName(readOnlyWorkspaceName); + cy.deleteWorkspaceByName(libraryWriteWorkspaceName); + cy.deleteWorkspaceByName(ownerWorkspaceName); + if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { + cy.deleteDataSource(datasourceId); + } + readOnlyWorkspaceId = ''; + libraryWriteWorkspaceId = ''; + + cy.deleteRoleMapping(WORKSPACE_TEST_ROLE_NAME); + cy.deleteInternalUser(NON_DASHBOARDS_ADMIN_USERNAME); + cy.deleteRole(WORKSPACE_TEST_ROLE_NAME); + }); + + describe('Normal user', () => { + beforeEach(() => { + ADMIN_AUTH.newUser = NON_DASHBOARDS_ADMIN_USERNAME; + ADMIN_AUTH.newPassword = workspaceTestUser.password; + }); + + it('Normal user should not be able to create workspace', () => { + cy.request({ + method: 'POST', + url: `${BASE_PATH}${WORKSPACE_API_PREFIX}`, + headers: { + 'osd-xsrf': true, + }, + body: { + attributes: { + name: 'test_workspace', + features: ['use-case-observability'], + description: 'test_description', + }, + }, + failOnStatusCode: false, + }).then((resp) => + cy + .wrap(resp.body.error) + .should('equal', 'Invalid permission, please contact OSD admin') + ); + }); + + it('Normal users should only see the workspaces they have permission with', () => { + cy.visit(`${BASE_PATH}/app/home`); + cy.contains(readOnlyWorkspaceName); + cy.contains(noPermissionWorkspaceName).should('not.exist'); + }); + + it('Readonly users should not be allowed to update dashboards/visualizations within the workspace', () => { + cy.visit(`${BASE_PATH}/w/${readOnlyWorkspaceId}/app/visualize`); + cy.contains(/\[eCommerce\] Markdown/).click(); + cy.getElementByTestId('visualizeSaveButton').click(); + cy.getElementByTestId('confirmSaveSavedObjectButton').click(); + cy.contains('Forbidden'); + }); + + it('Normal users should not be allowed to visit workspace he/she has no permission', () => { + cy.visit(`${BASE_PATH}/w/${noPermissionWorkspaceId}/app/objects`); + cy.contains('Invalid saved objects permission'); + }); + + it('Normal users should only see the workspaces he has library_write permission in the target workspaces list of duplicate modal', () => { + cy.visit(`${BASE_PATH}/w/${readOnlyWorkspaceId}/app/objects`); + cy.getElementByTestId('savedObjectsTableRowTitle').should('exist'); + cy.getElementByTestId('duplicateObjects') + .click() + .getElementByTestId('savedObjectsDuplicateModal') + .find('[data-test-subj="comboBoxInput"]') + .click(); + + cy.contains(libraryWriteWorkspaceName); + cy.contains(ownerWorkspaceName); + cy.contains(noPermissionWorkspaceName).should('not.exist'); + }); + + it('Users should not be able to update default index pattern / default data source if he/she is not the workspace owner', () => { + cy.visit( + `${BASE_PATH}/w/${libraryWriteWorkspaceId}/app/indexPatterns` + ); + cy.contains('opensearch_dashboards_sample_data_ecommerce').click(); + cy.getElementByTestId('setDefaultIndexPatternButton').click(); + cy.contains('Unable to update UI setting'); + }); + + it('Normal users should not be able to find objects from other workspaces when inside a workspace', () => { + cy.visit(`${BASE_PATH}/w/${readOnlyWorkspaceId}/app/objects`); + cy.getElementByTestId('savedObjectsTableRowTitle').should('exist'); + cy.getElementByTestId( + 'savedObjectsTableColumn-workspace_column' + ).should('not.exist'); + cy.contains('opensearch_dashboards_sample_data_ecommerce'); + // Electron old version may not support search event, so we manually trigger a search event + cy.getElementByTestId('savedObjectSearchBar') + .type('opensearch_dashboards_sample_data_ecommerce{enter}') + .trigger('search'); + cy.getElementByTestId('savedObjectsTableRowTitle').should( + 'have.length', + 1 + ); + }); + + if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { + it('Normal users should not be able to associate / dissociate data sources from workspace.', () => { + cy.visit(`${BASE_PATH}/w/${ownerWorkspaceId}/app/dataSources`); + cy.contains('Data sources'); + cy.getElementByTestId('workspaceAssociateDataSourceButton').should( + 'not.exist' + ); + cy.getElementByTestId( + 'dataSourcesManagement-dataSourceTable-dissociateButton' + ).should('not.exist'); + }); + } + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_analytics_overviews.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_analytics_overviews.cases.js new file mode 100644 index 000000000..03eef836f --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_analytics_overviews.cases.js @@ -0,0 +1,163 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +export const WorkspaceAnalyticsOverviewTestCases = () => { + const miscUtils = new MiscUtils(cy); + const workspaceName = `test_workspace_analytics_${Math.random() + .toString(36) + .substring(7)}`; + let workspaceDescription = 'This is a analytics workspace description.'; + let workspaceId; + let datasourceId; + let workspaceFeatures = ['use-case-all']; + + const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); + + if (Cypress.env('WORKSPACE_ENABLED')) { + const createWorkspace = (dsId) => { + cy.createWorkspace({ + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + ...(dsId ? { dataSources: [dsId] } : {}), + }, + }).then((value) => { + workspaceId = value; + // load sample data + cy.loadSampleDataForWorkspace('ecommerce', value, dsId); + }); + }; + + describe('Analytics workspace overview', () => { + before(() => { + cy.deleteWorkspaceByName(workspaceName); + if (MDSEnabled) { + cy.deleteAllDataSources(); + cy.createDataSourceNoAuth().then((result) => { + datasourceId = result[0]; + expect(datasourceId).to.be.a('string').that.is.not.empty; + createWorkspace(datasourceId); + }); + } else { + createWorkspace(); + } + }); + + after(() => { + if (workspaceId) { + cy.removeSampleDataForWorkspace( + 'ecommerce', + workspaceId, + datasourceId + ); + cy.deleteWorkspaceById(workspaceId); + } + cy.deleteAllDataSources(); + }); + + beforeEach(() => { + // Visit workspace update page + miscUtils.visitPage(`w/${workspaceId}/app/all_overview`); + // wait for page load + cy.contains('h1', 'Overview'); + }); + + it('should display get started sections', () => { + cy.get('.euiCard__footer') + .contains('Observability') + .should('be.visible'); + // this is depends on observability plugin been installed + // cy.url().should('include', 'app/observability-overview'); + + cy.get('.euiCard__footer') + .contains('Security Analytics') + .should('be.visible'); + // this is depends on security analytics plugin been installed + // cy.url().should('include', 'app/sa_overview'); + + cy.get('.euiCard__footer') + .contains('Search') + .should('be.visible') + .click(); + cy.url().should('include', 'app/search_overview'); + }); + + it('should display asset section correctly', () => { + // no recently view assets + cy.contains('No assets to display'); + + // recentlyCard + cy.contains('Recently updated').should('be.visible').click(); + // should have 6 elements + cy.getElementByTestId('recentlyCard').should('have.length', 6); + + // filter by dashboard + cy.getElementByTestId('comboBoxInput').click(); + cy.get('span.euiComboBoxOption__content').contains('dashboard').click(); + + // click dashboard card + cy.getElementByTestId('recentlyCard').first().click(); + + // verify url has /app/dashboards + cy.url().should('include', 'app/dashboards'); + + cy.go('back'); + + // view all + cy.contains('View all').click(); + // verify url has /app/objects + cy.url().should('include', 'app/objects'); + }); + + // Alerts and threat Alerts cards are depends on plugins + + it('should display OpenSearch Documentation panel', () => { + cy.contains('OpenSearch Documentation').should('be.visible'); + cy.get('.euiLink') + .contains('Quickstart guide') + .should('be.visible') + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/quickstart\/$/ + ); + }); + cy.get('.euiLink') + .contains('Building data visualizations') + .should('be.visible') + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/visualize\/viz-index\/$/ + ); + }); + cy.get('.euiLink') + .contains('Creating dashboards') + .should('be.visible') + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/dashboard\/index\/$/ + ); + }); + cy.contains('Learn more in Documentation') + .should('be.visible') + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/index\/$/ + ); + }); + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_assets.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_assets.cases.js new file mode 100644 index 000000000..49d0da48a --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_assets.cases.js @@ -0,0 +1,191 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { BASE_PATH } from '../../../base_constants'; + +export const WorkspaceAssetsTestCases = () => { + let sourceWorkspaceName = 'test_source_workspace'; + let targetWorkspaceName = 'test_target_workspace'; + + let sourceWorkspaceId = ''; + let targetWorkspaceId = ''; + let datasourceId = ''; + + const setupWorkspace = (workspaceName, datasourceId) => { + return cy + .createWorkspace({ + name: workspaceName, + settings: { + ...(datasourceId ? { dataSources: [datasourceId] } : {}), + }, + }) + .then((value) => { + // load sample data + cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId); + cy.wrap(value); + }); + }; + + if (Cypress.env('WORKSPACE_ENABLED')) { + describe('Workspace assets', () => { + before(() => { + cy.deleteWorkspaceByName(sourceWorkspaceName); + cy.deleteWorkspaceByName(targetWorkspaceName); + if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { + cy.createDataSourceNoAuth().then((result) => { + datasourceId = result[0]; + expect(datasourceId).to.be.a('string').that.is.not.empty; + setupWorkspace(sourceWorkspaceName, datasourceId).then( + (value) => (sourceWorkspaceId = value) + ); + setupWorkspace(targetWorkspaceName, datasourceId).then( + (value) => (targetWorkspaceId = value) + ); + }); + } else { + setupWorkspace(sourceWorkspaceName).then( + (value) => (sourceWorkspaceId = value) + ); + setupWorkspace(targetWorkspaceName).then( + (value) => (targetWorkspaceId = value) + ); + } + }); + + after(() => { + // Uninstallation will delete the data index + // and workspace deletion will remove all the saved objects within the workspace, + // so calling `removeSampleDataForWorkspace` once is good enough. + cy.removeSampleDataForWorkspace( + 'ecommerce', + sourceWorkspaceId, + datasourceId + ); + cy.deleteWorkspaceByName(sourceWorkspaceName); + cy.deleteWorkspaceByName(targetWorkspaceName); + if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { + cy.deleteDataSource(datasourceId); + } + sourceWorkspaceId = ''; + targetWorkspaceId = ''; + }); + + it('Should not list assets from other workspace and generate correct url for inspect url inside a workspace', () => { + cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/objects`); + cy.getElementByTestId('savedObjectsTableRowTitle').should('exist'); + cy.getElementByTestId( + 'savedObjectsTableColumn-workspace_column' + ).should('not.exist'); + cy.contains('opensearch_dashboards_sample_data_ecommerce'); + // Electron old version may not support search event, so we manually trigger a search event + cy.getElementByTestId('savedObjectSearchBar') + .type('opensearch_dashboards_sample_data_ecommerce{enter}') + .trigger('search'); + cy.getElementByTestId('savedObjectsTableRowTitle').should( + 'have.length', + 1 + ); + + // Click more -> inspect + cy.getElementByTestId('euiCollapsedItemActionsButton') + .click() + .getElementByTestId('savedObjectsTableAction-inspect') + .click(); + cy.location('pathname').should( + 'include', + `/w/${sourceWorkspaceId}/app/indexPatterns` + ); + }); + + it('Should list assets from workspaces with permission and generate correct url for inspect url outside workspace', () => { + cy.visit(`${BASE_PATH}/app/objects`); + cy.getElementByTestId( + 'savedObjectsTableColumn-workspace_column' + ).should('exist'); + // Electron old version may not support search event, so we manually trigger a search event + cy.getElementByTestId('savedObjectSearchBar') + .type('opensearch_dashboards_sample_data_ecommerce{enter}') + .trigger('search'); + cy.getElementByTestId('savedObjectsTableRowTitle').should( + 'have.length', + 2 + ); + + // Find the row belong to the target workspace + cy.contains(targetWorkspaceName) + .parents('.euiTableRow') + // Click more -> inspect + .find('[data-test-subj="euiCollapsedItemActionsButton"]') + .click() + .getElementByTestId('savedObjectsTableAction-inspect') + .click(); + cy.location('pathname').should( + 'include', + `/w/${targetWorkspaceId}/app/indexPatterns` + ); + }); + + // TODO: this test case should be removed once index pattern access outside of workspace being blocked in the future. + it('Should not show set as default button when outside workspace', () => { + cy.request({ + url: `${BASE_PATH}/api/opensearch-dashboards/management/saved_objects/_find?workspaces=${targetWorkspaceId}&page=1&type=index-pattern`, + headers: { + 'Osd-Xsrf': 'osd-fetch', + }, + }) + .then((resp) => { + cy.wrap(resp.body.saved_objects).should('have.length', 1); + cy.wrap(resp.body.saved_objects[0].id); + }) + .then((indexPatternId) => { + cy.visit( + `${BASE_PATH}/app/indexPatterns/patterns/${indexPatternId}` + ); + cy.contains('opensearch_dashboards_sample_data_ecommerce'); + cy.getElementByTestId('setDefaultIndexPatternButton').should( + 'not.exist' + ); + }); + }); + + it('Short url should be able to be generated multiple times and preserve workspace info', () => { + cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/visualize`); + cy.contains(/\[eCommerce\] Markdown/).click(); + cy.getElementByTestId('shareTopNavButton') + .click() + .getElementByTestId('sharePanel-Permalinks') + .click() + .getElementByTestId('useShortUrl') + .as('generateShortUrlButton') + .click(); + + // Should generate successfully + cy.getElementByTestId('copyShareUrlButton') + .invoke('attr', 'data-share-url') + .should('include', `${BASE_PATH}/goto`); + + // Regeneration should work without error + cy.get('@generateShortUrlButton').click(); + cy.getElementByTestId('copyShareUrlButton') + .invoke('attr', 'data-share-url') + .should('include', `${BASE_PATH}/w/${sourceWorkspaceId}`); + cy.get('@generateShortUrlButton').click(); + cy.getElementByTestId('copyShareUrlButton') + .invoke('attr', 'data-share-url') + .then((shortUrl) => { + cy.wrap(shortUrl).should('include', `${BASE_PATH}/goto`); + cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/objects`); + cy.contains('Workspace assets'); + cy.visit(shortUrl); + cy.location('pathname').should( + 'include', + `/w/${sourceWorkspaceId}` + ); + cy.contains(/\[eCommerce\] Markdown/); + }); + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_association.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_association.cases.js new file mode 100644 index 000000000..316e94185 --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_association.cases.js @@ -0,0 +1,86 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +export const WorkspaceAssociationTestCases = () => { + const miscUtils = new MiscUtils(cy); + const workspaceName = 'test_workspace_collaborators'; + let workspaceId; + let dataSourceTitle1 = 'no_auth_data_source_title_1'; + let dataSourceTitle2 = 'no_auth_data_source_title_2'; + let dataSourceId1; + let dataSourceId2; + if ( + Cypress.env('WORKSPACE_ENABLED') && + Cypress.env('DATASOURCE_MANAGEMENT_ENABLED') + ) { + describe('Workspace association data source', () => { + before(() => { + cy.createDataSourceNoAuth({ title: dataSourceTitle1 }).then( + (result) => { + dataSourceId1 = result[0]; + } + ); + cy.createDataSourceNoAuth({ title: dataSourceTitle2 }).then( + (result) => { + dataSourceId2 = result[0]; + } + ); + }); + beforeEach(() => { + cy.deleteWorkspaceByName(workspaceName); + //Create a workspace before each test + cy.createWorkspace({ + name: workspaceName, + features: ['use-case-observability'], + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspaceId = value; + }); + }); + + after(() => { + cy.deleteDataSource(dataSourceId1); + cy.deleteDataSource(dataSourceId2); + }); + afterEach(() => { + cy.deleteWorkspaceById(workspaceId); + }); + + it('should associate and dissociate data source successfully', () => { + miscUtils.visitPage(`w/${workspaceId}/app/dataSources`); + + cy.getElementByTestId('workspaceAssociateDataSourceButton').click(); + cy.contains('OpenSearch data sources').click(); + cy.contains(dataSourceTitle1, { + withinSubject: parent.document.body, + }).click({ force: true }); + cy.contains(dataSourceTitle2, { + withinSubject: parent.document.body, + }).click({ force: true }); + cy.getElementByTestId( + 'workspace-detail-dataSources-associateModal-save-button' + ).click(); + + // The table is updated after successful association + cy.contains('table', dataSourceTitle1); + cy.contains('table', dataSourceTitle2); + + // The table is updated after successful dissociation + cy.getElementByTestId('checkboxSelectAll').check(); + cy.getElementByTestId('dissociateSelectedDataSources').click(); + cy.getElementByTestId('confirmModalConfirmButton').click(); + cy.contains('table', dataSourceTitle1).should('not.exist'); + cy.contains('table', dataSourceTitle2).should('not.exist'); + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_breadcrumbs.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_breadcrumbs.cases.js new file mode 100644 index 000000000..a9b5efe36 --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_breadcrumbs.cases.js @@ -0,0 +1,165 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +export const WorkspaceBreadcrumbsTestCases = () => { + const miscUtils = new MiscUtils(cy); + const workspaceName = `test_workspace_analytics_${Math.random() + .toString(36) + .substring(7)}`; + let workspaceDescription = 'This is a analytics workspace description.'; + let workspaceId; + let workspaceFeatures = ['use-case-all']; + + if (Cypress.env('WORKSPACE_ENABLED')) { + const createWorkspace = () => { + cy.createWorkspace({ + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspaceId = value; + }); + }; + + describe('Breadcrumbs in workspace', () => { + before(() => { + cy.deleteWorkspaceByName(workspaceName); + createWorkspace(); + }); + + after(() => { + if (workspaceId) { + cy.deleteWorkspaceById(workspaceId); + } + }); + + it('should show workspace name in breadcrumbs', () => { + miscUtils.visitPage(`w/${workspaceId}/app/objects`); + + // get div with class newTopNavHeader + cy.get('.newTopNavHeader').within(() => { + cy.getElementByTestId('breadcrumb first') + .should('exist') + .within(() => { + // Check for the icon + cy.getElementByTestId(`${workspaceId}-icon`).should('exist'); + // Check for the workspace name + cy.contains(workspaceName).should('exist').click(); + // click on breadcrumbs goes to overview page + cy.url().should('include', `w/${workspaceId}/app/all_overview`); + }); + }); + }); + + it('should show breadcrumbs in recent popover', () => { + miscUtils.visitPage(`w/${workspaceId}/app/workspace_detail`); + // wait for page load + cy.contains('h1', 'Workspace details'); + // waiting for page load completely + cy.getElementByTestId('recentItemsSectionButton').should( + 'not.have.class', + 'headerRecentItemsButton--loadingIndicator', + { + timeout: 10000, + } + ); + cy.wait(1000); + cy.getElementByTestId('recentItemsSectionButton').click({ + force: true, + }); + + cy.get('.euiPopover__panel').within(() => { + cy.getElementByTestId('breadcrumbs').within(() => { + // Check for the icon + cy.getElementByTestId(`${workspaceId}-icon`).should('exist'); + // Check for the workspace name + cy.contains(workspaceName).should('exist'); + // page title exists in breadcrumbs + cy.contains('Workspace details'); + }); + }); + }); + }); + + describe('Breadcrumbs out of workspace', () => { + it('breadcrumbs display correctly in settings and setup', () => { + miscUtils.visitPage('app/workspace_list'); + cy.contains('h1', 'Workspaces'); + + cy.get('.newTopNavHeader').within(() => { + cy.getElementByTestId('breadcrumb first') + .should('exist') + .within(() => { + // Check for the use case name + cy.contains('Settings and setup').click(); + cy.url().should('include', 'app/settings_landing'); + }); + }); + + // check breadcrumbs in recent popover + cy.getElementByTestId('recentItemsSectionButton').should( + 'not.have.class', + 'headerRecentItemsButton--loadingIndicator', + { + timeout: 10000, + } + ); + cy.wait(1000); + cy.getElementByTestId('recentItemsSectionButton').click({ + force: true, + }); + + cy.get('.euiPopover__panel').within(() => { + cy.getElementByTestId('breadcrumbs').within(() => { + cy.contains('Settings and setup'); + cy.contains('Settings and setup overview'); + }); + }); + }); + + it('breadcrumbs display correctly in data administration', () => { + miscUtils.visitPage('app/data_administration_landing'); + cy.contains('h1', 'Data administration overview'); + + cy.get('.newTopNavHeader').within(() => { + cy.getElementByTestId('breadcrumb first') + .should('exist') + .within(() => { + // Check for the use case name + cy.contains('Data administration'); + }); + }); + + // check breadcrumbs in recent popover + cy.getElementByTestId('recentItemsSectionButton').should( + 'not.have.class', + 'headerRecentItemsButton--loadingIndicator', + { + timeout: 10000, + } + ); + cy.wait(1000); + cy.getElementByTestId('recentItemsSectionButton').click({ + force: true, + }); + + cy.get('.euiPopover__panel').within(() => { + cy.getElementByTestId('breadcrumbs').within(() => { + cy.contains('Data administration'); + cy.contains('Data administration overview'); + }); + }); + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases.js new file mode 100644 index 000000000..3f17723df --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_collaborators.cases.js @@ -0,0 +1,214 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +export const WorkspaceCollaboratorsTestCases = () => { + const miscUtils = new MiscUtils(cy); + const workspaceName = 'test_workspace_collaborators'; + let workspaceId; + + if ( + Cypress.env('WORKSPACE_ENABLED') && + Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && + Cypress.env('SECURITY_ENABLED') + ) { + describe('Workspace collaborators', () => { + beforeEach(() => { + cy.deleteWorkspaceByName(workspaceName); + //Create a workspace before each test + cy.createWorkspace({ + name: workspaceName, + features: ['use-case-observability'], + settings: { + permissions: { + library_write: { + users: [`${Cypress.env('username')}`], + groups: ['admin_group'], + }, + write: { + users: [`${Cypress.env('username')}`], + groups: ['admin_group'], + }, + library_read: { + users: ['read_user'], + }, + read: { + users: ['read_user'], + }, + }, + }, + }).then((value) => { + workspaceId = value; + miscUtils.visitPage(`w/${value}/app/workspace_collaborators`); + }); + }); + + afterEach(() => { + cy.deleteWorkspaceById(workspaceId); + }); + + it('should add user and group collaborators successfully', () => { + //Add user + cy.getElementByTestId('add-collaborator-popover').click(); + cy.get('button[id="user"]').click(); + cy.contains('Add Users').should('be.visible'); + cy.getElementByTestId('workspaceCollaboratorIdInput-0').type( + 'new_read_user' + ); + cy.get('button[type="submit"]') + .contains('span', 'Add collaborators') + .click(); + + //Add group + cy.getElementByTestId('add-collaborator-popover').click(); + cy.get('button[id="group"]').click(); + cy.contains('Add Groups').should('be.visible'); + cy.getElementByTestId('workspaceCollaboratorIdInput-0').type( + 'new_admin_group' + ); + cy.get('span[title="Admin"]').click(); + cy.get('button[type="submit"]') + .contains('span', 'Add collaborators') + .click(); + + cy.contains('new_read_user'); + + cy.get('table') + .contains('td', 'new_read_user') + .parent() + .within(() => { + cy.get('td').eq(3).contains('Read only'); + }); + + cy.get('table') + .contains('td', 'new_admin_group') + .parent() + .within(() => { + cy.get('td').eq(3).contains('Admin'); + }); + const expectedWorkspace = { + name: workspaceName, + features: ['use-case-observability'], + description: 'test_description', + permissions: { + library_write: { + users: [`${Cypress.env('username')}`], + groups: ['admin_group', 'new_admin_group'], + }, + write: { + users: [`${Cypress.env('username')}`], + groups: ['admin_group', 'new_admin_group'], + }, + library_read: { + users: ['read_user', 'new_read_user'], + }, + read: { + users: ['read_user', 'new_read_user'], + }, + }, + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + + it('should change access level successfully', () => { + cy.get('table') + .contains('td', 'read_user') + .parent('tr') + .within(() => { + cy.get('input[type="checkbox"]').check(); + }); + cy.get('table') + .contains('td', 'admin_group') + .parent('tr') + .within(() => { + cy.get('input[type="checkbox"]').check(); + }); + + cy.getElementByTestId( + 'workspace-detail-collaborator-table-actions' + ).click(); + cy.get('div[role="dialog"]') + .find('span') + .contains('Change access level') + .click(); + cy.get('div[role="dialog"]') + .find('span') + .contains('Read and write') + .click(); + cy.getElementByTestId('confirmModalConfirmButton').click(); + + cy.contains('read_user'); + + cy.get('table') + .contains('td', 'read_user') + .parent() + .within(() => { + cy.get('td').eq(3).contains('Read and write'); + }); + cy.get('table') + .contains('td', 'admin_group') + .parent() + .within(() => { + cy.get('td').eq(3).contains('Read and write'); + }); + const expectedWorkspace = { + name: workspaceName, + features: ['use-case-observability'], + description: 'test_description', + permissions: { + library_write: { + users: [`${Cypress.env('username')}`, 'read_user'], + groups: ['admin_group'], + }, + write: { + users: [`${Cypress.env('username')}`], + }, + read: { + groups: ['admin_group'], + users: ['read_user'], + }, + }, + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + + it('should delete collaborators successfully', () => { + cy.get('table') + .contains('td', 'read_user') + .parent('tr') + .within(() => { + cy.get('input[type="checkbox"]').check(); + }); + cy.get('table') + .contains('td', 'admin_group') + .parent('tr') + .within(() => { + cy.get('input[type="checkbox"]').check(); + }); + + cy.getElementByTestId('confirm-delete-button').click(); + cy.getElementByTestId('confirmModalConfirmButton').click(); + + cy.contains('read_user').should('not.exist'); + cy.contains('admin_group').should('not.exist'); + const expectedWorkspace = { + name: workspaceName, + features: ['use-case-observability'], + description: 'test_description', + permissions: { + library_write: { + users: ['admin'], + }, + write: { + users: ['admin'], + }, + }, + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases.js new file mode 100644 index 000000000..13879d79f --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_create.cases.js @@ -0,0 +1,334 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +export const WorkspaceCreateTestCases = () => { + const miscUtils = new MiscUtils(cy); + const workspaceName = 'test_workspace_az3RBx6cE'; + const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); + + const inputWorkspaceName = (workspaceName) => { + const nameInputTestId = 'workspaceForm-workspaceDetails-nameInputText'; + cy.getElementByTestId(nameInputTestId).clear(); + cy.getElementByTestId(nameInputTestId).type(workspaceName); + }; + + const inputDataSourceWhenMDSEnabled = (dataSourceTitle) => { + if (!MDSEnabled) { + return; + } + cy.getElementByTestId( + 'workspace-creator-dataSources-assign-button' + ).click(); + + cy.get(`li[title="${dataSourceTitle}"]`).click(); + + cy.getElementByTestId( + 'workspace-detail-dataSources-associateModal-save-button' + ).click(); + }; + + if (Cypress.env('WORKSPACE_ENABLED')) { + describe('Create workspace', () => { + let dataSourceTitle; + before(() => { + cy.deleteWorkspaceByName(workspaceName); + if (MDSEnabled) { + cy.deleteAllDataSources(); + cy.createDataSourceNoAuth().then((result) => { + dataSourceTitle = result[1]; + }); + } + }); + + beforeEach(() => { + // Visit workspace create page + miscUtils.visitPage('app/workspace_create'); + + cy.intercept('POST', '/api/workspaces').as('createWorkspaceRequest'); + }); + + after(() => { + cy.deleteWorkspaceByName(workspaceName); + if (MDSEnabled) { + cy.deleteAllDataSources(); + } + }); + + it('should successfully load the page', () => { + cy.contains('Create a workspace', { timeout: 60000 }); + }); + + describe('Create a workspace successfully', () => { + it('should successfully create a workspace', () => { + inputWorkspaceName(workspaceName); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description.+~!'); + cy.getElementByTestId('workspaceUseCase-observability').click({ + force: true, + }); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); + + 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', + `w/${workspaceId}/app` + ); + + const expectedWorkspace = { + name: workspaceName, + description: 'test_workspace_description.+~!', + features: ['use-case-observability'], + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + }); + + it('should successfully create a workspace from home page', () => { + cy.deleteWorkspaceByName(workspaceName); + miscUtils.visitPage('app/workspace_initial'); + cy.getElementByTestId( + 'workspace-initial-card-createWorkspace-button' + ).click({ + force: true, + }); + cy.getElementByTestId( + 'workspace-initial-button-create-observability-workspace' + ).click({ + force: true, + }); + cy.contains('Observability') + .first() + .closest('.euiCheckableCard-isChecked') + .should('exist'); + + miscUtils.visitPage('app/workspace_initial'); + cy.getElementByTestId( + 'workspace-initial-useCaseCard-security-analytics-button-createWorkspace' + ).click({ + force: true, + }); + cy.contains('Security Analytics') + .first() + .closest('.euiCheckableCard-isChecked') + .should('exist'); + + inputWorkspaceName(workspaceName); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); + + 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', + `w/${workspaceId}/app` + ); + + const expectedWorkspace = { + name: workspaceName, + features: ['use-case-security-analytics'], + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + }); + + if ( + Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && + Cypress.env('SECURITY_ENABLED') + ) { + it('should successfully jump to collaborators page after creating a workspace', () => { + cy.deleteWorkspaceByName(workspaceName); + inputWorkspaceName(workspaceName); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click( + { + force: true, + } + ); + + 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', + `w/${workspaceId}/app/workspace_collaborators` + ); + }); + }); + } + + it('should correctly display the summary card', () => { + inputWorkspaceName(workspaceName); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description.+~!'); + cy.getElementByTestId('workspaceUseCase-essentials').click({ + force: true, + }); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.get('.workspaceCreateRightSidebar').within(() => { + cy.contains(workspaceName).should('exist'); + cy.contains('test_workspace_description.+~!').should('exist'); + cy.contains('Essentials').should('exist'); + if (MDSEnabled) { + cy.contains(dataSourceTitle).should('exist'); + } + }); + }); + }); + + describe('Validate workspace name and description', () => { + it('workspace name is required', () => { + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-nameInputText' + ).clear(); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); + cy.contains('Enter a name.').should('exist'); + }); + + it('workspace name is not valid', () => { + inputWorkspaceName('./+'); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description'); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); + cy.contains('Enter a valid name.').should('exist'); + }); + + it('workspace name cannot use an existing name', () => { + cy.deleteWorkspaceByName(workspaceName); + cy.createWorkspace({ + name: workspaceName, + features: ['use-case-observability'], + }); + inputWorkspaceName(workspaceName); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description'); + cy.getElementByTestId('workspaceUseCase-observability').click({ + force: true, + }); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ + force: true, + }); + cy.contains('workspace name has already been used').should('exist'); + }); + }); + + if (MDSEnabled) { + describe('Create a workspace with associated data sources', () => { + before(() => { + cy.deleteWorkspaceByName(workspaceName); + }); + + it('should be exists inside workspace data source list', () => { + inputWorkspaceName(workspaceName); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description'); + cy.getElementByTestId('workspaceUseCase-observability').click({ + force: true, + }); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click( + { + force: true, + } + ); + + cy.wait('@createWorkspaceRequest') + .then((interception) => { + expect(interception.response.statusCode).to.equal(200); + return interception.response.body.result.id; + }) + .then((workspaceId) => { + const dataSourcePathname = `w/${workspaceId}/app/dataSources`; + miscUtils.visitPage(dataSourcePathname); + cy.location('pathname', { timeout: 6000 }).should( + 'include', + dataSourcePathname + ); + cy.contains(dataSourceTitle).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', () => { + inputWorkspaceName(workspaceName); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description'); + cy.getElementByTestId('workspaceUseCase-observability').click({ + force: true, + }); + inputDataSourceWhenMDSEnabled(dataSourceTitle); + cy.getElementByTestId('workspaceForm-bottomBar-createButton').click( + { + force: true, + } + ); + + 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', + `w/${workspaceId}/app` + ); + const expectedWorkspace = { + name: workspaceName, + description: 'test_workspace_description', + features: ['use-case-observability'], + permissions: { + write: { + users: [`${Cypress.env('username')}`], + }, + library_write: { + users: [`${Cypress.env('username')}`], + }, + }, + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + }); + }); + } + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_delete.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_delete.cases.js new file mode 100644 index 000000000..b2d1a0a77 --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_delete.cases.js @@ -0,0 +1,185 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +export const WorkspaceDeleteTestCases = () => { + const miscUtils = new MiscUtils(cy); + const workspace1Name = 'test_workspace_320sdfouAz'; + let workspace1Description = 'This is a workspace1 description.'; + const workspace2Name = 'test_workspace_321sdfouAz'; + let workspace2Description = 'This is a workspace2 description.'; + + let workspace1Id; + let workspace2Id; + + if (Cypress.env('WORKSPACE_ENABLED')) { + describe('Delete Workspace(s) in 2 ways in workspace list page', () => { + before(() => { + cy.deleteWorkspaceByName(workspace1Name); + cy.deleteWorkspaceByName(workspace2Name); + }); + beforeEach(() => { + cy.createWorkspace({ + name: workspace1Name, + description: workspace1Description, + features: ['use-case-observability'], + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspace1Id = value; + cy.intercept('DELETE', `/api/workspaces/${workspace1Id}`).as( + 'deleteWorkspace1Request' + ); + }); + + cy.createWorkspace({ + name: workspace2Name, + description: workspace2Description, + features: ['use-case-search'], + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspace2Id = value; + cy.intercept('DELETE', `/api/workspaces/${workspace2Id}`).as( + 'deleteWorkspace2Request' + ); + }); + // Visit workspace list page + miscUtils.visitPage(`/app/workspace_list`); + }); + + afterEach(() => { + cy.deleteWorkspaceByName(workspace1Name); + cy.deleteWorkspaceByName(workspace2Name); + }); + + describe('delete a workspace successfully using action buttons', () => { + it('should successfully load delete button and show delete modal when clicking action button', () => { + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId(`checkboxSelectRow-${workspace1Id}`) + .parents('tr') + .within(() => { + cy.getElementByTestId('euiCollapsedItemActionsButton').click(); + }); + cy.getElementByTestId('workspace-list-delete-icon').should( + 'be.visible' + ); + cy.getElementByTestId('workspace-list-delete-icon').click(); + cy.contains('Delete workspace').should('be.visible'); + cy.contains( + 'The following workspace will be permanently deleted. This action cannot be undone' + ).should('be.visible'); + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId('delete-workspace-modal-input').type('delete'); + cy.getElementByTestId('delete-workspace-modal-confirm').click(); + cy.wait('@deleteWorkspace1Request').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.location('pathname').should('include', 'app/workspace_list'); + cy.contains('Delete workspace successfully').should('be.visible'); + cy.contains(workspace1Name).should('not.exist'); + }); + }); + + describe('delete workspace(s) successfully using multi-deletion button', () => { + it('should successfully show multi-deletion button and perform deletion when choosing one workspace', () => { + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId(`checkboxSelectRow-${workspace1Id}`).click(); + cy.getElementByTestId('multi-deletion-button').should('be.visible'); + cy.getElementByTestId('multi-deletion-button').click(); + cy.contains('Delete workspace').should('be.visible'); + cy.contains( + 'The following workspace will be permanently deleted. This action cannot be undone' + ).should('be.visible'); + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId('delete-workspace-modal-input').type('delete'); + cy.getElementByTestId('delete-workspace-modal-confirm').click(); + cy.wait('@deleteWorkspace1Request').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.location('pathname').should('include', 'app/workspace_list'); + cy.contains('Delete workspace successfully').should('be.visible'); + cy.contains(workspace1Name).should('not.exist'); + }); + + it('should successfully delete all', () => { + cy.contains(workspace1Name).should('be.visible'); + cy.contains(workspace2Name).should('be.visible'); + cy.getElementByTestId('checkboxSelectAll').click(); + cy.getElementByTestId('multi-deletion-button').should('be.visible'); + cy.getElementByTestId('multi-deletion-button').click(); + cy.contains('Delete workspace').should('be.visible'); + cy.contains( + 'The following workspace will be permanently deleted. This action cannot be undone' + ).should('be.visible'); + cy.contains(workspace1Name).should('be.visible'); + cy.contains(workspace2Name).should('be.visible'); + cy.getElementByTestId('delete-workspace-modal-input').type('delete'); + cy.getElementByTestId('delete-workspace-modal-confirm').click(); + cy.wait('@deleteWorkspace1Request').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.location('pathname').should('include', 'app/workspace_list'); + cy.contains('Delete workspace successfully').should('be.visible'); + cy.contains(workspace1Name).should('not.exist'); + cy.contains(workspace2Name).should('not.exist'); + }); + }); + }); + + describe('Workspace deletion in workspace detail page', () => { + before(() => { + cy.deleteWorkspaceByName(workspace1Name); + cy.createWorkspace({ + name: workspace1Name, + description: workspace1Description, + features: ['use-case-observability'], + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + }, + }).then((value) => { + workspace1Id = value; + }); + }); + + beforeEach(() => { + cy.intercept( + 'DELETE', + `/w/${workspace1Id}/api/workspaces/${workspace1Id}` + ).as('deleteWorkspace1Request'); + // Visit workspace detail page + miscUtils.visitPage(`w/${workspace1Id}/app/workspace_detail`); + }); + + it('should delete workspace in workspace detail page', () => { + cy.getElementByTestId('workspace-detail-delete-button').click(); + cy.contains('Delete workspace').should('be.visible'); + cy.contains(workspace1Name).should('be.visible'); + cy.getElementByTestId('delete-workspace-modal-input').type( + workspace1Name + ); + cy.getElementByTestId('delete-workspace-modal-confirm').click(); + cy.wait('@deleteWorkspace1Request').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.contains('Delete workspace successfully').should('be.visible'); + cy.location('pathname').should('include', 'app/workspace_list'); + cy.contains(workspace1Name).should('not.exist'); + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases.js new file mode 100644 index 000000000..aeb72573f --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_detail.cases.js @@ -0,0 +1,300 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { ADMIN_AUTH } from '../../../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'; + +export const WorkspaceDetailTestCases = () => { + const NONE_DASHBOARDS_ADMIN_USERNAME = 'workspace-test'; + const WORKSPACE_TEST_ROLE_NAME = 'workspace-test-role'; + + const miscUtils = new MiscUtils(cy); + const workspaceName = 'test_workspace_320sdfouAz'; + let workspaceDescription = 'This is a workspace description.'; + let workspaceId; + let workspaceFeatures = ['use-case-observability']; + + if (Cypress.env('WORKSPACE_ENABLED')) { + describe('Workspace detail', () => { + before(() => { + if (Cypress.env('SECURITY_ENABLED')) { + cy.createInternalUser( + NONE_DASHBOARDS_ADMIN_USERNAME, + workspaceTestUser + ); + cy.createRole(WORKSPACE_TEST_ROLE_NAME, workspaceTestRole); + cy.createRoleMapping( + WORKSPACE_TEST_ROLE_NAME, + workspaceTestRoleMapping + ); + } + cy.deleteWorkspaceByName(workspaceName); + cy.createWorkspace({ + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + library_read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, + read: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, + }, + }, + }).then((value) => (workspaceId = value)); + }); + + after(() => { + cy.deleteWorkspaceById(workspaceId); + if (Cypress.env('SECURITY_ENABLED')) { + cy.deleteRoleMapping(WORKSPACE_TEST_ROLE_NAME); + cy.deleteInternalUser(NONE_DASHBOARDS_ADMIN_USERNAME); + cy.deleteRole(WORKSPACE_TEST_ROLE_NAME); + } + }); + + describe('workspace details', () => { + beforeEach(() => { + // Visit workspace update page + miscUtils.visitPage(`w/${workspaceId}/app/workspace_detail`); + + cy.intercept( + 'PUT', + `/w/${workspaceId}/api/workspaces/${workspaceId}` + ).as('updateWorkspaceRequest'); + cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); + }); + + describe('Validate workspace name and description', () => { + it('workspace name is required', () => { + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-nameInputText' + ).clear({ + force: true, + }); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).clear({ + force: true, + }); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description'); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click( + { + force: true, + } + ); + cy.contains('Enter a name.').should('exist'); + }); + + it('workspace name is not valid', () => { + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-nameInputText' + ).clear({ + force: true, + }); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).clear({ + force: true, + }); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-nameInputText' + ).type('./+'); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description'); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click( + { + force: true, + } + ); + cy.contains('Enter a valid name.').should('exist'); + }); + }); + + describe('Update a workspace successfully', () => { + it('should successfully update a workspace', () => { + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-nameInputText' + ).clear({ + force: true, + }); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).clear({ + force: true, + }); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-nameInputText' + ).type(workspaceName); + workspaceDescription = 'test_workspace_description.+~!'; + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type(workspaceDescription); + cy.getElementByTestId( + 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' + ).click(); + cy.get('button[aria-label="Select #6092C0 as the color"]').click(); + cy.get('button.euiSuperSelectControl') + .contains('Observability') + .click({ + force: true, + }); + cy.get('button.euiSuperSelect__item').contains('Analytics').click({ + force: true, + }); + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click( + { + force: true, + } + ); + cy.wait('@updateWorkspaceRequest').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); + cy.location('pathname', { timeout: 6000 }).should( + 'include', + 'app/workspace_detail' + ); + const expectedWorkspace = { + name: workspaceName, + description: 'test_workspace_description.+~!', + color: '#6092C0', + features: ['use-case-all'], + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + // Update features after updated + workspaceFeatures = expectedWorkspace.features; + }); + }); + }); + + if ( + Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && + Cypress.env('SECURITY_ENABLED') + ) { + describe('update with different workspace access level', () => { + const originalUser = ADMIN_AUTH.username; + const originalPassword = ADMIN_AUTH.password; + beforeEach(() => { + ADMIN_AUTH.username = originalUser; + ADMIN_AUTH.password = originalPassword; + }); + after(() => { + ADMIN_AUTH.newUser = originalUser; + ADMIN_AUTH.newPassword = originalPassword; + }); + it('should not able to update workspace meta for non workspace admin', () => { + ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USERNAME; + ADMIN_AUTH.newPassword = workspaceTestUser.password; + + // Visit workspace list page + miscUtils.visitPage(`/app/workspace_list`); + + cy.getElementByTestId('headerApplicationTitle') + .contains('Workspaces') + .should('be.exist'); + + cy.get('[role="main"]').contains(workspaceName).should('be.exist'); + + cy.get(`#${workspaceId}-actions`).click(); + cy.getElementByTestId('workspace-list-edit-icon').click(); + + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-edit' + ).click(); + + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).clear({ + force: true, + }); + + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click( + { + force: true, + } + ); + cy.getElementByTestId('globalToastList') + .contains('Invalid workspace permission') + .should('be.exist'); + }); + + it('should able to update workspace meta for workspace admin', () => { + const kibanaServerAdminWorkspace = { + name: 'kibana-server-workspace-admin', + features: ['use-case-all'], + settings: { + permissions: { + library_write: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, + write: { users: [NONE_DASHBOARDS_ADMIN_USERNAME] }, + }, + }, + }; + cy.deleteWorkspaceByName(kibanaServerAdminWorkspace.name); + cy.createWorkspace(kibanaServerAdminWorkspace) + .as('adminWorkspaceId') + .then(() => { + ADMIN_AUTH.newUser = NONE_DASHBOARDS_ADMIN_USERNAME; + ADMIN_AUTH.newPassword = workspaceTestUser.password; + }); + + // Visit workspace list page + miscUtils.visitPage(`/app/workspace_list`); + + cy.getElementByTestId('headerApplicationTitle') + .contains('Workspaces') + .should('be.exist'); + + cy.get('[role="main"]') + .contains(kibanaServerAdminWorkspace.name) + .should('be.exist'); + + cy.get('@adminWorkspaceId').then((adminWorkspaceId) => { + cy.get(`#${adminWorkspaceId}-actions`).click(); + }); + cy.getElementByTestId('workspace-list-edit-icon').click(); + + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-edit' + ).click(); + + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).clear({ + force: true, + }); + + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('This is a new workspace description.'); + + cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click( + { + force: true, + } + ); + cy.getElementByTestId('globalToastList') + .contains('Update workspace successfully') + .should('be.exist'); + + cy.get('@adminWorkspaceId').then((adminWorkspaceId) => { + const expectedWorkspace = { + ...kibanaServerAdminWorkspace, + description: 'This is a new workspace description.', + }; + cy.checkWorkspace(adminWorkspaceId, expectedWorkspace); + cy.deleteWorkspaceById(adminWorkspaceId); + }); + }); + }); + } + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_essential_overviews.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_essential_overviews.cases.js new file mode 100644 index 000000000..e8c2f0dad --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_essential_overviews.cases.js @@ -0,0 +1,164 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +export const WorkspaceEssentialOverviewTestCases = () => { + const miscUtils = new MiscUtils(cy); + const workspaceName = `test_workspace_${Math.random() + .toString(36) + .substring(7)}`; + let workspaceDescription = 'This is a workspace description.'; + let workspaceId; + let datasourceId; + let workspaceFeatures = ['use-case-essentials']; + + const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); + + if (Cypress.env('WORKSPACE_ENABLED')) { + const createWorkspace = (datasourceId) => { + cy.createWorkspace({ + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + ...(datasourceId ? { dataSources: [datasourceId] } : {}), + }, + }).then((value) => { + workspaceId = value; + // load sample data + cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId); + }); + }; + + describe('Essential workspace overview', () => { + before(() => { + cy.deleteWorkspaceByName(workspaceName); + if (MDSEnabled) { + cy.deleteAllDataSources(); + cy.createDataSourceNoAuth().then((result) => { + datasourceId = result[0]; + expect(datasourceId).to.be.a('string').that.is.not.empty; + createWorkspace(datasourceId); + }); + } else { + createWorkspace(); + } + }); + + after(() => { + if (workspaceId) { + cy.removeSampleDataForWorkspace( + 'ecommerce', + workspaceId, + datasourceId + ); + cy.deleteWorkspaceById(workspaceId); + } + cy.deleteAllDataSources(); + }); + + beforeEach(() => { + // Visit workspace update page + miscUtils.visitPage(`w/${workspaceId}/app/essentials_overview`); + // wait for page load + cy.contains('h1', 'Overview'); + }); + + it('Get started cards display correctly', () => { + // verify four get started cards exist + cy.contains( + 'Install sample data to experiment with OpenSearch.' + ).click(); + // verify url has app/import_sample_data + cy.url().should('include', 'app/import_sample_data'); + + // browser back + cy.go('back'); + cy.contains('Explore data to uncover and discover insights.').click(); + // verify url has app/data-explorer/discover + cy.url().should('include', 'app/data-explorer/discover'); + + // browser back + cy.go('back'); + cy.contains( + 'Gain deeper insights by visualizing and aggregating your data.' + ).click(); + // verify url has app/visualize + cy.url().should('include', 'app/visualize'); + + cy.go('back'); + cy.contains( + 'Monitor and explore your data using dynamic data visualization tools.' + ).click(); + // verify url has app/dashboards + cy.url().should('include', 'app/dashboards'); + }); + + it('Assets cards display correctly', () => { + // no recently view assets + cy.contains('No assets to display'); + + // recentlyCard + cy.contains('Recently updated').should('be.visible').click(); + // should have 6 elements + cy.getElementByTestId('recentlyCard').should('have.length', 6); + + // filter by dashboard + cy.getElementByTestId('comboBoxInput').click(); + cy.get('span.euiComboBoxOption__content').contains('dashboard').click(); + + // click dashboard card + cy.getElementByTestId('recentlyCard').first().click(); + + // verify url has /app/dashboards + cy.url().should('include', 'app/dashboards'); + + cy.go('back'); + + // view all + cy.contains('View all').click(); + // verify url has /app/objects + cy.url().should('include', 'app/objects'); + }); + + it('Opensearch documentation cards display correctly', () => { + cy.contains('OpenSearch Documentation'); + + // get a link with text as Quickstart guide + cy.get('a') + .contains('Quickstart guide') + .should('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/quickstart\/$/ + ); + }); + + cy.get('a') + .contains('Building data visualizations') + .should('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/visualize\/viz-index\/$/ + ); + }); + + cy.get('a') + .contains('Creating dashboards') + .should('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /^https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/dashboards\/dashboard\/index\/$/ + ); + }); + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases.js new file mode 100644 index 000000000..ea5aec66b --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_import_sample_data_to.cases.js @@ -0,0 +1,175 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); + +export const WorkspaceImportSampleDataTestCases = () => { + if (Cypress.env('WORKSPACE_ENABLED')) { + describe('import sample data to workspace', () => { + let workspaceId; + let dataSourceId; + let dataSourceTitle; + const workspaceName = `workspace-${new Date().getTime()}`; + + const getTitleWithDataSource = (title) => { + if (!dataSourceTitle) { + return title; + } + return `${title}_${dataSourceTitle}`; + }; + + before(() => { + if (MDSEnabled) { + cy.createDataSourceNoAuth() + .then((result) => { + dataSourceId = result[0]; + dataSourceTitle = result[1]; + return result; + }) + .then((result) => { + cy.createWorkspace({ + name: workspaceName, + settings: MDSEnabled + ? { + dataSources: [result[0]], + } + : undefined, + }).then((id) => { + workspaceId = id; + }); + }); + } else { + cy.createWorkspace({ + name: workspaceName, + }).then((id) => { + workspaceId = id; + }); + } + }); + + after(() => { + if (workspaceId) { + cy.deleteWorkspaceById(workspaceId); + } + if (MDSEnabled) { + cy.deleteAllDataSources(); + } + }); + + beforeEach(() => { + cy.visit(`/w/${workspaceId}/app/import_sample_data`); + if (MDSEnabled) { + cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); + } + }); + + it('should show Add data buttons if sample data not installed', () => { + cy.getElementByTestId('addSampleDataSetecommerce').should('be.visible'); + cy.getElementByTestId('addSampleDataSetflights').should('be.visible'); + cy.getElementByTestId('addSampleDataSetlogs').should('be.visible'); + }); + + it('should show remove buttons after sample data installed', () => { + cy.getElementByTestId('addSampleDataSetecommerce').click(); + cy.getElementByTestId('addSampleDataSetflights').click(); + cy.getElementByTestId('addSampleDataSetlogs').click(); + + cy.getElementByTestId('removeSampleDataSetecommerce').should( + 'be.visible' + ); + cy.getElementByTestId('removeSampleDataSetflights').should( + 'be.visible' + ); + cy.getElementByTestId('removeSampleDataSetlogs').should('be.visible'); + + cy.getElementByTestId('removeSampleDataSetecommerce').click(); + cy.getElementByTestId('removeSampleDataSetflights').click(); + cy.getElementByTestId('removeSampleDataSetlogs').click(); + }); + + it('should be able to visit ecommerce dashboard', () => { + cy.getElementByTestId('addSampleDataSetecommerce').click(); + + cy.getElementByTestId('launchSampleDataSetecommerce') + .should('be.visible') + .click(); + + cy.location('href').should( + 'include', + `/w/${workspaceId}/app/dashboards` + ); + cy.getElementByTestId('headerAppActionMenu').should( + 'contain', + getTitleWithDataSource('[eCommerce] Revenue Dashboard') + ); + cy.get( + `[data-title="${getTitleWithDataSource( + '[eCommerce] Total Revenue' + )}"]` + ).should('not.contain', 'No results found'); + cy.visit(`/w/${workspaceId}/app/import_sample_data`); + + if (MDSEnabled) { + cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); + } + cy.getElementByTestId('removeSampleDataSetecommerce').click(); + }); + + it('should be able to visit flights dashboards', () => { + cy.getElementByTestId('addSampleDataSetflights').click(); + + cy.getElementByTestId('launchSampleDataSetflights') + .should('be.visible') + .click(); + + cy.location('href').should( + 'include', + `/w/${workspaceId}/app/dashboards` + ); + cy.getElementByTestId('headerAppActionMenu').should( + 'contain', + getTitleWithDataSource('[Flights] Global Flight Dashboard') + ); + cy.get( + `[data-title="${getTitleWithDataSource('[Flights] Flight Delays')}"]` + ).should('not.contain', 'No results found'); + cy.visit(`/w/${workspaceId}/app/import_sample_data`); + + if (MDSEnabled) { + cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); + } + cy.getElementByTestId('removeSampleDataSetflights').click(); + }); + + it('should be able to visit logs dashboards', () => { + cy.getElementByTestId('addSampleDataSetlogs').click(); + + cy.getElementByTestId('launchSampleDataSetlogs') + .should('be.visible') + .click(); + + cy.location('href').should( + 'include', + `/w/${workspaceId}/app/dashboards` + ); + cy.getElementByTestId('headerAppActionMenu').should( + 'contain', + getTitleWithDataSource('[Logs] Web Traffic') + ); + cy.get( + `[data-title="${getTitleWithDataSource( + '[Logs] Unique Visitors vs. Average Bytes' + )}"]` + ).should('not.contain', 'No results found'); + cy.visit(`/w/${workspaceId}/app/import_sample_data`); + + if (MDSEnabled) { + cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); + } + cy.getElementByTestId('removeSampleDataSetlogs').click(); + }); + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_initial.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_initial.cases.js new file mode 100644 index 000000000..1ebe55560 --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_initial.cases.js @@ -0,0 +1,273 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { ADMIN_AUTH } from '../../../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'; + +export const WorkspaceInitialTestCases = () => { + 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') + .should('have.attr', 'target', '_blank') + .and('have.attr', 'href') + .and((href) => { + expect(href).to.match( + /https:\/\/opensearch.org\/docs\/(latest|(\d.)+)\/opensearch\/index\/$/ + ); + }); + + 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'); + }); + }); + } + }); + } +}; diff --git a/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_search_overviews.cases.js b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_search_overviews.cases.js new file mode 100644 index 000000000..35613d139 --- /dev/null +++ b/cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_search_overviews.cases.js @@ -0,0 +1,94 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +export const WorkspaceSearchOverviewTestCases = () => { + const miscUtils = new MiscUtils(cy); + const workspaceName = `test_workspace_search_${Math.random() + .toString(36) + .substring(7)}`; + let workspaceDescription = 'This is a search workspace description.'; + let workspaceId; + let datasourceId; + let workspaceFeatures = ['use-case-search']; + + const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); + + if (Cypress.env('WORKSPACE_ENABLED')) { + const createWorkspace = (datasourceId) => { + cy.createWorkspace({ + name: workspaceName, + description: workspaceDescription, + features: workspaceFeatures, + settings: { + permissions: { + library_write: { users: ['%me%'] }, + write: { users: ['%me%'] }, + }, + ...(datasourceId ? { dataSources: [datasourceId] } : {}), + }, + }).then((value) => { + workspaceId = value; + }); + }; + + describe('Search workspace overview', () => { + before(() => { + cy.deleteWorkspaceByName(workspaceName); + if (MDSEnabled) { + cy.deleteAllDataSources(); + cy.createDataSourceNoAuth().then((result) => { + datasourceId = result[0]; + expect(datasourceId).to.be.a('string').that.is.not.empty; + createWorkspace(datasourceId); + }); + } else { + createWorkspace(); + } + }); + + after(() => { + if (workspaceId) { + cy.deleteWorkspaceById(workspaceId); + } + cy.deleteAllDataSources(); + }); + + beforeEach(() => { + // Visit workspace update page + miscUtils.visitPage(`w/${workspaceId}/app/search_overview`); + // wait for page load + cy.contains('h1', 'Overview'); + }); + + it('Set up search cards display correctly', () => { + cy.contains( + 'Explore search capabilities and functionality of OpenSearch.' + ); + cy.contains( + 'Create a document collection (an index) to query your data.' + ); + + cy.contains('Explore data to uncover and discover insights.').click(); + // verify url has app/data-explorer/discover + cy.url().should('include', 'app/data-explorer/discover'); + }); + + it('Different search techniques section display correctly', () => { + cy.contains('h3', 'Text search').should('be.visible'); + cy.contains('h3', 'Analyzers').should('be.visible'); + cy.contains('h3', 'Semantic vector search').should('be.visible'); + cy.contains('h3', 'Neural sparse search').should('be.visible'); + cy.contains('h3', 'Hybrid search').should('be.visible'); + }); + + it('Configure and evaluate search cards display correctly', () => { + cy.contains('Compare search results').should('be.visible').click(); + cy.url().should('contains', 'app/searchRelevance'); + }); + }); + } +};