Skip to content

Commit 5824f7c

Browse files
zhongnansugithub-actions[bot]
authored andcommitted
[MD]Update cypress tests for sigV4 & serverless support (#669)
Signed-off-by: Su <[email protected]> (cherry picked from commit 9ebded5)
1 parent 8e9a58a commit 5824f7c

File tree

4 files changed

+303
-43
lines changed

4 files changed

+303
-43
lines changed

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js

+143-39
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
77
import {
88
OSD_TEST_DOMAIN_ENDPOINT_URL,
9-
OSD_INVALID_ENPOINT_URL,
9+
OSD_INVALID_ENDPOINT_URL,
1010
} from '../../../../utils/dashboards/datasource-management-dashboards-plugin/constants';
1111

1212
const miscUtils = new MiscUtils(cy);
@@ -19,11 +19,19 @@ const SECRET_KEY = 'secretKey';
1919

2020
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
2121
describe('Create datasources', () => {
22+
before(() => {
23+
// Clean up before creating new data sources for testing
24+
cy.deleteAllDataSources();
25+
});
2226
beforeEach(() => {
2327
// Visit OSD create page
2428
miscUtils.visitPage(
2529
'app/management/opensearch-dashboards/dataSources/create'
2630
);
31+
32+
cy.intercept('POST', '/api/saved_objects/data-source').as(
33+
'createDataSourceRequest'
34+
);
2735
});
2836

2937
after(() => {
@@ -40,20 +48,35 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
4048

4149
describe('Datasource can be created successfully', () => {
4250
it('with no auth and all required inputs', () => {
51+
cy.get('[data-test-subj="createDataSourceButton"]').should(
52+
'be.disabled'
53+
);
4354
cy.get('[name="dataSourceTitle"]').type('test_noauth');
4455
cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL);
4556
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
4657
'no_auth'
4758
);
48-
cy.getElementByTestId('createDataSourceButton').click();
59+
cy.get('[data-test-subj="createDataSourceButton"]').should(
60+
'be.enabled'
61+
);
62+
cy.get('[name="dataSourceDescription"]').type(
63+
'cypress test no auth data source'
64+
);
4965

66+
cy.get('[data-test-subj="createDataSourceButton"]').click();
67+
cy.wait('@createDataSourceRequest').then((interception) => {
68+
expect(interception.response.statusCode).to.equal(200);
69+
});
5070
cy.location('pathname', { timeout: 6000 }).should(
5171
'include',
5272
'app/management/opensearch-dashboards/dataSources'
5373
);
5474
});
5575

5676
it('with basic auth and all required inputs', () => {
77+
cy.get('[data-test-subj="createDataSourceButton"]').should(
78+
'be.disabled'
79+
);
5780
cy.get('[name="dataSourceTitle"]').type('test_auth');
5881
cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL);
5982
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
@@ -65,71 +88,93 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
6588
cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type(
6689
password
6790
);
68-
cy.getElementByTestId('createDataSourceButton').click();
69-
91+
cy.get('[data-test-subj="createDataSourceButton"]').should(
92+
'be.enabled'
93+
);
94+
cy.get('[name="dataSourceDescription"]').type(
95+
'cypress test basic auth data source'
96+
);
97+
cy.get('[data-test-subj="createDataSourceButton"]').click();
98+
cy.wait('@createDataSourceRequest').then((interception) => {
99+
expect(interception.response.statusCode).to.equal(200);
100+
});
70101
cy.location('pathname', { timeout: 6000 }).should(
71102
'include',
72103
'app/management/opensearch-dashboards/dataSources'
73104
);
74105
});
75106

76-
it('with sigV4 and all required inputs', () => {
77-
cy.get('[name="dataSourceTitle"]').type('test_sigv4');
107+
it('with sigV4 and all required inputs to connect to OpenSearch Service', () => {
108+
cy.get('[data-test-subj="createDataSourceButton"]').should(
109+
'be.disabled'
110+
);
111+
cy.get('[name="dataSourceTitle"]').type('test_sigv4_es');
78112
cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL);
79113
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
80114
'sigv4'
81115
);
82116
cy.get('[data-test-subj="createDataSourceFormRegionField"]').type(
83117
REGION
84118
);
119+
cy.get(
120+
'[data-test-subj="createDataSourceFormSigV4ServiceTypeSelect"]'
121+
).select('es');
85122
cy.get('[data-test-subj="createDataSourceFormAccessKeyField"]').type(
86123
ACCESS_KEY
87124
);
88125
cy.get('[data-test-subj="createDataSourceFormSecretKeyField"]').type(
89126
SECRET_KEY
90127
);
128+
cy.get('[data-test-subj="createDataSourceButton"]').should(
129+
'be.enabled'
130+
);
131+
cy.get('[name="dataSourceDescription"]').type(
132+
'cypress test sigV4 data source'
133+
);
91134

92-
cy.getElementByTestId('createDataSourceButton').click();
135+
cy.get('[data-test-subj="createDataSourceButton"]').click();
136+
cy.wait('@createDataSourceRequest').then((interception) => {
137+
expect(interception.response.statusCode).to.equal(200);
138+
});
93139

94140
cy.location('pathname', { timeout: 6000 }).should(
95141
'include',
96142
'app/management/opensearch-dashboards/dataSources'
97143
);
98144
});
99145

100-
it('with no auth and all inputs', () => {
101-
cy.get('[name="dataSourceTitle"]').type('test_noauth_with_all_Inputs');
102-
cy.get('[name="dataSourceDescription"]').type(
103-
'test if can create datasource with no auth successfully'
146+
it('with sigV4 and all required inputs to connect to OpenSearch Serverless Service', () => {
147+
cy.get('[data-test-subj="createDataSourceButton"]').should(
148+
'be.disabled'
104149
);
150+
cy.get('[name="dataSourceTitle"]').type('test_sigv4_aoss');
105151
cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL);
106152
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
107-
'no_auth'
153+
'sigv4'
108154
);
109-
cy.getElementByTestId('createDataSourceButton').click();
110-
111-
cy.location('pathname', { timeout: 6000 }).should(
112-
'include',
113-
'app/management/opensearch-dashboards/dataSources'
155+
cy.get('[data-test-subj="createDataSourceFormRegionField"]').type(
156+
REGION
114157
);
115-
});
116-
117-
it('with basic auth and all inputs', () => {
118-
cy.get('[name="dataSourceTitle"]').type('test_auth_with_all_Inputs');
119-
cy.get('[name="dataSourceDescription"]').type(
120-
'test if can create datasource with basic auth successfully'
158+
cy.get(
159+
'[data-test-subj="createDataSourceFormSigV4ServiceTypeSelect"]'
160+
).select('aoss');
161+
cy.get('[data-test-subj="createDataSourceFormAccessKeyField"]').type(
162+
ACCESS_KEY
121163
);
122-
cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL);
123-
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
124-
'username_password'
164+
cy.get('[data-test-subj="createDataSourceFormSecretKeyField"]').type(
165+
SECRET_KEY
125166
);
126-
cy.get('[data-test-subj="createDataSourceFormUsernameField"]').type(
127-
username
167+
cy.get('[data-test-subj="createDataSourceButton"]').should(
168+
'be.enabled'
128169
);
129-
cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type(
130-
password
170+
cy.get('[name="dataSourceDescription"]').type(
171+
'cypress test sigV4 data source (Serverless)'
131172
);
132-
cy.getElementByTestId('createDataSourceButton').click();
173+
174+
cy.get('[data-test-subj="createDataSourceButton"]').click();
175+
cy.wait('@createDataSourceRequest').then((interception) => {
176+
expect(interception.response.statusCode).to.equal(200);
177+
});
133178

134179
cy.location('pathname', { timeout: 6000 }).should(
135180
'include',
@@ -189,7 +234,7 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
189234
});
190235

191236
it('validate that endpoint field cannot use invalid format of URL', () => {
192-
cy.get('[name="endpoint"]').type(OSD_INVALID_ENPOINT_URL).blur();
237+
cy.get('[name="endpoint"]').type(OSD_INVALID_ENDPOINT_URL).blur();
193238
cy.get('input[name="endpoint"]:invalid').should('have.length', 1);
194239
});
195240

@@ -269,33 +314,92 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
269314
});
270315
});
271316

272-
describe('Create datasource button', () => {
273-
it('validate if create data source connection button is disabled when first visit this page', () => {
317+
describe('SigV4 AuthType: fields validation', () => {
318+
it('validate that region is a required field', () => {
319+
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
320+
'sigv4'
321+
);
322+
cy.get('[data-test-subj="createDataSourceFormRegionField"]')
323+
.focus()
324+
.blur();
325+
cy.get(
326+
'input[data-test-subj="createDataSourceFormRegionField"]:invalid'
327+
).should('have.length', 1);
328+
});
329+
330+
it('validate that accessKey is a required field', () => {
331+
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
332+
'sigv4'
333+
);
334+
cy.get('[data-test-subj="createDataSourceFormAccessKeyField"]')
335+
.focus()
336+
.blur();
337+
cy.get(
338+
'input[data-test-subj="createDataSourceFormAccessKeyField"]:invalid'
339+
).should('have.length', 1);
340+
});
341+
342+
it('validate that secretKey is a required field', () => {
343+
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
344+
'sigv4'
345+
);
346+
cy.get('[data-test-subj="createDataSourceFormSecretKeyField"]')
347+
.focus()
348+
.blur();
349+
cy.get(
350+
'input[data-test-subj="createDataSourceFormSecretKeyField"]:invalid'
351+
).should('have.length', 1);
352+
});
353+
354+
it('validate that serviceName is a required field, and with default option rendered', () => {
355+
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
356+
'sigv4'
357+
);
358+
cy.get(
359+
'[data-test-subj="createDataSourceFormSigV4ServiceTypeSelect"]'
360+
).should('have.value', 'es');
361+
});
362+
});
363+
364+
describe('Cancel button and create data source button', () => {
365+
it('validate if create data source button is disabled when first visit this page', () => {
274366
miscUtils.visitPage(
275367
'app/management/opensearch-dashboards/dataSources/create'
276368
);
277-
cy.getElementByTestId('createDataSourceButton').should('be.disabled');
369+
cy.get('[data-test-subj="createDataSourceButton"]').should(
370+
'be.disabled'
371+
);
278372
});
279373

280-
it('validate if create data source connection button is disabled when there is any field error', () => {
374+
it('validate if create data source button is disabled when there is any field error', () => {
281375
cy.get('[name="dataSourceTitle"]').focus().blur();
282376
cy.get('input[name="dataSourceTitle"]:invalid').should(
283377
'have.length',
284378
1
285379
);
286-
cy.getElementByTestId('createDataSourceButton').should('be.disabled');
380+
cy.get('[data-test-subj="createDataSourceButton"]').should(
381+
'be.disabled'
382+
);
287383
});
288384

289-
it('validate if create data source connection button is not disabled only if there is no any field error', () => {
385+
it('validate if create data source button is not disabled only if there is no any field error', () => {
290386
cy.get('[name="dataSourceTitle"]').type('test_create_button');
291387
cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL);
292388
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
293389
'no_auth'
294390
);
295-
cy.getElementByTestId('createDataSourceButton').should(
391+
cy.get('[data-test-subj="createDataSourceButton"]').should(
296392
'not.be.disabled'
297393
);
298394
});
395+
396+
it('cancel button should redirect to datasource listing page', () => {
397+
cy.get('[data-test-subj="cancelCreateDataSourceButton"]').click();
398+
cy.location('pathname', { timeout: 6000 }).should(
399+
'include',
400+
'app/management/opensearch-dashboards/dataSources'
401+
);
402+
});
299403
});
300404
});
301405
}

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { TIMEOUT_OPTS } from '../../../../utils/dashboards/datasource-management-dashboards-plugin/constants';
6+
import {
7+
TIMEOUT_OPTS,
8+
OSD_TEST_DOMAIN_ENDPOINT_URL,
9+
} from '../../../../utils/dashboards/datasource-management-dashboards-plugin/constants';
710

811
const searchFieldIdentifier = 'input[type="search"]';
912
const tableHeadIdentifier = 'thead > tr > th';
@@ -49,7 +52,7 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
4952
attributes: {
5053
title: `ds_${char}`,
5154
description: `test ds_description_${char}`,
52-
endpoint: `https://dummy${char}`,
55+
endpoint: `${OSD_TEST_DOMAIN_ENDPOINT_URL}/${char}`,
5356
auth: {
5457
type: i % 2 ? 'username_password' : 'no_auth',
5558
},

0 commit comments

Comments
 (0)