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