@@ -9,7 +9,6 @@ const textConstants = {
9
9
// Toolbar options
10
10
toolbarConfiguration : 'Configuration' ,
11
11
toolbarAddNewDomain : 'Add a New Domain' ,
12
- toolbarRemoveDomain : 'Remove this Domain' ,
13
12
toolbarAddNewNamespace : 'Add a New Namespace' ,
14
13
toolbarEditNamespace : 'Edit this Namespace' ,
15
14
toolbarRemoveNamespace : 'Remove this Namespace' ,
@@ -41,9 +40,6 @@ const textConstants = {
41
40
editNamespaceFormHeader : 'Editing Automate Namespace' ,
42
41
namespaceFormSubHeader : 'Info' ,
43
42
44
- // List items
45
- dataStoreAccordionItem : 'Datastore' ,
46
-
47
43
// Buttons
48
44
addButton : 'Add' ,
49
45
cancelButton : 'Cancel' ,
@@ -84,7 +80,6 @@ const {
84
80
toolbarAddNewNamespace,
85
81
toolbarEditNamespace,
86
82
toolbarRemoveNamespace,
87
- toolbarRemoveDomain,
88
83
addNamespaceFormHeader,
89
84
editNamespaceFormHeader,
90
85
namespaceFormSubHeader,
@@ -103,7 +98,6 @@ const {
103
98
flashMessageNameAlreadyExists,
104
99
flashMessageResetNamespace,
105
100
browserConfirmRemoveMessage,
106
- dataStoreAccordionItem,
107
101
nameInputFieldId,
108
102
descriptionInputFieldId,
109
103
namespacePathInputFieldId,
@@ -125,7 +119,6 @@ function selectAccordionTree(textValue) {
125
119
const aliasObject = {
126
120
[ domainName ] : 'getCreatedDomainInfo' ,
127
121
[ namespaceName ] : 'getCreatedNamespaceInfo' ,
128
- [ dataStoreAccordionItem ] : 'getDataStoreAccordionItemInfo' ,
129
122
} ;
130
123
cy . intercept (
131
124
'POST' ,
@@ -192,6 +185,33 @@ function createNamespaceAndOpenEditForm() {
192
185
cy . toolbar ( toolbarConfiguration , toolbarEditNamespace ) ;
193
186
}
194
187
188
+ function extractDomainIdAndTokenFromResponse ( interception ) {
189
+ const rawTreeObject = interception ?. response ?. body ?. reloadTrees ?. ae_tree ;
190
+ if ( rawTreeObject ) {
191
+ const rawTreeParsed = JSON . parse ( rawTreeObject ) ;
192
+ rawTreeParsed . every ( ( treeObject ) => {
193
+ // Exit iteration once id is extracted from nodes array
194
+ return treeObject ?. nodes ?. every ( ( nodeObject ) => {
195
+ if ( nodeObject ?. text === domainName ) {
196
+ const domainId = nodeObject ?. key ?. split ( '-' ) ?. [ 1 ] ;
197
+ const csrfToken = interception ?. request ?. headers ?. [ 'x-csrf-token' ] ;
198
+ const idAndToken = {
199
+ domainId,
200
+ csrfToken,
201
+ } ;
202
+ // Creating an aliased state to store id and token
203
+ cy . wrap ( idAndToken ) . as ( 'idAndToken' ) ;
204
+
205
+ // Stop iterating once the domain id is found
206
+ return false ;
207
+ }
208
+ // Continue iterating
209
+ return true ;
210
+ } ) ;
211
+ } ) ;
212
+ }
213
+ }
214
+
195
215
describe ( 'Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form' , ( ) => {
196
216
beforeEach ( ( ) => {
197
217
cy . login ( ) ;
@@ -208,7 +228,9 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
208
228
'addNamespaceApi'
209
229
) ;
210
230
cy . contains ( buttonSelector ( submitButtonType ) , addButton ) . click ( ) ;
211
- cy . wait ( '@addNamespaceApi' ) ;
231
+ cy . wait ( '@addNamespaceApi' ) . then ( ( interception ) => {
232
+ extractDomainIdAndTokenFromResponse ( interception ) ;
233
+ } ) ;
212
234
cy . expect_flash ( flashTypeSuccess , flashMessageAddSuccess ) ;
213
235
// Selecting the created domain from the accordion list items
214
236
selectAccordionTree ( domainName ) ;
@@ -334,15 +356,18 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
334
356
} ) ;
335
357
336
358
afterEach ( ( ) => {
337
- // Selecting the created domain(Test_Domain) from the accordion list items
338
- selectAccordionTree ( dataStoreAccordionItem ) ;
339
- cy . accordionItem ( domainName ) ;
340
- cy . wait ( '@getCreatedDomainInfo' ) ;
341
- // Removing the domain
342
- cy . expect_browser_confirm_with_text ( {
343
- confirmTriggerFn : ( ) =>
344
- cy . toolbar ( toolbarConfiguration , toolbarRemoveDomain ) ,
345
- containsText : browserConfirmRemoveMessage ,
359
+ // retrieve the id and token from the aliased state
360
+ // to invoke api for deleting the created domain
361
+ cy . get ( '@idAndToken' ) . then ( ( data ) => {
362
+ cy . request ( {
363
+ method : 'POST' ,
364
+ url : `/miq_ae_class/x_button/${ data . domainId } ?pressed=miq_ae_domain_delete` ,
365
+ headers : {
366
+ 'X-CSRF-Token' : data ?. csrfToken ,
367
+ } ,
368
+ } ) . then ( ( response ) => {
369
+ expect ( response . status ) . to . eq ( 200 ) ;
370
+ } ) ;
346
371
} ) ;
347
372
} ) ;
348
373
} ) ;
0 commit comments