-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ec235ed
commit 6e9bca1
Showing
2 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
251 changes: 251 additions & 0 deletions
251
...dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; | ||
import { | ||
OSD_TEST_DOMAIN_ENDPOINT_URL, | ||
OSD_INVALID_ENPOINT_URL, | ||
} from '../../../../utils/dashboards/datasource-management-dashboards-plugin/cosntants'; | ||
|
||
const miscUtils = new MiscUtils(cy); | ||
// Get environment variables | ||
const username = Cypress.env('username'); | ||
const password = Cypress.env('password'); | ||
|
||
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { | ||
describe('Create datasources', () => { | ||
beforeEach(() => { | ||
// Visit OSD create page | ||
miscUtils.visitPage( | ||
'app/management/opensearch-dashboards/dataSources/create' | ||
); | ||
}); | ||
|
||
it('should successfully load the page', () => { | ||
cy.contains( | ||
'Create a new data source connection to help you retrieve data from an external OpenSearch compatible source.', | ||
{ timeout: 60000 } | ||
); | ||
}); | ||
|
||
it('should successfully show the experimental feature callout', () => { | ||
cy.get('[data-test-subj="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.location('pathname', { timeout: 6000 }).should( | ||
'include', | ||
'app/management/opensearch-dashboards/dataSources' | ||
); | ||
}); | ||
|
||
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="createDataSourceFormUsernameField"]').type( | ||
username | ||
); | ||
cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type( | ||
password | ||
); | ||
cy.get('[type="submit"]').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('[type="submit"]').click(); | ||
|
||
cy.location('pathname', { timeout: 6000 }).should( | ||
'include', | ||
'app/management/opensearch-dashboards/dataSources' | ||
); | ||
}); | ||
|
||
it('with basic auth and all inputs', () => { | ||
cy.get('[name="dataSourceTitle"]').type('test_auth_with_all_Inputs'); | ||
cy.get('[name="dataSourceDescription"]').type( | ||
'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="createDataSourceFormUsernameField"]').type( | ||
username | ||
); | ||
cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type( | ||
password | ||
); | ||
cy.get('[type="submit"]').click(); | ||
|
||
cy.location('pathname', { timeout: 6000 }).should( | ||
'include', | ||
'app/management/opensearch-dashboards/dataSources' | ||
); | ||
}); | ||
}); | ||
|
||
describe('Title validation', () => { | ||
it('validate that title is a required field', () => { | ||
cy.get('[name="dataSourceTitle"]').focus().blur(); | ||
cy.get('input[name="dataSourceTitle"]:invalid').should( | ||
'have.length', | ||
1 | ||
); | ||
}); | ||
|
||
it('validate that title cannot use existing datasource name', () => { | ||
cy.get('[name="dataSourceTitle"]').type('test_auth').blur(); | ||
cy.get('input[name="dataSourceTitle"]:invalid').should( | ||
'have.length', | ||
1 | ||
); | ||
cy.contains('This title is already in use').should('exist'); | ||
}); | ||
|
||
it('validate that title field does not show any error if title is valid and unique', () => { | ||
cy.get('[name="dataSourceTitle"]').type('test_unique_title').blur(); | ||
cy.get('input[name="dataSourceTitle"]:valid').should('have.length', 1); | ||
}); | ||
}); | ||
|
||
describe('Description validation', () => { | ||
it('validate that description field does not show any error if the field is empty', () => { | ||
cy.get('[name="dataSourceDescription"]').focus().blur(); | ||
cy.get('input[name="dataSourceDescription"]:valid').should( | ||
'have.length', | ||
1 | ||
); | ||
}); | ||
|
||
it('validate that description field does not show any error if there is a description', () => { | ||
cy.get('[name="dataSourceDescription"]') | ||
.type('test description field') | ||
.blur(); | ||
cy.get('input[name="dataSourceDescription"]:valid').should( | ||
'have.length', | ||
1 | ||
); | ||
}); | ||
}); | ||
|
||
describe('Endpoint validation', () => { | ||
it('validate that endpoint is a required field', () => { | ||
cy.get('[name="endpoint"]').focus().blur(); | ||
cy.get('input[name="endpoint"]:invalid').should('have.length', 1); | ||
}); | ||
|
||
it('validate that endpoint field cannot use invalid format of URL', () => { | ||
cy.get('[name="endpoint"]').type(OSD_INVALID_ENPOINT_URL).blur(); | ||
cy.get('input[name="endpoint"]:invalid').should('have.length', 1); | ||
}); | ||
|
||
it('validate that endpoint field does not show any error if URL is valid', () => { | ||
cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL).blur(); | ||
cy.get('input[name="endpoint"]:valid').should('have.length', 1); | ||
}); | ||
}); | ||
|
||
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="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="createDataSourceFormUsernameField"]') | ||
.focus() | ||
.blur(); | ||
cy.get( | ||
'input[data-test-subj="createDataSourceFormUsernameField"]:invalid' | ||
).should('have.length', 1); | ||
}); | ||
|
||
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="createDataSourceFormUsernameField"]') | ||
.type(username) | ||
.blur(); | ||
cy.get( | ||
'input[data-test-subj="createDataSourceFormUsernameField"]:valid' | ||
).should('have.length', 1); | ||
}); | ||
}); | ||
|
||
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="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="createDataSourceFormPasswordField"]') | ||
.focus() | ||
.blur(); | ||
cy.get( | ||
'input[data-test-subj="createDataSourceFormPasswordField"]:invalid' | ||
).should('have.length', 1); | ||
}); | ||
|
||
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="createDataSourceFormPasswordField"]') | ||
.type(password) | ||
.blur(); | ||
cy.get( | ||
'input[data-test-subj="createDataSourceFormPasswordField"]:valid' | ||
).should('have.length', 1); | ||
}); | ||
}); | ||
|
||
describe('Create datasource button', () => { | ||
it('validate if create data source connection button is disabled when first visit this page', () => { | ||
miscUtils.visitPage( | ||
'app/management/opensearch-dashboards/dataSources/create' | ||
); | ||
cy.get('[type="submit"]').should('be.disabled'); | ||
}); | ||
|
||
it('validate if create data source connection button is disabled when there is any field error', () => { | ||
cy.get('[name="dataSourceTitle"]').focus().blur(); | ||
cy.get('input[name="dataSourceTitle"]:invalid').should( | ||
'have.length', | ||
1 | ||
); | ||
cy.get('[type="submit"]').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'); | ||
}); | ||
}); | ||
}); | ||
} |
16 changes: 16 additions & 0 deletions
16
cypress/utils/dashboards/datasource-management-dashboards-plugin/cosntants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const DS_API_PREFIX = '/api/saved_objects'; | ||
|
||
export const DS_API = { | ||
DATA_SOURCES_LISTING: `${DS_API_PREFIX}/_find?fields=id&fields=description&fields=title&per_page=10000&type=data-source`, | ||
CREATE_DATA_SOURCE: `${DS_API_PREFIX}/data-source`, | ||
DELETE_DATA_SOURCE: `${DS_API_PREFIX}/data-source/`, | ||
}; | ||
|
||
export const OSD_TEST_DOMAIN_ENDPOINT_URL = 'https://test'; | ||
|
||
export const OSD_INVALID_ENPOINT_URL = 'test'; |