@@ -41,9 +41,6 @@ const textConstants = {
4141 editNamespaceFormHeader : 'Editing Automate Namespace' ,
4242 namespaceFormSubHeader : 'Info' ,
4343
44- // List items
45- dataStoreAccordionItem : 'Datastore' ,
46-
4744 // Buttons
4845 addButton : 'Add' ,
4946 cancelButton : 'Cancel' ,
@@ -104,7 +101,6 @@ const {
104101 flashMessageNameAlreadyExists,
105102 flashMessageResetNamespace,
106103 browserConfirmRemoveMessage,
107- dataStoreAccordionItem,
108104 nameInputFieldId,
109105 descriptionInputFieldId,
110106 namespacePathInputFieldId,
@@ -126,7 +122,6 @@ function selectAccordionTree(textValue) {
126122 const aliasObject = {
127123 [ domainName ] : 'getCreatedDomainInfo' ,
128124 [ namespaceName ] : 'getCreatedNamespaceInfo' ,
129- [ dataStoreAccordionItem ] : 'getDataStoreAccordionItemInfo' ,
130125 } ;
131126 cy . intercept (
132127 'POST' ,
@@ -193,6 +188,33 @@ function createNamespaceAndOpenEditForm() {
193188 cy . toolbar ( toolbarConfiguration , toolbarEditNamespace ) ;
194189}
195190
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+
196218describe ( 'Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form' , ( ) => {
197219 beforeEach ( ( ) => {
198220 cy . login ( ) ;
@@ -209,7 +231,9 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
209231 'addNamespaceApi'
210232 ) ;
211233 cy . contains ( buttonSelector ( submitButtonType ) , addButton ) . click ( ) ;
212- cy . wait ( '@addNamespaceApi' ) ;
234+ cy . wait ( '@addNamespaceApi' ) . then ( ( interception ) => {
235+ extractDomainIdAndTokenFromResponse ( interception ) ;
236+ } ) ;
213237 cy . expect_flash ( flashTypeSuccess , flashMessageAddSuccess ) ;
214238 // Selecting the created domain from the accordion list items
215239 selectAccordionTree ( domainName ) ;
@@ -335,15 +359,18 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
335359 } ) ;
336360
337361 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+ } ) ;
347374 } ) ;
348375 } ) ;
349376} ) ;
0 commit comments