6
6
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library' ;
7
7
import {
8
8
OSD_TEST_DOMAIN_ENDPOINT_URL ,
9
- OSD_INVALID_ENPOINT_URL ,
9
+ OSD_INVALID_ENDPOINT_URL ,
10
10
} from '../../../../utils/dashboards/datasource-management-dashboards-plugin/constants' ;
11
11
12
12
const miscUtils = new MiscUtils ( cy ) ;
@@ -19,11 +19,19 @@ const SECRET_KEY = 'secretKey';
19
19
20
20
if ( Cypress . env ( 'DATASOURCE_MANAGEMENT_ENABLED' ) ) {
21
21
describe ( 'Create datasources' , ( ) => {
22
+ before ( ( ) => {
23
+ // Clean up before creating new data sources for testing
24
+ cy . deleteAllDataSources ( ) ;
25
+ } ) ;
22
26
beforeEach ( ( ) => {
23
27
// Visit OSD create page
24
28
miscUtils . visitPage (
25
29
'app/management/opensearch-dashboards/dataSources/create'
26
30
) ;
31
+
32
+ cy . intercept ( 'POST' , '/api/saved_objects/data-source' ) . as (
33
+ 'createDataSourceRequest'
34
+ ) ;
27
35
} ) ;
28
36
29
37
after ( ( ) => {
@@ -40,20 +48,35 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
40
48
41
49
describe ( 'Datasource can be created successfully' , ( ) => {
42
50
it ( 'with no auth and all required inputs' , ( ) => {
51
+ cy . get ( '[data-test-subj="createDataSourceButton"]' ) . should (
52
+ 'be.disabled'
53
+ ) ;
43
54
cy . get ( '[name="dataSourceTitle"]' ) . type ( 'test_noauth' ) ;
44
55
cy . get ( '[name="endpoint"]' ) . type ( OSD_TEST_DOMAIN_ENDPOINT_URL ) ;
45
56
cy . get ( '[data-test-subj="createDataSourceFormAuthTypeSelect"]' ) . select (
46
57
'no_auth'
47
58
) ;
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
+ ) ;
49
65
66
+ cy . get ( '[data-test-subj="createDataSourceButton"]' ) . click ( ) ;
67
+ cy . wait ( '@createDataSourceRequest' ) . then ( ( interception ) => {
68
+ expect ( interception . response . statusCode ) . to . equal ( 200 ) ;
69
+ } ) ;
50
70
cy . location ( 'pathname' , { timeout : 6000 } ) . should (
51
71
'include' ,
52
72
'app/management/opensearch-dashboards/dataSources'
53
73
) ;
54
74
} ) ;
55
75
56
76
it ( 'with basic auth and all required inputs' , ( ) => {
77
+ cy . get ( '[data-test-subj="createDataSourceButton"]' ) . should (
78
+ 'be.disabled'
79
+ ) ;
57
80
cy . get ( '[name="dataSourceTitle"]' ) . type ( 'test_auth' ) ;
58
81
cy . get ( '[name="endpoint"]' ) . type ( OSD_TEST_DOMAIN_ENDPOINT_URL ) ;
59
82
cy . get ( '[data-test-subj="createDataSourceFormAuthTypeSelect"]' ) . select (
@@ -65,71 +88,93 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
65
88
cy . get ( '[data-test-subj="createDataSourceFormPasswordField"]' ) . type (
66
89
password
67
90
) ;
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
+ } ) ;
70
101
cy . location ( 'pathname' , { timeout : 6000 } ) . should (
71
102
'include' ,
72
103
'app/management/opensearch-dashboards/dataSources'
73
104
) ;
74
105
} ) ;
75
106
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' ) ;
78
112
cy . get ( '[name="endpoint"]' ) . type ( OSD_TEST_DOMAIN_ENDPOINT_URL ) ;
79
113
cy . get ( '[data-test-subj="createDataSourceFormAuthTypeSelect"]' ) . select (
80
114
'sigv4'
81
115
) ;
82
116
cy . get ( '[data-test-subj="createDataSourceFormRegionField"]' ) . type (
83
117
REGION
84
118
) ;
119
+ cy . get (
120
+ '[data-test-subj="createDataSourceFormSigV4ServiceTypeSelect"]'
121
+ ) . select ( 'es' ) ;
85
122
cy . get ( '[data-test-subj="createDataSourceFormAccessKeyField"]' ) . type (
86
123
ACCESS_KEY
87
124
) ;
88
125
cy . get ( '[data-test-subj="createDataSourceFormSecretKeyField"]' ) . type (
89
126
SECRET_KEY
90
127
) ;
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
+ ) ;
91
134
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
+ } ) ;
93
139
94
140
cy . location ( 'pathname' , { timeout : 6000 } ) . should (
95
141
'include' ,
96
142
'app/management/opensearch-dashboards/dataSources'
97
143
) ;
98
144
} ) ;
99
145
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'
104
149
) ;
150
+ cy . get ( '[name="dataSourceTitle"]' ) . type ( 'test_sigv4_aoss' ) ;
105
151
cy . get ( '[name="endpoint"]' ) . type ( OSD_TEST_DOMAIN_ENDPOINT_URL ) ;
106
152
cy . get ( '[data-test-subj="createDataSourceFormAuthTypeSelect"]' ) . select (
107
- 'no_auth '
153
+ 'sigv4 '
108
154
) ;
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
114
157
) ;
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
121
163
) ;
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
125
166
) ;
126
- cy . get ( '[data-test-subj="createDataSourceFormUsernameField "]' ) . type (
127
- username
167
+ cy . get ( '[data-test-subj="createDataSourceButton "]' ) . should (
168
+ 'be.enabled'
128
169
) ;
129
- cy . get ( '[data-test-subj="createDataSourceFormPasswordField "]' ) . type (
130
- password
170
+ cy . get ( '[name="dataSourceDescription "]' ) . type (
171
+ 'cypress test sigV4 data source (Serverless)'
131
172
) ;
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
+ } ) ;
133
178
134
179
cy . location ( 'pathname' , { timeout : 6000 } ) . should (
135
180
'include' ,
@@ -189,7 +234,7 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
189
234
} ) ;
190
235
191
236
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 ( ) ;
193
238
cy . get ( 'input[name="endpoint"]:invalid' ) . should ( 'have.length' , 1 ) ;
194
239
} ) ;
195
240
@@ -269,33 +314,92 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
269
314
} ) ;
270
315
} ) ;
271
316
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' , ( ) => {
274
366
miscUtils . visitPage (
275
367
'app/management/opensearch-dashboards/dataSources/create'
276
368
) ;
277
- cy . getElementByTestId ( 'createDataSourceButton' ) . should ( 'be.disabled' ) ;
369
+ cy . get ( '[data-test-subj="createDataSourceButton"]' ) . should (
370
+ 'be.disabled'
371
+ ) ;
278
372
} ) ;
279
373
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' , ( ) => {
281
375
cy . get ( '[name="dataSourceTitle"]' ) . focus ( ) . blur ( ) ;
282
376
cy . get ( 'input[name="dataSourceTitle"]:invalid' ) . should (
283
377
'have.length' ,
284
378
1
285
379
) ;
286
- cy . getElementByTestId ( 'createDataSourceButton' ) . should ( 'be.disabled' ) ;
380
+ cy . get ( '[data-test-subj="createDataSourceButton"]' ) . should (
381
+ 'be.disabled'
382
+ ) ;
287
383
} ) ;
288
384
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' , ( ) => {
290
386
cy . get ( '[name="dataSourceTitle"]' ) . type ( 'test_create_button' ) ;
291
387
cy . get ( '[name="endpoint"]' ) . type ( OSD_TEST_DOMAIN_ENDPOINT_URL ) ;
292
388
cy . get ( '[data-test-subj="createDataSourceFormAuthTypeSelect"]' ) . select (
293
389
'no_auth'
294
390
) ;
295
- cy . getElementByTestId ( ' createDataSourceButton') . should (
391
+ cy . get ( '[data-test-subj=" createDataSourceButton"] ') . should (
296
392
'not.be.disabled'
297
393
) ;
298
394
} ) ;
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
+ } ) ;
299
403
} ) ;
300
404
} ) ;
301
405
}
0 commit comments