@@ -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' ,
@@ -84,7 +80,6 @@ const {
8480 toolbarAddNewNamespace,
8581 toolbarEditNamespace,
8682 toolbarRemoveNamespace,
87- toolbarRemoveDomain,
8883 addNamespaceFormHeader,
8984 editNamespaceFormHeader,
9085 namespaceFormSubHeader,
@@ -103,7 +98,6 @@ const {
10398 flashMessageNameAlreadyExists,
10499 flashMessageResetNamespace,
105100 browserConfirmRemoveMessage,
106- dataStoreAccordionItem,
107101 nameInputFieldId,
108102 descriptionInputFieldId,
109103 namespacePathInputFieldId,
@@ -125,7 +119,6 @@ function selectAccordionTree(textValue) {
125119 const aliasObject = {
126120 [ domainName ] : 'getCreatedDomainInfo' ,
127121 [ namespaceName ] : 'getCreatedNamespaceInfo' ,
128- [ dataStoreAccordionItem ] : 'getDataStoreAccordionItemInfo' ,
129122 } ;
130123 cy . intercept (
131124 'POST' ,
@@ -192,6 +185,33 @@ function createNamespaceAndOpenEditForm() {
192185 cy . toolbar ( toolbarConfiguration , toolbarEditNamespace ) ;
193186}
194187
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+
195215describe ( 'Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form' , ( ) => {
196216 beforeEach ( ( ) => {
197217 cy . login ( ) ;
@@ -208,7 +228,9 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
208228 'addNamespaceApi'
209229 ) ;
210230 cy . contains ( buttonSelector ( submitButtonType ) , addButton ) . click ( ) ;
211- cy . wait ( '@addNamespaceApi' ) ;
231+ cy . wait ( '@addNamespaceApi' ) . then ( ( interception ) => {
232+ extractDomainIdAndTokenFromResponse ( interception ) ;
233+ } ) ;
212234 cy . expect_flash ( flashTypeSuccess , flashMessageAddSuccess ) ;
213235 // Selecting the created domain from the accordion list items
214236 selectAccordionTree ( domainName ) ;
@@ -334,15 +356,18 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
334356 } ) ;
335357
336358 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+ } ) ;
346371 } ) ;
347372 } ) ;
348373} ) ;
0 commit comments