From 821528ea9e001c57c93765aa70ad159fcc7c8664 Mon Sep 17 00:00:00 2001 From: Zhongnan Su Date: Wed, 12 Apr 2023 14:09:47 -0700 Subject: [PATCH 1/2] [Multiple Datasource] Update tests for 2.7 (#610) Signed-off-by: Su (cherry picked from commit 9f890f794f1937615ee97e2dc550f5c723430c18) Signed-off-by: Yibo Wang --- .../1_create_datasource.spec.js | 93 ++++++++++++++----- .../2_datasource_table.spec.js | 5 - .../3_update_datasource.spec.js | 80 ++++++++++++---- 3 files changed, 133 insertions(+), 45 deletions(-) diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js index 830445087..452ea8cdd 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js @@ -13,6 +13,9 @@ const miscUtils = new MiscUtils(cy); // Get environment variables const username = Cypress.env('username'); const password = Cypress.env('password'); +const REGION = 'us-east-1'; +const ACCESS_KEY = 'accessKey'; +const SECRET_KEY = 'secretKey'; if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { describe('Create datasources', () => { @@ -35,16 +38,14 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { ); }); - it('should successfully show the experimental feature callout', () => { - cy.getElementByTestId('data-source-experimental-call').should('exist'); - }); - describe('Datasource can be created successfully', () => { it('with no auth and all required inputs', () => { cy.get('[name="dataSourceTitle"]').type('test_noauth'); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); - cy.get('[for="no_auth"]').click(); - cy.get('[type="submit"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'no_auth' + ); + cy.getElementByTestId('createDataSourceButton').click(); cy.location('pathname', { timeout: 6000 }).should( 'include', @@ -55,14 +56,40 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { it('with basic auth and all required inputs', () => { cy.get('[name="dataSourceTitle"]').type('test_auth'); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); - cy.get('[for="username_password"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'username_password' + ); cy.get('[data-test-subj="createDataSourceFormUsernameField"]').type( username ); cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type( password ); - cy.get('[type="submit"]').click(); + cy.getElementByTestId('createDataSourceButton').click(); + + cy.location('pathname', { timeout: 6000 }).should( + 'include', + 'app/management/opensearch-dashboards/dataSources' + ); + }); + + it('with sigV4 and all required inputs', () => { + cy.get('[name="dataSourceTitle"]').type('test_sigv4'); + cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'sigv4' + ); + cy.get('[data-test-subj="createDataSourceFormRegionField"]').type( + REGION + ); + cy.get('[data-test-subj="createDataSourceFormAccessKeyField"]').type( + ACCESS_KEY + ); + cy.get('[data-test-subj="createDataSourceFormSecretKeyField"]').type( + SECRET_KEY + ); + + cy.getElementByTestId('createDataSourceButton').click(); cy.location('pathname', { timeout: 6000 }).should( 'include', @@ -76,8 +103,10 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { 'test if can create datasource with no auth successfully' ); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); - cy.get('[for="no_auth"]').click(); - cy.get('[type="submit"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'no_auth' + ); + cy.getElementByTestId('createDataSourceButton').click(); cy.location('pathname', { timeout: 6000 }).should( 'include', @@ -91,14 +120,16 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { 'test if can create datasource with basic auth successfully' ); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); - cy.get('[for="username_password"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'username_password' + ); cy.get('[data-test-subj="createDataSourceFormUsernameField"]').type( username ); cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type( password ); - cy.get('[type="submit"]').click(); + cy.getElementByTestId('createDataSourceButton').click(); cy.location('pathname', { timeout: 6000 }).should( 'include', @@ -170,14 +201,18 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { describe('Username validation', () => { it('validate that username field does not show when auth type is no auth', () => { - cy.get('[for="no_auth"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'no_auth' + ); cy.get('[data-test-subj="createDataSourceFormUsernameField"]').should( 'not.exist' ); }); it('validate that username is a required field when auth type is username & password', () => { - cy.get('[for="username_password"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'username_password' + ); cy.get('[data-test-subj="createDataSourceFormUsernameField"]') .focus() .blur(); @@ -187,7 +222,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('validate that username field does not show any error when auth type is username & password and field is not empty', () => { - cy.get('[for="username_password"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'username_password' + ); cy.get('[data-test-subj="createDataSourceFormUsernameField"]') .type(username) .blur(); @@ -199,14 +236,18 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { describe('Password validation', () => { it('validate that password field does not show when auth type is no auth', () => { - cy.get('[for="no_auth"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'no_auth' + ); cy.get('[data-test-subj="createDataSourceFormPasswordField"]').should( 'not.exist' ); }); it('validate that password is a required field when auth type is username & password', () => { - cy.get('[for="username_password"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'username_password' + ); cy.get('[data-test-subj="createDataSourceFormPasswordField"]') .focus() .blur(); @@ -216,7 +257,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('validate that password field does not show any error when auth type is username & password and field is not empty', () => { - cy.get('[for="username_password"]').click(); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'username_password' + ); cy.get('[data-test-subj="createDataSourceFormPasswordField"]') .type(password) .blur(); @@ -231,7 +274,7 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { miscUtils.visitPage( 'app/management/opensearch-dashboards/dataSources/create' ); - cy.get('[type="submit"]').should('be.disabled'); + cy.getElementByTestId('createDataSourceButton').should('be.disabled'); }); it('validate if create data source connection button is disabled when there is any field error', () => { @@ -240,15 +283,19 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { 'have.length', 1 ); - cy.get('[type="submit"]').should('be.disabled'); + cy.getElementByTestId('createDataSourceButton').should('be.disabled'); }); it('validate if create data source connection button is not disabled only if there is no any field error', () => { cy.get('[name="dataSourceTitle"]').type('test_create_button'); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); - cy.get('[for="no_auth"]').click(); - cy.get('[type="submit"]').should('not.be.disabled'); + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'no_auth' + ); + cy.getElementByTestId('createDataSourceButton').should( + 'not.be.disabled' + ); }); }); }); -} +} \ No newline at end of file diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js index 157ffdf9f..aec4e6deb 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js @@ -27,11 +27,6 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { ); }); - /* Experimental Callout */ - it('should display experimental call out', () => { - cy.getElementByTestId('data-source-experimental-call').should('exist'); - }); - describe('Empty State', () => { before(() => { // Clean up table before other tests run diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/3_update_datasource.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/3_update_datasource.spec.js index 27f575ea2..d37e6a22f 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/3_update_datasource.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/3_update_datasource.spec.js @@ -152,7 +152,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('should make sure that endpoint field is disabled in all scenarios', () => { // credential: Username & password - cy.get('[type="radio"]').last().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'username_password' + ); cy.get('input[name="endpoint"]').should('be.disabled'); cy.get('input[name="endpoint"]').should( 'have.value', @@ -160,7 +162,19 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { ); // credential: No Authentication - cy.get('[type="radio"]').first().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'no_auth' + ); + cy.get('input[name="endpoint"]').should('be.disabled'); + cy.get('input[name="endpoint"]').should( + 'have.value', + DS_JSON.attributes.endpoint + ); + + // credential: sigv4 + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'sigv4' + ); cy.get('input[name="endpoint"]').should('be.disabled'); cy.get('input[name="endpoint"]').should( 'have.value', @@ -169,7 +183,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('should make sure that username field is required for credential: Username & password & hidden when credential: No Authentication', () => { // credential: Username & password - cy.get('[type="radio"]').last().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'username_password' + ); cy.get('input[name="datasourceUsername"]').should('exist'); cy.get('input[name="datasourceUsername"]').should('be.empty'); @@ -192,12 +208,16 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { ); // credential: No Authentication - cy.get('[type="radio"]').first().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'no_auth' + ); cy.get('input[name="datasourceUsername"]').should('not.exist'); }); it('should make sure that password field is required', () => { // credential: Username & password - cy.get('[type="radio"]').last().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'username_password' + ); cy.getElementByTestId('editDatasourceUpdatePasswordBtn').should( 'not.exist' ); @@ -217,7 +237,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { cy.get('input[type="password"]:valid').should('have.length', 1); // credential: No Authentication - cy.get('[type="radio"]').first().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'no_auth' + ); cy.get(passwordFieldIdentifier).should('not.exist'); }); }); @@ -247,7 +269,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('should change credential to "Username & Password" & save changes with valid form', () => { // credential: Username & password - cy.get('[type="radio"]').last().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'username_password' + ); // set username typeInInputFieldAndBlur( 'datasourceUsername', @@ -269,7 +293,11 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { ).should('not.exist'); }); it('should verify that changes were updated successfully', () => { - cy.get('[type="radio"]').last().should('be.checked'); // credential: Username & password + // credential: Username & password + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').should( + 'have.value', + 'username_password' + ); cy.get('[name="datasourceUsername"]').should( 'have.value', DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.username @@ -340,7 +368,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('should make sure that endpoint field is disabled in all scenarios', () => { // credential: No Authentication - cy.get('[type="radio"]').first().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'no_auth' + ); cy.get('input[name="endpoint"]').should('be.disabled'); cy.get('input[name="endpoint"]').should( 'have.value', @@ -348,7 +378,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { ); // credential: Username & password - cy.get('[type="radio"]').last().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'username_password' + ); cy.get('input[name="endpoint"]').should('be.disabled'); cy.get('input[name="endpoint"]').should( 'have.value', @@ -358,11 +390,15 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { it('should make sure that username field is hidden when credential: No Authentication & required for credential: Username & password', () => { // credential: No Authentication - cy.get('[type="radio"]').first().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'no_auth' + ); cy.get('input[name="datasourceUsername"]').should('not.exist'); // credential: Username & password - cy.get('[type="radio"]').last().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'username_password' + ); cy.get('input[name="datasourceUsername"]').should('exist'); cy.get('input[name="datasourceUsername"]').should( 'have.value', @@ -389,14 +425,18 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('should make sure that password field is disabled & Update stored password button is present', () => { // credential: No Authentication - cy.get('[type="radio"]').first().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'no_auth' + ); cy.get(passwordFieldIdentifier).should('not.exist'); cy.getElementByTestId('editDatasourceUpdatePasswordBtn').should( 'not.exist' // Update stored password button ); // credential: Username & password - cy.get('[type="radio"]').last().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'username_password' + ); cy.getElementByTestId('editDatasourceUpdatePasswordBtn').should( 'exist' // Update stored password button ); @@ -499,7 +539,7 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.password ); }); - it('should save valid updated stored passwoprd', () => { + it('should save valid updated stored password', () => { typeInInputFieldAndBlur( '', DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.password, @@ -525,7 +565,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { describe('bottom bar: Save Changes -> "Change Credential Type & few fields"', () => { it('should change credential to "No Authentication" & save changes with valid form', () => { // credential: No Authentication - cy.get('[type="radio"]').first().check(FORCE_CLICK_OPTS); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'no_auth' + ); typeInInputFieldAndBlur( 'dataSourceTitle', DS_JSON_UNIQUE_VALUES.attributes.title, @@ -544,7 +586,11 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { 'have.value', DS_JSON_UNIQUE_VALUES.attributes.title ); - cy.get('[type="radio"]').first().should('be.checked'); // credential: Username & password + // credential: No Authentication + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').should( + 'have.value', + 'no_auth' + ); cy.get('[name="datasourceUsername"]').should('not.exist'); cy.get(passwordFieldIdentifier).should('not.exist'); cy.getElementByTestId('editDatasourceUpdatePasswordBtn').should( From b7be2f647bf6882b2406b1ab6b9e83f8c814e1e0 Mon Sep 17 00:00:00 2001 From: Yibo Wang Date: Sun, 16 Apr 2023 17:41:52 -0700 Subject: [PATCH 2/2] lint check fix Signed-off-by: Yibo Wang --- .../datasource-management-plugin/1_create_datasource.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js index 452ea8cdd..e0228bf28 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js @@ -298,4 +298,4 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); }); }); -} \ No newline at end of file +}