diff --git a/.github/workflows/ml-commons-release-e2e-workflow.yml b/.github/workflows/ml-commons-release-e2e-workflow.yml index 51a1cdedd..3abd6f9ef 100644 --- a/.github/workflows/ml-commons-release-e2e-workflow.yml +++ b/.github/workflows/ml-commons-release-e2e-workflow.yml @@ -32,3 +32,4 @@ jobs: test-name: ML Commons With Multi Data Source test-command: env CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/plugins/ml-commons-dashboards/mds*.js' osd-serve-args: --ml_commons_dashboards.enabled=true --data_source.enabled=true --data_source.hideLocalCluster=true + artifact-name-suffix: "-with-security-and-mds" diff --git a/.github/workflows/workspace-release-e2e-workflow.yml b/.github/workflows/workspace-release-e2e-workflow.yml index 913a9e56f..9978664ce 100644 --- a/.github/workflows/workspace-release-e2e-workflow.yml +++ b/.github/workflows/workspace-release-e2e-workflow.yml @@ -23,22 +23,25 @@ jobs: with: test-name: dashboards workspace test-command: env CYPRESS_WORKSPACE_ENABLED=true CYPRESS_SAVED_OBJECTS_PERMISSION_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/*' - osd-serve-args: --workspace.enabled=true --savedObjects.permission.enabled=true --opensearch_security.multitenancy.enabled=false --opensearchDashboards.dashboardAdmin.users='["admin"]' + osd-serve-args: --workspace.enabled=true --savedObjects.permission.enabled=true --opensearch_security.multitenancy.enabled=false --opensearchDashboards.dashboardAdmin.users='["admin"]' --uiSettings.overrides.home:useNewHomePage=true + artifact-name-suffix: "-with-security" tests-without-security: needs: changes if: ${{ needs.changes.outputs.tests == 'true' }} uses: ./.github/workflows/release-e2e-workflow-template.yml with: - test-name: dashboards workspace + test-name: dashboards workspace without security test-command: env CYPRESS_WORKSPACE_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/*' - osd-serve-args: --workspace.enabled=true --savedObjects.permission.enabled=false + osd-serve-args: --workspace.enabled=true --savedObjects.permission.enabled=false --uiSettings.overrides.home:useNewHomePage=true security-enabled: false + artifact-name-suffix: "-without-security" tests-with-multiple-data-source-and-disabled-local-cluster: needs: changes if: ${{ needs.changes.outputs.tests == 'true' }} uses: ./.github/workflows/release-e2e-workflow-template.yml with: - test-name: dashboards workspace + test-name: dashboards workspace with MDS test-command: env CYPRESS_DISABLE_LOCAL_CLUSTER=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true CYPRESS_WORKSPACE_ENABLED=true CYPRESS_SAVED_OBJECTS_PERMISSION_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds*.js' - osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --data_source.hideLocalCluster=true --workspace.enabled=true --savedObjects.permission.enabled=true --opensearch_security.multitenancy.enabled=false --opensearchDashboards.dashboardAdmin.users='["admin"]' + osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --data_source.hideLocalCluster=true --workspace.enabled=true --savedObjects.permission.enabled=true --opensearch_security.multitenancy.enabled=false --opensearchDashboards.dashboardAdmin.users='["admin"]' --uiSettings.overrides.home:useNewHomePage=true security-enabled: true + artifact-name-suffix: "-with-security-and-mds" 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 5b8775e40..61a24dced 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 @@ -4,12 +4,41 @@ */ import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + 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(() => { @@ -21,6 +50,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { after(() => { cy.deleteWorkspaceByName(workspaceName); + if (MDSEnabled) { + cy.deleteAllDataSources(); + } }); it('should successfully load the page', () => { @@ -29,18 +61,14 @@ if (Cypress.env('WORKSPACE_ENABLED')) { describe('Create a workspace successfully', () => { it('should successfully create a workspace', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).type(workspaceName); + inputWorkspaceName(workspaceName); cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description.+~!'); - cy.getElementByTestId( - 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' - ).type('#000000'); cy.getElementByTestId('workspaceUseCase-observability').click({ force: true, }); + inputDataSourceWhenMDSEnabled(dataSourceTitle); cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ force: true, }); @@ -52,13 +80,13 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.location('pathname', { timeout: 6000 }).should( 'include', - 'app/workspace_detail' + `w/${workspaceId}/app` ); const expectedWorkspace = { name: workspaceName, description: 'test_workspace_description.+~!', - features: ['workspace_detail', 'use-case-observability'], + features: ['use-case-observability'], }; cy.checkWorkspace(workspaceId, expectedWorkspace); }); @@ -68,37 +96,41 @@ if (Cypress.env('WORKSPACE_ENABLED')) { describe('Validate workspace name and description', () => { it('workspace name is required', () => { cy.getElementByTestId( - 'workspaceForm-workspaceDetails-descriptionInputText' - ).type('test_workspace_description'); + 'workspaceForm-workspaceDetails-nameInputText' + ).clear(); + inputDataSourceWhenMDSEnabled(dataSourceTitle); cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ force: true, }); - cy.contains('Name is required. Enter a name.').should('exist'); + cy.contains('Enter a name.').should('exist'); }); it('workspace name is not valid', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).type('./+'); + inputWorkspaceName('./+'); cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); + inputDataSourceWhenMDSEnabled(dataSourceTitle); cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ force: true, }); - cy.contains('Name is invalid. Enter a valid name.').should('exist'); + cy.contains('Enter a valid name.').should('exist'); }); it('workspace name cannot use an existing name', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).type(workspaceName); + 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, }); @@ -106,15 +138,42 @@ if (Cypress.env('WORKSPACE_ENABLED')) { }); }); - it('workspace use case is required', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).type(workspaceName); - cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ - force: true, + 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'); + }); + }); }); - cy.contains('Use case is required. Select a use case.').should('exist'); - }); + } if ( Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED') && @@ -126,25 +185,14 @@ if (Cypress.env('WORKSPACE_ENABLED')) { }); it('should successfully create a workspace with permissions', () => { - cy.getElementByTestId( - 'workspaceForm-workspaceDetails-nameInputText' - ).type(workspaceName); + inputWorkspaceName(workspaceName); cy.getElementByTestId( 'workspaceForm-workspaceDetails-descriptionInputText' ).type('test_workspace_description'); - cy.getElementByTestId( - 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' - ).type('#000000'); cy.getElementByTestId('workspaceUseCase-observability').click({ force: true, }); - cy.getElementByTestId( - 'workspaceForm-permissionSettingPanel-user-addNew' - ).click(); - cy.contains('.euiComboBoxPlaceholder', 'Select a user') - .parent() - .find('input') - .type('test_user_sfslja260'); + inputDataSourceWhenMDSEnabled(dataSourceTitle); cy.getElementByTestId('workspaceForm-bottomBar-createButton').click({ force: true, }); @@ -155,19 +203,13 @@ if (Cypress.env('WORKSPACE_ENABLED')) { workspaceId = interception.response.body.result.id; cy.location('pathname', { timeout: 6000 }).should( 'include', - 'app/workspace_detail' + `w/${workspaceId}/app` ); const expectedWorkspace = { name: workspaceName, description: 'test_workspace_description', - features: ['workspace_detail', 'use-case-observability'], + features: ['use-case-observability'], permissions: { - read: { - users: ['test_user_sfslja260'], - }, - library_read: { - users: ['test_user_sfslja260'], - }, write: { users: [`${Cypress.env('username')}`], }, 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 a65652438..3475f612e 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,12 @@ */ import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + 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 +18,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%'] }, @@ -39,19 +41,9 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.deleteWorkspaceById(workspaceId); }); - 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'); - - if (Cypress.env('SAVED_OBJECTS_PERMISSION_ENABLED')) { - cy.contains('Collaborators', { timeout: 60000 }).should('be.visible'); - } - }); - - describe('settings tab', () => { + describe('workspace details', () => { beforeEach(() => { - cy.contains('Settings').click(); + cy.getElementByTestId('workspaceForm-workspaceDetails-edit').click(); }); describe('Validate workspace name and description', () => { @@ -72,7 +64,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ force: true, }); - cy.contains('Name is required. Enter a name.').should('exist'); + cy.contains('Enter a name.').should('exist'); }); it('workspace name is not valid', () => { @@ -95,7 +87,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.getElementByTestId('workspaceForm-bottomBar-updateButton').click({ force: true, }); - cy.contains('Name is invalid. Enter a valid name.').should('exist'); + cy.contains('Enter a valid name.').should('exist'); }); }); @@ -120,8 +112,14 @@ if (Cypress.env('WORKSPACE_ENABLED')) { ).type(workspaceDescription); cy.getElementByTestId( 'euiColorPickerAnchor workspaceForm-workspaceDetails-colorPicker' - ).type('#D36086'); - cy.getElementByTestId('workspaceUseCase-observability').click({ + ).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({ @@ -137,61 +135,14 @@ if (Cypress.env('WORKSPACE_ENABLED')) { const expectedWorkspace = { name: workspaceName, description: 'test_workspace_description.+~!', - features: ['workspace_detail', 'use-case-observability'], + 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 a workspace with permissions successfully', () => { - beforeEach(() => { - cy.contains('Collaborators').click(); - }); - it('should successfully update a workspace with permissions', () => { - cy.getElementByTestId( - 'workspaceForm-permissionSettingPanel-user-addNew' - ).click(); - cy.contains('.euiComboBoxPlaceholder', 'Select a user') - .parent() - .find('input') - .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: ['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); - }); - }); - } }); } 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..ea477fbb2 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,9 +59,8 @@ if (Cypress.env('WORKSPACE_ENABLED')) { beforeEach(() => { cy.visit(`/w/${workspaceId}/app/import_sample_data`); - cy.waitForLoader(); if (MDSEnabled) { - cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId); + cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); } }); @@ -95,16 +94,17 @@ 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'); cy.visit(`/w/${workspaceId}/app/import_sample_data`); if (MDSEnabled) { - cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId); + cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); } cy.getElementByTestId('removeSampleDataSetecommerce').click(); }); @@ -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( @@ -126,7 +127,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.visit(`/w/${workspaceId}/app/import_sample_data`); if (MDSEnabled) { - cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId); + cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); } cy.getElementByTestId('removeSampleDataSetflights').click(); }); @@ -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( @@ -150,7 +152,7 @@ if (Cypress.env('WORKSPACE_ENABLED')) { cy.visit(`/w/${workspaceId}/app/import_sample_data`); if (MDSEnabled) { - cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId); + cy.selectTopRightNavigationDataSource(dataSourceTitle, dataSourceId); } cy.getElementByTestId('removeSampleDataSetlogs').click(); }); diff --git a/cypress/support/index.js b/cypress/support/index.js index 0033fdce4..c6090f69c 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -19,7 +19,7 @@ // *********************************************************** // Import commands.js using ES2015 syntax: -import '../utils/commands'; +import * as commands from '../utils/commands'; import '../utils/dashboards/commands'; import '../utils/dashboards/datasource-management-dashboards-plugin/commands'; import '../utils/plugins/index-management-dashboards-plugin/commands'; @@ -34,13 +34,13 @@ import '../utils/plugins/notifications-dashboards/commands'; import '../utils/plugins/dashboards-assistant/commands'; import '../utils/dashboards/console/commands'; import '../utils/dashboards/workspace-plugin/commands'; -import { currentBackendEndpoint } from '../utils/commands'; import 'cypress-real-events'; // Alternatively you can use CommonJS syntax: // require('./commands') +const { currentBackendEndpoint } = commands; const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/; Cypress.on('uncaught:exception', (err) => { /* returning false here prevents Cypress from failing the test */ diff --git a/cypress/utils/commands.js b/cypress/utils/commands.js index 77cc341aa..f74983fa3 100644 --- a/cypress/utils/commands.js +++ b/cypress/utils/commands.js @@ -620,6 +620,41 @@ Cypress.Commands.add( } ); +Cypress.Commands.add( + 'selectTopRightNavigationDataSource', + (dataSourceTitle, dataSourceId) => { + cy.getElementByTestId('dataSourceSelectableButton').click(); + cy.getElementByTestId('dataSourceSelectable').find('input').clear(); + cy.getElementByTestId('dataSourceSelectable') + .find('input') + .type(dataSourceTitle); + let dataSourceElement; + if (dataSourceId) { + dataSourceElement = cy.get(`#${dataSourceId}`); + } else if (dataSourceTitle) { + dataSourceElement = cy + .get('.euiSelectableListItem') + .contains(dataSourceTitle) + .closest('.euiSelectableListItem'); + } + + if (dataSourceElement) { + dataSourceElement.then(($element) => { + if ($element.attr('aria-selected') === 'false') { + dataSourceElement.click(); + } else { + // Close data source picker manually if data source already selected + cy.getElementByTestId('dataSourceSelectableButton').click(); + } + }); + } + // Close data source picker manually if no data source element need to be clicked + if (!dataSourceElement) { + cy.getElementByTestId('dataSourceSelectableButton').click(); + } + } +); + Cypress.Commands.add('viewData', (sampleData) => { cy.get(`button[data-test-subj="launchSampleDataSet${sampleData}"]`) .should('be.visible') diff --git a/cypress/utils/dashboards/datasource-management-dashboards-plugin/commands.js b/cypress/utils/dashboards/datasource-management-dashboards-plugin/commands.js index 4cee061de..db0736590 100644 --- a/cypress/utils/dashboards/datasource-management-dashboards-plugin/commands.js +++ b/cypress/utils/dashboards/datasource-management-dashboards-plugin/commands.js @@ -35,29 +35,57 @@ Cypress.Commands.add('deleteAllDataSources', () => { ); }); -Cypress.Commands.add( - 'createDataSourceNoAuth', - ({ title = 'RemoteDataSourceNoAuth' } = {}) => { - cy.request({ +const fetchDataSourceMetadata = (body) => + cy + .request({ method: 'POST', - url: `${BASE_PATH}/api/saved_objects/data-source`, + url: `${BASE_PATH}/internal/data-source-management/fetchDataSourceMetaData`, headers: { 'osd-xsrf': true, }, - body: { - attributes: { - title, - endpoint: Cypress.env('remoteDataSourceNoAuthUrl'), - auth: { - type: 'no_auth', + body, + failOnStatusCode: false, + }) + .then(({ body }) => body); + +Cypress.Commands.add( + 'createDataSourceNoAuth', + ({ title = 'RemoteDataSourceNoAuth' } = {}) => { + const endpoint = Cypress.env('remoteDataSourceNoAuthUrl'); + const createDataSourceNoAuth = (dataSourceMetaData = {}) => { + cy.request({ + method: 'POST', + url: `${BASE_PATH}/api/saved_objects/data-source`, + headers: { + 'osd-xsrf': true, + }, + body: { + attributes: { + title, + endpoint, + auth: { + type: 'no_auth', + }, + ...dataSourceMetaData, }, }, + }).then((resp) => { + if (resp && resp.body && resp.body.id) { + return [resp.body.id, title]; + } + }); + }; + fetchDataSourceMetadata({ + dataSourceAttr: { + endpoint, + auth: { + type: 'no_auth', + }, }, - }).then((resp) => { - if (resp && resp.body && resp.body.id) { - return [resp.body.id, title]; - } - }); + }).then( + (dataSourceMeta) => createDataSourceNoAuth(dataSourceMeta), + () => createDataSourceNoAuth() + ); } ); diff --git a/cypress/utils/dashboards/workspace-plugin/commands.js b/cypress/utils/dashboards/workspace-plugin/commands.js index 4ecf49df1..49cba69d2 100644 --- a/cypress/utils/dashboards/workspace-plugin/commands.js +++ b/cypress/utils/dashboards/workspace-plugin/commands.js @@ -51,6 +51,7 @@ Cypress.Commands.add('createWorkspace', ({ settings, ...workspace } = {}) => { body: { attributes: { ...workspace, + features: workspace.features || ['use-case-observability'], description: workspace.description || 'test_description', }, settings, diff --git a/cypress/utils/plugins/ml-commons-dashboards/commands.js b/cypress/utils/plugins/ml-commons-dashboards/commands.js index 969e93dc8..b08a4660a 100644 --- a/cypress/utils/plugins/ml-commons-dashboards/commands.js +++ b/cypress/utils/plugins/ml-commons-dashboards/commands.js @@ -167,38 +167,3 @@ Cypress.Commands.add('deleteDataSource', (id) => { url: `/api/saved_objects/data-source/${id}`, }); }); - -Cypress.Commands.add( - 'selectTopRightNavigationDataSource', - (dataSourceTitle, dataSourceId) => { - cy.getElementByTestId('dataSourceSelectableButton').click(); - cy.getElementByTestId('dataSourceSelectable').find('input').clear(); - cy.getElementByTestId('dataSourceSelectable') - .find('input') - .type(dataSourceTitle); - let dataSourceElement; - if (dataSourceId) { - dataSourceElement = cy.get(`#${dataSourceId}`); - } else if (dataSourceTitle) { - dataSourceElement = cy - .get('.euiSelectableListItem') - .contains(dataSourceTitle) - .closest('.euiSelectableListItem'); - } - - if (dataSourceElement) { - dataSourceElement.then(($element) => { - if ($element.attr('aria-selected') === 'false') { - dataSourceElement.click(); - } else { - // Close data source picker manually if data source already selected - cy.getElementByTestId('dataSourceSelectableButton').click(); - } - }); - } - // Close data source picker manually if no data source element need to be clicked - if (!dataSourceElement) { - cy.getElementByTestId('dataSourceSelectableButton').click(); - } - } -);