From 5a12c9b4868f31302b84d6800776944c24f7fe21 Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Tue, 10 Sep 2024 15:55:38 +0800 Subject: [PATCH] Add FTs for data source association in workspace creator and detail Signed-off-by: Kapian1234 --- .../mds_workspace_create.spec.js | 132 +++++++++++------ .../mds_workspace_detail.spec.js | 136 ++++++++++++------ ...ds_workspace_import_sample_data_to.spec.js | 14 +- 3 files changed, 193 insertions(+), 89 deletions(-) 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 d2cccec8c..0d98c7496 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 @@ -6,6 +6,23 @@ import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; const miscUtils = new MiscUtils(cy); const workspaceName = 'test_workspace_az3RBx6cE'; + +const inputWorkspaceName = (workspaceName) => { + const nameInput = cy.getElementByTestId( + 'workspaceForm-workspaceDetails-nameInputText' + ); + nameInput.clear(); + nameInput.type(workspaceName); +}; + +const inputWorkspaceColor = (color = '#000000') => { + const colorPicker = cy.getElementByTestId( + 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' + ); + colorPicker.clear({ force: true }); + colorPicker.type(color); +}; + if (Cypress.env('WORKSPACE_ENABLED')) { describe('Create workspace', () => { before(() => { @@ -29,21 +46,11 @@ if (Cypress.env('WORKSPACE_ENABLED')) { describe('Create a workspace successfully', () => { it('should successfully create a workspace', () => { - cy.getElementByTestId('workspaceForm-workspaceDetails-nameInputText') - .clear({ - force: true, - }) - .type(workspaceName); + inputWorkspaceName(workspaceName); cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description.+~!'); - cy.getElementByTestId( - 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' - ) - .clear({ - force: true, - }) - .type('#000000'); + inputWorkspaceColor(); cy.getElementByTestId('workspaceUseCase-observability').click({ force: true, }); @@ -58,7 +65,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.location('pathname', { timeout: 6000 }).should( 'include', - 'app/discover' + `w/${workspaceId}/app` ); const expectedWorkspace = { @@ -75,12 +82,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { it('workspace name is required', () => { cy.getElementByTestId( 'workspaceForm-workspaceDetails-nameInputText' - ).clear({ - force: true, - }); - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description'); + ).clear(); cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ force: true, }); @@ -88,9 +90,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { }); it('workspace name is not valid', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).type('./+'); + inputWorkspaceName('./+'); cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); @@ -101,11 +101,12 @@ if (Cypress.env('WORKSPACE_ENABLED')) { }); it('workspace name cannot use an existing name', () => { - cy.getElementByTestId('workspaceForm-workspaceDetails-nameInputText') - .clear({ - force: true, - }) - .type(workspaceName); + cy.deleteWorkspaceByName(workspaceName); + cy.createWorkspace({ + name: workspaceName, + features: ['use-case-observability'], + }); + inputWorkspaceName(workspaceName); cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); @@ -129,27 +130,20 @@ if (Cypress.env('WORKSPACE_ENABLED')) { }); it('should successfully create a workspace with permissions', () => { - cy.getElementByTestId('workspaceForm-workspaceDetails-nameInputText') - .clear({ - force: true, - }) - .type(workspaceName); + inputWorkspaceName(workspaceName); cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); - cy.getElementByTestId( - 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' - ) - .clear({ - force: true, - }) - .type('#000000'); + inputWorkspaceColor(); + cy.getElementByTestId('workspaceUseCase-observability').click({ + force: true, + }); cy.getElementByTestId( 'workspaceForm-permissionSettingPanel-addNew' ).click(); - cy.get( - 'input[placeholder="Enter user name or uer ID"][value=""]' - ).type('test_user_sfslja260'); + cy.getElementByTestId('workspaceFormUserIdOrGroupInput') + .last() + .type('test_user_sfslja260'); cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ force: true, }); @@ -160,7 +154,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { workspaceId = interception.response.body.result.id; cy.location('pathname', { timeout: 6000 }).should( 'include', - 'app/discover' + `w/${workspaceId}/app` ); const expectedWorkspace = { name: workspaceName, @@ -186,5 +180,57 @@ if (Cypress.env('WORKSPACE_ENABLED')) { }); }); } + + if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { + describe('Create a workspace with data sources successfully', () => { + let dataSourceId; + let dataSourceTitle; + before(() => { + cy.deleteWorkspaceByName(workspaceName); + cy.createDataSourceNoAuth().then((result) => { + dataSourceId = result[0]; + dataSourceTitle = result[1]; + return result; + }); + }); + it('should successfully create a workspace with data sources', () => { + inputWorkspaceName(workspaceName); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-descriptionInputText' + ).type('test_workspace_description'); + inputWorkspaceColor(); + cy.getElementByTestId('workspaceUseCase-observability').click({ + force: true, + }); + cy.getElementByTestId( + 'workspace-creator-dataSources-assign-button' + ).click(); + cy.contains('div', dataSourceTitle).click(); + cy.getElementByTestId( + 'workspace-detail-dataSources-associateModal-save-button' + ).click(); + 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); + cy.checkAssignedDatasource(dataSourceId, workspaceId); + cy.deleteAllDataSources(); + }); + }); + }); + } }); } 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 105088d2b..edc0c528b 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 @@ -4,10 +4,13 @@ */ import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED'); 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', () => { @@ -16,7 +19,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.createWorkspace({ name: workspaceName, description: workspaceDescription, - features: ['workspace_detail', 'use-case-observability'], + features: workspaceFeatures, settings: { permissions: { library_write: { users: ['%me%'] }, @@ -41,17 +44,20 @@ if (Cypress.env('WORKSPACE_ENABLED')) { it('should successfully load the page', () => { cy.contains(workspaceName, { timeout: 60000 }).should('be.visible'); - cy.contains('Overview', { timeout: 60000 }).should('be.visible'); - cy.contains('settings', { timeout: 60000 }).should('be.visible'); + cy.contains('Details', { timeout: 60000 }).should('be.visible'); + if (MDSEnabled) { + cy.contains('Data sources', { timeout: 60000 }).should('be.visible'); + } if (Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED')) { cy.contains('Collaborators', { timeout: 60000 }).should('be.visible'); } }); - describe('settings tab', () => { + describe('Details tab', () => { beforeEach(() => { - cy.contains('settings').click(); + cy.contains('Details').click(); + cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); }); describe('Validate workspace name and description', () => { @@ -66,7 +72,6 @@ if (Cypress.env('WORKSPACE_ENABLED')) { ).clear({ force: true, }); - cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); @@ -87,7 +92,6 @@ if (Cypress.env('WORKSPACE_ENABLED')) { ).clear({ force: true, }); - cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); cy.getElementByTestId( 'workspaceForm-workspaceDetails-nameInputText' ).type('./+'); @@ -113,7 +117,6 @@ if (Cypress.env('WORKSPACE_ENABLED')) { ).clear({ force: true, }); - cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); cy.getElementByTestId( 'workspaceForm-workspaceDetails-nameInputText' ).type(workspaceName); @@ -124,6 +127,16 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId( 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' ).type('#D36086'); + cy.get('button.euiSuperSelectControl') + .contains('Observability') + .click({ + force: true, + }); + cy.get('button.euiSuperSelect__item') + .contains('Analytics (All)') + .click({ + force: true, + }); cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ force: true, }); @@ -137,9 +150,11 @@ if (Cypress.env('WORKSPACE_ENABLED')) { const expectedWorkspace = { name: workspaceName, description: 'test_workspace_description.+~!', - features: ['workspace_detail', 'use-case-observability'], + features: ['use-case-all'], }; cy.checkWorkspace(workspaceId, expectedWorkspace); + // Update features after updated + workspaceFeatures = expectedWorkspace.features; }); }); }); @@ -148,21 +163,80 @@ if (Cypress.env('WORKSPACE_ENABLED')) { Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && Cypress.env('SECURITY_ENABLED') ) { - describe('Update a workspace with permissions successfully', () => { + describe('Collaborators tab', () => { + describe('Update a workspace with permissions successfully', () => { + beforeEach(() => { + cy.contains('Collaborators').click(); + cy.getElementByTestId( + 'workspaceForm-workspaceDetails-edit' + ).click(); + }); + it('should successfully update a workspace with permissions', () => { + cy.getElementByTestId( + 'workspaceForm-permissionSettingPanel-addNew' + ).click(); + cy.getElementByTestId('workspaceFormUserIdOrGroupInput') + .last() + .type('test_user_Fnxs972xC'); + 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: workspaceDescription, + features: workspaceFeatures, + permissions: { + read: { + users: ['test_user_Fnxs972xC'], + }, + library_read: { + users: ['test_user_Fnxs972xC'], + }, + write: { + users: [`${Cypress.env('username')}`], + }, + library_write: { + users: [`${Cypress.env('username')}`], + }, + }, + }; + cy.checkWorkspace(workspaceId, expectedWorkspace); + }); + }); + }); + } + + if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { + describe('Update a workspace with data source successfully', () => { + let dataSourceId; + let dataSourceTitle; + before(() => { + cy.createDataSourceNoAuth().then((result) => { + dataSourceId = result[0]; + dataSourceTitle = result[1]; + return result; + }); + }); beforeEach(() => { - cy.contains('Collaborators').click(); + cy.contains('Data sources').click(); }); - it('should successfully update a workspace with permissions', () => { - cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); + it('should successfully update a workspace with data source', () => { + cy.getElementByTestId('workspace-detail-dataSources-assign-button') + .first() + .click(); + cy.contains('div', dataSourceTitle).click(); cy.getElementByTestId( - 'workspaceForm-permissionSettingPanel-addNew' + 'workspace-detail-dataSources-associateModal-save-button' ).click(); - cy.get( - 'input[placeholder="Enter user name or uer ID"][value=""]' - ).type('test_user_Fnxs972xC'); - cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ - force: true, - }); cy.wait('@updateWorkspaceRequest').then((interception) => { expect(interception.response.statusCode).to.equal(200); }); @@ -170,26 +244,8 @@ if (Cypress.env('WORKSPACE_ENABLED')) { 'include', 'app/workspace_detail' ); - const expectedWorkspace = { - name: workspaceName, - description: workspaceDescription, - features: ['workspace_detail', 'use-case-observability'], - permissions: { - read: { - users: ['test_user_Fnxs972xC'], - }, - library_read: { - users: ['test_user_Fnxs972xC'], - }, - write: { - users: [`${Cypress.env('username')}`], - }, - library_write: { - users: [`${Cypress.env('username')}`], - }, - }, - }; - cy.checkWorkspace(workspaceId, expectedWorkspace); + cy.checkAssignedDatasource(dataSourceId, workspaceId); + cy.deleteAllDataSources(); }); }); } 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 f988f4ddc..0f82b2fee 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 @@ -59,7 +59,6 @@ if (Cypress.env('WORKSPACE_ENABLED')) { beforeEach(() => { cy.visit(`/w/${workspaceId}/app/import_sample_data`); - cy.waitForLoader(); if (MDSEnabled) { cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId); } @@ -95,9 +94,10 @@ if (Cypress.env('WORKSPACE_ENABLED')) { .click(); cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`); - cy.getElementByTestId('breadcrumb last') - .contains(getTitleWithDataSource('[eCommerce] Revenue Dashboard')) - .should('be.visible'); + cy.getElementByTestId('headerAppActionMenu').should( + 'contain', + getTitleWithDataSource('[eCommerce] Revenue Dashboard') + ); cy.get( `[data-title="${getTitleWithDataSource('[eCommerce] Total Revenue')}"]` ).should('not.contain', 'No results found'); @@ -117,7 +117,8 @@ if (Cypress.env('WORKSPACE_ENABLED')) { .click(); cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`); - cy.getElementByTestId('breadcrumb last').contains( + cy.getElementByTestId('headerAppActionMenu').should( + 'contain', getTitleWithDataSource('[Flights] Global Flight Dashboard') ); cy.get( @@ -139,7 +140,8 @@ if (Cypress.env('WORKSPACE_ENABLED')) { .click(); cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`); - cy.getElementByTestId('breadcrumb last').contains( + cy.getElementByTestId('headerAppActionMenu').should( + 'contain', getTitleWithDataSource('[Logs] Web Traffic') ); cy.get(