@@ -9,7 +9,6 @@ const textConstants = {
99 // Toolbar options
1010 toolbarConfiguration : 'Configuration' ,
1111 toolbarAddNewDomain : 'Add a New Domain' ,
12- toolbarRemoveDomain : 'Remove this Domain' ,
1312 toolbarAddNewNamespace : 'Add a New Namespace' ,
1413 toolbarEditNamespace : 'Edit this Namespace' ,
1514 toolbarRemoveNamespace : 'Remove this Namespace' ,
@@ -41,9 +40,6 @@ const textConstants = {
4140 editNamespaceFormHeader : 'Editing Automate Namespace' ,
4241 namespaceFormSubHeader : 'Info' ,
4342
44- // List items
45- dataStoreAccordionItem : 'Datastore' ,
46-
4743 // Buttons
4844 addButton : 'Add' ,
4945 cancelButton : 'Cancel' ,
@@ -85,7 +81,6 @@ const {
8581 toolbarAddNewNamespace,
8682 toolbarEditNamespace,
8783 toolbarRemoveNamespace,
88- toolbarRemoveDomain,
8984 addNamespaceFormHeader,
9085 editNamespaceFormHeader,
9186 namespaceFormSubHeader,
@@ -104,7 +99,6 @@ const {
10499 flashMessageNameAlreadyExists,
105100 flashMessageResetNamespace,
106101 browserConfirmRemoveMessage,
107- dataStoreAccordionItem,
108102 nameInputFieldId,
109103 descriptionInputFieldId,
110104 namespacePathInputFieldId,
@@ -126,7 +120,6 @@ function selectAccordionTree(textValue) {
126120 const aliasObject = {
127121 [ domainName ] : 'getCreatedDomainInfo' ,
128122 [ namespaceName ] : 'getCreatedNamespaceInfo' ,
129- [ dataStoreAccordionItem ] : 'getDataStoreAccordionItemInfo' ,
130123 } ;
131124 cy . intercept (
132125 'POST' ,
@@ -193,6 +186,33 @@ function createNamespaceAndOpenEditForm() {
193186 cy . toolbar ( toolbarConfiguration , toolbarEditNamespace ) ;
194187}
195188
189+ function extractDomainIdAndTokenFromResponse ( interception ) {
190+ const rawTreeObject = interception ?. response ?. body ?. reloadTrees ?. ae_tree ;
191+ if ( rawTreeObject ) {
192+ const rawTreeParsed = JSON . parse ( rawTreeObject ) ;
193+ rawTreeParsed . every ( ( treeObject ) => {
194+ // Exit iteration once id is extracted from nodes array
195+ return treeObject ?. nodes ?. every ( ( nodeObject ) => {
196+ if ( nodeObject ?. text === domainName ) {
197+ const domainId = nodeObject ?. key ?. split ( '-' ) ?. [ 1 ] ;
198+ const csrfToken = interception ?. request ?. headers ?. [ 'x-csrf-token' ] ;
199+ const idAndToken = {
200+ domainId,
201+ csrfToken,
202+ } ;
203+ // Creating an aliased state to store id and token
204+ cy . wrap ( idAndToken ) . as ( 'idAndToken' ) ;
205+
206+ // Stop iterating once the domain id is found
207+ return false ;
208+ }
209+ // Continue iterating
210+ return true ;
211+ } ) ;
212+ } ) ;
213+ }
214+ }
215+
196216describe ( 'Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form' , ( ) => {
197217 beforeEach ( ( ) => {
198218 cy . login ( ) ;
@@ -209,7 +229,9 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
209229 'addNamespaceApi'
210230 ) ;
211231 cy . contains ( buttonSelector ( submitButtonType ) , addButton ) . click ( ) ;
212- cy . wait ( '@addNamespaceApi' ) ;
232+ cy . wait ( '@addNamespaceApi' ) . then ( ( interception ) => {
233+ extractDomainIdAndTokenFromResponse ( interception ) ;
234+ } ) ;
213235 cy . expect_flash ( flashTypeSuccess , flashMessageAddSuccess ) ;
214236 // Selecting the created domain from the accordion list items
215237 selectAccordionTree ( domainName ) ;
@@ -335,15 +357,18 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
335357 } ) ;
336358
337359 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 ,
360+ // retrieve the id and token from the aliased state
361+ // to invoke api for deleting the created domain
362+ cy . get ( '@idAndToken' ) . then ( ( data ) => {
363+ cy . request ( {
364+ method : 'POST' ,
365+ url : `/miq_ae_class/x_button/${ data . domainId } ?pressed=miq_ae_domain_delete` ,
366+ headers : {
367+ 'X-CSRF-Token' : data ?. csrfToken ,
368+ } ,
369+ } ) . then ( ( response ) => {
370+ expect ( response . status ) . to . eq ( 200 ) ;
371+ } ) ;
347372 } ) ;
348373 } ) ;
349374} ) ;
0 commit comments