Skip to content

Commit

Permalink
[Multiple Datasource] Update tests for 2.7 (#610)
Browse files Browse the repository at this point in the history
Signed-off-by: Su <szhongna@amazon.com>
  • Loading branch information
zhongnansu authored Apr 12, 2023
1 parent 59e486a commit 9f890f7
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ENDPOINT_WITH_PROXY": false,
"MANAGED_SERVICE_ENDPOINT": false,
"VISBUILDER_ENABLED": true,
"DATASOURCE_MANAGEMENT_ENABLED": false,
"DATASOURCE_MANAGEMENT_ENABLED": true,
"ML_COMMONS_DASHBOARDS_ENABLED": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -35,15 +38,13 @@ 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('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
'no_auth'
);
cy.getElementByTestId('createDataSourceButton').click();

cy.location('pathname', { timeout: 6000 }).should(
Expand All @@ -55,7 +56,9 @@ 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
);
Expand All @@ -70,13 +73,39 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
);
});

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',
'app/management/opensearch-dashboards/dataSources'
);
});

it('with no auth and all inputs', () => {
cy.get('[name="dataSourceTitle"]').type('test_noauth_with_all_Inputs');
cy.get('[name="dataSourceDescription"]').type(
'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('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
'no_auth'
);
cy.getElementByTestId('createDataSourceButton').click();

cy.location('pathname', { timeout: 6000 }).should(
Expand All @@ -91,7 +120,9 @@ 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
);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -246,7 +289,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
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('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
'no_auth'
);
cy.getElementByTestId('createDataSourceButton').should(
'not.be.disabled'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,29 @@ 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',
DS_JSON.attributes.endpoint
);

// 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',
Expand All @@ -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');

Expand All @@ -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'
);
Expand All @@ -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');
});
});
Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -340,15 +368,19 @@ 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',
DS_JSON.attributes.endpoint
);

// 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',
Expand All @@ -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',
Expand All @@ -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
);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 9f890f7

Please sign in to comment.