@@ -14,13 +14,32 @@ const textConstants = {
14
14
toolbarEditNamespace : 'Edit this Namespace' ,
15
15
toolbarRemoveNamespace : 'Remove this Namespace' ,
16
16
17
+ // Common selectors
18
+ inputFieldSelector : ( inputId ) =>
19
+ `#main-content #datastore-form-wrapper input#${ inputId } ` ,
20
+ buttonSelector : ( type ) => `#main-content .bx--btn-set button[type="${ type } "]` ,
21
+ inputFieldLabelSelector : ( forValue ) =>
22
+ `#main-content #datastore-form-wrapper label[for="${ forValue } "]` ,
23
+
24
+ // Element ids
25
+ nameInputFieldId : 'name' ,
26
+ descriptionInputFieldId : 'description' ,
27
+ namespacePathInputFieldId : 'namespacePath' ,
28
+
29
+ // Button types
30
+ submitButtonType : 'submit' ,
31
+ normalButtonType : 'button' ,
32
+
17
33
// Field values
18
34
domainName : 'Test_Domain' ,
19
35
description : 'Test description' ,
20
36
namespaceName : 'Test_Namespace' ,
21
37
editedNamespaceName : 'Test_Namespace_Edited' ,
22
38
editedDescription : 'Test description edited' ,
23
39
invalidNamespaceName : 'Test Namespace' ,
40
+ addNamespaceFormHeader : 'Adding a new Automate Namespace' ,
41
+ editNamespaceFormHeader : 'Editing Automate Namespace' ,
42
+ namespaceFormSubHeader : 'Info' ,
24
43
25
44
// List items
26
45
dataStoreAccordionItem : 'Datastore' ,
@@ -39,7 +58,7 @@ const textConstants = {
39
58
// Flash message text snippets
40
59
flashMessageAddSuccess : 'added' ,
41
60
flashMessageSaveSuccess : 'saved' ,
42
- flashMessageCancelled : 'cancelled ' ,
61
+ flashMessageCancelled : 'cancel ' ,
43
62
flashMessageInvalidNamespace : 'contain only alphanumeric' ,
44
63
flashMessageNamespaceRemoved : 'delete successful' ,
45
64
flashMessageNameAlreadyExists : 'taken' ,
@@ -51,6 +70,10 @@ const {
51
70
automationMenuOption,
52
71
embeddedAutomationMenuOption,
53
72
explorerMenuOption,
73
+ inputFieldSelector,
74
+ buttonSelector,
75
+ normalButtonSelector,
76
+ inputFieldLabelSelector,
54
77
addButton,
55
78
cancelButton,
56
79
resetButton,
@@ -63,6 +86,9 @@ const {
63
86
toolbarEditNamespace,
64
87
toolbarRemoveNamespace,
65
88
toolbarRemoveDomain,
89
+ addNamespaceFormHeader,
90
+ editNamespaceFormHeader,
91
+ namespaceFormSubHeader,
66
92
namespaceName,
67
93
editedNamespaceName,
68
94
editedDescription,
@@ -79,21 +105,24 @@ const {
79
105
flashMessageResetNamespace,
80
106
browserConfirmRemoveMessage,
81
107
dataStoreAccordionItem,
108
+ nameInputFieldId,
109
+ descriptionInputFieldId,
110
+ namespacePathInputFieldId,
111
+ submitButtonType,
112
+ normalButtonType,
82
113
} = textConstants ;
83
114
84
115
function addNamespace ( nameFieldValue = namespaceName ) {
85
116
// Navigating to the Add Namespace form
86
117
cy . toolbar ( toolbarConfiguration , toolbarAddNewNamespace ) ;
87
118
// Creating a new namespace
88
- cy . get ( '#datastore-form-wrapper input#name' ) . type ( nameFieldValue ) ;
89
- cy . get ( '#datastore-form-wrapper input#description' ) . type ( description ) ;
90
- cy . get ( '#main-content .bx--btn-set button[type="submit"]' )
91
- . contains ( addButton )
92
- . click ( ) ;
119
+ cy . get ( inputFieldSelector ( nameInputFieldId ) ) . type ( nameFieldValue ) ;
120
+ cy . get ( inputFieldSelector ( descriptionInputFieldId ) ) . type ( description ) ;
121
+ cy . contains ( buttonSelector ( submitButtonType ) , addButton ) . click ( ) ;
93
122
cy . wait ( '@addNamespaceApi' ) ;
94
123
}
95
124
96
- function interceptAccordionApi ( textValue = namespaceName ) {
125
+ function selectAccordionTree ( textValue ) {
97
126
const aliasObject = {
98
127
[ domainName ] : 'getCreatedDomainInfo' ,
99
128
[ namespaceName ] : 'getCreatedNamespaceInfo' ,
@@ -107,6 +136,63 @@ function interceptAccordionApi(textValue = namespaceName) {
107
136
cy . wait ( `@${ aliasObject [ textValue ] } ` ) ;
108
137
}
109
138
139
+ function validateNamespaceFormFields ( isEditForm = false ) {
140
+ // Validate form header visibility
141
+ cy . expect_explorer_title (
142
+ isEditForm
143
+ ? `${ editNamespaceFormHeader } "${ namespaceName } "`
144
+ : addNamespaceFormHeader
145
+ ) ;
146
+ // Validate sub header visibility
147
+ cy . get ( '#main-content #datastore-form-wrapper h3' ) . contains (
148
+ namespaceFormSubHeader
149
+ ) ;
150
+ // Validate name-space path field visibility
151
+ cy . get ( inputFieldLabelSelector ( namespacePathInputFieldId ) ) . should (
152
+ 'be.visible'
153
+ ) ;
154
+ cy . get ( inputFieldSelector ( namespacePathInputFieldId ) )
155
+ . should ( 'be.visible' )
156
+ . and ( 'be.disabled' )
157
+ . and (
158
+ 'have.value' ,
159
+ isEditForm ? `/${ domainName } /${ namespaceName } ` : `/${ domainName } `
160
+ ) ;
161
+ // Validate name field visibility
162
+ cy . get ( inputFieldLabelSelector ( nameInputFieldId ) ) . should ( 'be.visible' ) ;
163
+ cy . get ( inputFieldSelector ( nameInputFieldId ) )
164
+ . should ( 'be.visible' )
165
+ . and ( 'be.enabled' ) ;
166
+ // Validate description field visibility
167
+ cy . get ( inputFieldLabelSelector ( descriptionInputFieldId ) ) . should ( 'be.visible' ) ;
168
+ cy . get ( inputFieldSelector ( descriptionInputFieldId ) )
169
+ . should ( 'be.visible' )
170
+ . and ( 'be.enabled' ) ;
171
+ // Validate cancel button visibility
172
+ cy . get ( buttonSelector ( normalButtonType ) )
173
+ . contains ( cancelButton )
174
+ . should ( 'be.visible' ) ;
175
+ // Validate add/save button visibility
176
+ cy . get ( buttonSelector ( submitButtonType ) )
177
+ . contains ( isEditForm ? saveButton : addButton )
178
+ . should ( 'be.visible' ) ;
179
+ if ( isEditForm ) {
180
+ // Validate reset button visibility
181
+ cy . get ( buttonSelector ( normalButtonType ) )
182
+ . contains ( resetButton )
183
+ . should ( 'be.visible' ) ;
184
+ }
185
+ }
186
+
187
+ function createNamespaceAndOpenEditForm ( ) {
188
+ // Adding a new namespace
189
+ addNamespace ( ) ;
190
+ // Selecting the created namespace from the accordion list items
191
+ selectAccordionTree ( namespaceName ) ;
192
+ // Opening the edit form
193
+ cy . toolbar ( toolbarConfiguration , toolbarEditNamespace ) ;
194
+ }
195
+
110
196
describe ( 'Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form' , ( ) => {
111
197
beforeEach ( ( ) => {
112
198
cy . login ( ) ;
@@ -117,25 +203,35 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
117
203
) ;
118
204
// Creating a domain to test namespace operations
119
205
cy . toolbar ( toolbarConfiguration , toolbarAddNewDomain ) ;
120
- cy . get ( '#datastore-form-wrapper input#name' ) . type ( domainName ) ;
121
- cy . get ( '#datastore-form-wrapper input#description' ) . type ( description ) ;
206
+ cy . get ( inputFieldSelector ( nameInputFieldId ) ) . type ( domainName ) ;
207
+ cy . get ( inputFieldSelector ( descriptionInputFieldId ) ) . type ( description ) ;
122
208
cy . intercept ( 'POST' , '/miq_ae_class/create_namespace/new?button=add' ) . as (
123
209
'addNamespaceApi'
124
210
) ;
125
- cy . get ( '#main-content .bx--btn-set button[type="submit"]' )
126
- . contains ( addButton )
127
- . click ( ) ;
211
+ cy . contains ( buttonSelector ( submitButtonType ) , addButton ) . click ( ) ;
128
212
cy . wait ( '@addNamespaceApi' ) ;
129
213
cy . expect_flash ( flashTypeSuccess , flashMessageAddSuccess ) ;
130
214
// Selecting the created domain from the accordion list items
131
- interceptAccordionApi ( domainName ) ;
215
+ selectAccordionTree ( domainName ) ;
216
+ } ) ;
217
+
218
+ it ( 'Validate Add Namespace form fields' , ( ) => {
219
+ // Navigating to the Add Namespace form
220
+ cy . toolbar ( toolbarConfiguration , toolbarAddNewNamespace ) ;
221
+
222
+ // Validating the form fields
223
+ validateNamespaceFormFields ( ) ;
224
+
225
+ // Cancelling the form
226
+ cy . contains ( buttonSelector ( normalButtonType ) , cancelButton ) . click ( ) ;
132
227
} ) ;
133
228
134
229
it ( 'Validate Cancel button' , ( ) => {
230
+ // Navigating to the Add Namespace form
135
231
cy . toolbar ( toolbarConfiguration , toolbarAddNewNamespace ) ;
232
+
136
233
// Cancelling the form
137
- cy . get ( '#main-content .bx--btn-set button[type="button"]' )
138
- . contains ( cancelButton )
234
+ cy . contains ( buttonSelector ( normalButtonType ) , cancelButton )
139
235
. should ( 'be.enabled' )
140
236
. click ( ) ;
141
237
cy . expect_flash ( flashTypeWarning , flashMessageCancelled ) ;
@@ -145,10 +241,20 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
145
241
// Trying to add a namespace with invalid characters
146
242
addNamespace ( invalidNamespaceName ) ;
147
243
cy . expect_flash ( flashTypeError , flashMessageInvalidNamespace ) ;
244
+
148
245
// Cancelling the form
149
- cy . get ( '#main-content .bx--btn-set button[type="button"]' )
150
- . contains ( cancelButton )
151
- . click ( ) ;
246
+ cy . contains ( buttonSelector ( normalButtonType ) , cancelButton ) . click ( ) ;
247
+ } ) ;
248
+
249
+ it ( 'Validate Edit Namespace form fields' , ( ) => {
250
+ // Create a namespace and open the edit form
251
+ createNamespaceAndOpenEditForm ( ) ;
252
+
253
+ // Validating the form fields
254
+ validateNamespaceFormFields ( true ) ;
255
+
256
+ // Cancelling the form
257
+ cy . contains ( buttonSelector ( normalButtonType ) , cancelButton ) . click ( ) ;
152
258
} ) ;
153
259
154
260
it ( 'Checking whether add, edit & delete namespace works' , ( ) => {
@@ -157,18 +263,17 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
157
263
cy . expect_flash ( flashTypeSuccess , flashMessageAddSuccess ) ;
158
264
159
265
// Selecting the created namespace from the accordion list items
160
- interceptAccordionApi ( ) ;
266
+ selectAccordionTree ( namespaceName ) ;
161
267
// Editing the namespace
162
268
cy . toolbar ( toolbarConfiguration , toolbarEditNamespace ) ;
163
269
// Checking if the Save button is disabled initially
164
- cy . get ( '#main-content .bx--btn-set button[type="submit"]' )
165
- . contains ( saveButton )
166
- . should ( 'be.disabled' ) ;
167
- cy . get ( '#datastore-form-wrapper input#description' )
270
+ cy . contains ( buttonSelector ( submitButtonType ) , saveButton ) . should (
271
+ 'be.disabled'
272
+ ) ;
273
+ cy . get ( inputFieldSelector ( descriptionInputFieldId ) )
168
274
. clear ( )
169
275
. type ( editedDescription ) ;
170
- cy . get ( '#main-content .bx--btn-set button[type="submit"]' )
171
- . contains ( saveButton )
276
+ cy . contains ( buttonSelector ( submitButtonType ) , saveButton )
172
277
. should ( 'be.enabled' )
173
278
. click ( ) ;
174
279
cy . expect_flash ( flashTypeSuccess , flashMessageSaveSuccess ) ;
@@ -190,57 +295,48 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
190
295
cy . expect_flash ( flashTypeError , flashMessageNameAlreadyExists ) ;
191
296
192
297
// Cancelling the form
193
- cy . get ( '#main-content .bx--btn-set button[type="button"]' )
194
- . contains ( cancelButton )
195
- . click ( ) ;
298
+ cy . contains ( buttonSelector ( normalButtonType ) , cancelButton ) . click ( ) ;
196
299
} ) ;
197
300
198
301
it ( 'Checking whether Cancel & Reset buttons work fine in the Edit form' , ( ) => {
199
- // Adding a new namespace
200
- addNamespace ( ) ;
201
- // Selecting the created namespace from the accordion list items
202
- interceptAccordionApi ( ) ;
203
- // Opening the edit form
204
- cy . toolbar ( toolbarConfiguration , toolbarEditNamespace ) ;
302
+ // Create a namespace and open the edit form
303
+ createNamespaceAndOpenEditForm ( ) ;
205
304
206
305
/* Validating Reset button */
207
306
// Checking if the Reset button is disabled initially
208
- cy . get ( '#main-content .bx--btn-set button[type="button"]' )
209
- . contains ( resetButton )
210
- . should ( 'be.disabled' ) ;
307
+ cy . contains ( buttonSelector ( normalButtonType ) , resetButton ) . should (
308
+ 'be.disabled'
309
+ ) ;
211
310
// Editing name and description fields
212
- cy . get ( '#datastore-form-wrapper input#name' )
311
+ cy . get ( inputFieldSelector ( nameInputFieldId ) )
213
312
. clear ( )
214
313
. type ( editedNamespaceName ) ;
215
- cy . get ( '#datastore-form-wrapper input#description' )
314
+ cy . get ( inputFieldSelector ( descriptionInputFieldId ) )
216
315
. clear ( )
217
316
. type ( editedDescription ) ;
218
317
// Resetting
219
- cy . get ( '#main-content .bx--btn-set button[type="button"]' )
220
- . contains ( resetButton )
318
+ cy . contains ( buttonSelector ( normalButtonType ) , resetButton )
221
319
. should ( 'be.enabled' )
222
320
. click ( ) ;
223
321
cy . expect_flash ( flashTypeWarning , flashMessageResetNamespace ) ;
224
322
// Confirming the edited fields contain the old values after resetting
225
- cy . get ( '#datastore-form-wrapper input#name' ) . should (
323
+ cy . get ( inputFieldSelector ( nameInputFieldId ) ) . should (
226
324
'have.value' ,
227
325
namespaceName
228
326
) ;
229
- cy . get ( '#datastore-form-wrapper input#description' ) . should (
327
+ cy . get ( inputFieldSelector ( descriptionInputFieldId ) ) . should (
230
328
'have.value' ,
231
329
description
232
330
) ;
233
331
234
332
/* Validating Cancel button */
235
- cy . get ( '#main-content .bx--btn-set button[type="button"]' )
236
- . contains ( cancelButton )
237
- . click ( ) ;
333
+ cy . contains ( buttonSelector ( normalButtonType ) , cancelButton ) . click ( ) ;
238
334
cy . expect_flash ( flashTypeWarning , flashMessageCancelled ) ;
239
335
} ) ;
240
336
241
337
afterEach ( ( ) => {
242
338
// Selecting the created domain(Test_Domain) from the accordion list items
243
- interceptAccordionApi ( dataStoreAccordionItem ) ;
339
+ selectAccordionTree ( dataStoreAccordionItem ) ;
244
340
cy . accordionItem ( domainName ) ;
245
341
cy . wait ( '@getCreatedDomainInfo' ) ;
246
342
// Removing the domain
0 commit comments