@@ -79,28 +79,8 @@ const {
7979 flashMessageOperationCancelled,
8080} = textConstants ;
8181
82- function interceptAndAwaitApi ( {
83- alias,
84- method = 'POST' ,
85- urlPattern,
86- triggerFn,
87- currentApiIntercepts,
88- } ) {
89- // If the alias is already registered, do not register it again
90- // This prevents multiple intercepts for the same API call
91- // which can lead to unexpected behavior in tests.
92- if ( ! currentApiIntercepts [ alias ] ) {
93- cy . intercept ( method , urlPattern ) . as ( alias ) ;
94- currentApiIntercepts [ alias ] = alias ;
95- }
96-
97- triggerFn ( ) ;
98-
99- cy . wait ( `@${ alias } ` ) ;
100- }
101-
102- function goToCollectLogsTab ( { currentApiIntercepts } ) {
103- interceptAndAwaitApi ( {
82+ function goToCollectLogsTab ( ) {
83+ cy . interceptApi ( {
10484 alias : 'getCollectLogsTabInfo' ,
10585 urlPattern : '/ops/change_tab?tab_id=diagnostics_collect_logs' ,
10686 triggerFn : ( ) =>
@@ -109,24 +89,19 @@ function goToCollectLogsTab({ currentApiIntercepts }) {
10989 '#tab_all_tabs_div #ops_tabs .nav-tabs li#diagnostics_collect_logs_tab'
11090 )
11191 . click ( ) ,
112- currentApiIntercepts,
11392 } ) ;
11493}
11594
11695function selectToolbarEditButton ( ) {
117- interceptAndAwaitApi ( {
96+ cy . interceptApi ( {
11897 alias : 'editEventForServer' ,
11998 // This pattern matches both /ops/x_button/1?pressed=log_depot_edit & /ops/x_button/2?pressed=zone_log_depot_edit endpoints
12099 urlPattern : / \/ o p s \/ x _ b u t t o n \/ [ ^ / ] + \? p r e s s e d = .* l o g _ d e p o t _ e d i t / ,
121100 triggerFn : ( ) => cy . toolbar ( editToolbarButton ) ,
122- currentApiIntercepts,
123101 } ) ;
124102}
125103
126- function resetProtocolDropdown ( {
127- currentApiIntercepts,
128- selectServerListItem = true ,
129- } ) {
104+ function resetProtocolDropdown ( { selectServerListItem = true } = { } ) {
130105 // Select Diagnostics
131106 cy . accordion ( diagnosticsAccordionItem ) ;
132107 // Select "Zone:" or "Server:" accordion item
@@ -137,7 +112,7 @@ function resetProtocolDropdown({
137112 ] ) ;
138113
139114 // Clicking Edit button
140- selectToolbarEditButton ( { currentApiIntercepts } ) ;
115+ selectToolbarEditButton ( ) ;
141116
142117 // Resetting Protocol dropdown value
143118 cy . getFormSelectFieldById ( protocolSelectFieldId ) . then ( ( selectField ) => {
@@ -152,15 +127,11 @@ function resetProtocolDropdown({
152127 } ) ;
153128}
154129
155- function goToCollectLogsTabAndOpenEditForm ( registeredApiIntercepts ) {
130+ function goToCollectLogsTabAndOpenEditForm ( ) {
156131 // Selecting Collect Logs tab
157- goToCollectLogsTab ( {
158- currentApiIntercepts : registeredApiIntercepts ,
159- } ) ;
132+ goToCollectLogsTab ( ) ;
160133 // Clicking Edit button
161- selectToolbarEditButton ( {
162- currentApiIntercepts : registeredApiIntercepts ,
163- } ) ;
134+ selectToolbarEditButton ( ) ;
164135}
165136
166137function validateFormElements ( ) {
@@ -221,21 +192,14 @@ function saveButtonValidation() {
221192}
222193
223194describe ( 'Automate Collect logs Edit form operations' , ( ) => {
224- // Map that keeps track of registered API intercepts
225- // This is used to avoid registering the same API intercept multiple times
226- // during the test run, which can lead to unexpected behavior.
227- let registeredApiIntercepts ;
228-
229195 beforeEach ( ( ) => {
230- registeredApiIntercepts = { } ;
231196 cy . login ( ) ;
232197 // Navigate to Application settings and expand Diagnostics accordion
233198 cy . menu ( settingsMenuOption , appSettingsMenuOption ) ;
234- interceptAndAwaitApi ( {
199+ cy . interceptApi ( {
235200 alias : 'getDiagnosticsInfo' ,
236201 urlPattern : `/ops/accordion_select?id=${ diagnosticsAccordionItemId } ` ,
237202 triggerFn : ( ) => cy . accordion ( diagnosticsAccordionItem ) ,
238- currentApiIntercepts : registeredApiIntercepts ,
239203 } ) ;
240204 } ) ;
241205
@@ -248,7 +212,7 @@ describe('Automate Collect logs Edit form operations', () => {
248212 serverAccordItem ,
249213 ] ) ;
250214 // Select collect logs navbar and open edit form
251- goToCollectLogsTabAndOpenEditForm ( registeredApiIntercepts ) ;
215+ goToCollectLogsTabAndOpenEditForm ( ) ;
252216 } ) ;
253217
254218 it ( 'Validate form elements' , ( ) => {
@@ -276,26 +240,23 @@ describe('Automate Collect logs Edit form operations', () => {
276240 }
277241 } )
278242 . then ( ( ) => {
279- resetProtocolDropdown ( {
280- currentApiIntercepts : registeredApiIntercepts ,
281- } ) ;
243+ resetProtocolDropdown ( ) ;
282244 } ) ;
283245 } ) ;
284246 } ) ;
285247
286248 describe ( 'Settings > Application Settings > Diagnostics > Manage IQ Region > Zone > Collect logs > Edit' , ( ) => {
287249 beforeEach ( ( ) => {
288250 // Select "Zone:" accordion item
289- interceptAndAwaitApi ( {
251+ cy . interceptApi ( {
290252 alias : 'treeSelectApi' ,
291253 urlPattern :
292254 / o p s \/ t r e e _ s e l e c t \? i d = .* & t e x t = .* Z o n e .* D e f a u l t .* Z o n e .* ( c u r r e n t ) .* / ,
293255 triggerFn : ( ) =>
294256 cy . selectAccordionItem ( [ manageIQRegionAccordItem , zoneAccordItem ] ) ,
295- currentApiIntercepts : registeredApiIntercepts ,
296257 } ) ;
297258 // Select collect logs tab and open edit form
298- goToCollectLogsTabAndOpenEditForm ( registeredApiIntercepts ) ;
259+ goToCollectLogsTabAndOpenEditForm ( ) ;
299260 } ) ;
300261
301262 it ( 'Validate form elements' , ( ) => {
@@ -323,12 +284,8 @@ describe('Automate Collect logs Edit form operations', () => {
323284 }
324285 } )
325286 . then ( ( ) => {
326- resetProtocolDropdown ( {
327- currentApiIntercepts : registeredApiIntercepts ,
328- selectServerListItem : false ,
329- } ) ;
287+ resetProtocolDropdown ( { selectServerListItem : false } ) ;
330288 } ) ;
331289 } ) ;
332290 } ) ;
333291} ) ;
334-
0 commit comments