Skip to content

Commit b45d49b

Browse files
Applied interceptApi command
1 parent fd1f7ff commit b45d49b

File tree

1 file changed

+14
-57
lines changed

1 file changed

+14
-57
lines changed

cypress/e2e/ui/Settings/Application-Settings/edit_collect_logs.cy.js

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,8 @@ const {
6565
formSubheaderSnippet,
6666
} = textConstants;
6767

68-
function interceptAndAwaitApi({
69-
alias,
70-
method = 'POST',
71-
urlPattern,
72-
triggerFn,
73-
currentApiIntercepts,
74-
}) {
75-
// If the alias is already registered, do not register it again
76-
// This prevents multiple intercepts for the same API call
77-
// which can lead to unexpected behavior in tests.
78-
if (!currentApiIntercepts[alias]) {
79-
cy.intercept(method, urlPattern).as(alias);
80-
currentApiIntercepts[alias] = alias;
81-
}
82-
83-
triggerFn();
84-
85-
cy.wait(`@${alias}`);
86-
}
87-
88-
function goToCollectLogsTab({ currentApiIntercepts }) {
89-
interceptAndAwaitApi({
68+
function goToCollectLogsTab() {
69+
cy.interceptApi({
9070
alias: 'getCollectLogsTabInfo',
9171
urlPattern: '/ops/change_tab?tab_id=diagnostics_collect_logs',
9272
triggerFn: () =>
@@ -95,24 +75,19 @@ function goToCollectLogsTab({ currentApiIntercepts }) {
9575
'#tab_all_tabs_div #ops_tabs .nav-tabs li#diagnostics_collect_logs_tab'
9676
)
9777
.click(),
98-
currentApiIntercepts,
9978
});
10079
}
10180

10281
function selectToolbarEditButton() {
103-
interceptAndAwaitApi({
82+
cy.interceptApi({
10483
alias: 'editEventForServer',
10584
// This pattern matches both /ops/x_button/1?pressed=log_depot_edit & /ops/x_button/2?pressed=zone_log_depot_edit endpoints
10685
urlPattern: /\/ops\/x_button\/[^/]+\?pressed=.*log_depot_edit/,
10786
triggerFn: () => cy.toolbar(editToolbarButton),
108-
currentApiIntercepts,
10987
});
11088
}
11189

112-
function resetProtocolDropdown({
113-
currentApiIntercepts,
114-
selectServerListItem = true,
115-
}) {
90+
function resetProtocolDropdown({ selectServerListItem = true } = {}) {
11691
// Select Diagnostics
11792
cy.accordion(diagnosticsAccordionItem);
11893
// Select "Zone:" or "Server:" accordion item
@@ -123,7 +98,7 @@ function resetProtocolDropdown({
12398
]);
12499

125100
// Clicking Edit button
126-
selectToolbarEditButton({ currentApiIntercepts });
101+
selectToolbarEditButton();
127102

128103
// Resetting Protocol dropdown value
129104
cy.getFormSelectFieldById(protocolSelectFieldId).then((selectField) => {
@@ -138,15 +113,11 @@ function resetProtocolDropdown({
138113
});
139114
}
140115

141-
function goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts) {
116+
function goToCollectLogsTabAndOpenEditForm() {
142117
// Selecting Collect Logs tab
143-
goToCollectLogsTab({
144-
currentApiIntercepts: registeredApiIntercepts,
145-
});
118+
goToCollectLogsTab();
146119
// Clicking Edit button
147-
selectToolbarEditButton({
148-
currentApiIntercepts: registeredApiIntercepts,
149-
});
120+
selectToolbarEditButton();
150121
}
151122

152123
function validateFormElements() {
@@ -205,21 +176,14 @@ function saveButtonValidation() {
205176
}
206177

207178
describe('Automate Collect logs Edit form operations', () => {
208-
// Map that keeps track of registered API intercepts
209-
// This is used to avoid registering the same API intercept multiple times
210-
// during the test run, which can lead to unexpected behavior.
211-
let registeredApiIntercepts;
212-
213179
beforeEach(() => {
214-
registeredApiIntercepts = {};
215180
cy.login();
216181
// Navigate to Application settings and expand Diagnostics accordion
217182
cy.menu(settingsMenuOption, appSettingsMenuOption);
218-
interceptAndAwaitApi({
183+
cy.interceptApi({
219184
alias: 'getDiagnosticsInfo',
220185
urlPattern: `/ops/accordion_select?id=${diagnosticsAccordionItemId}`,
221186
triggerFn: () => cy.accordion(diagnosticsAccordionItem),
222-
currentApiIntercepts: registeredApiIntercepts,
223187
});
224188
});
225189

@@ -232,7 +196,7 @@ describe('Automate Collect logs Edit form operations', () => {
232196
serverAccordItem,
233197
]);
234198
// Select collect logs navbar and open edit form
235-
goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts);
199+
goToCollectLogsTabAndOpenEditForm();
236200
});
237201

238202
it('Validate form elements', () => {
@@ -260,26 +224,23 @@ describe('Automate Collect logs Edit form operations', () => {
260224
}
261225
})
262226
.then(() => {
263-
resetProtocolDropdown({
264-
currentApiIntercepts: registeredApiIntercepts,
265-
});
227+
resetProtocolDropdown();
266228
});
267229
});
268230
});
269231

270232
describe('Settings > Application Settings > Diagnostics > Manage IQ Region > Zone > Collect logs > Edit', () => {
271233
beforeEach(() => {
272234
// Select "Zone:" accordion item
273-
interceptAndAwaitApi({
235+
cy.interceptApi({
274236
alias: 'treeSelectApi',
275237
urlPattern:
276238
/ops\/tree_select\?id=.*&text=.*Zone.*Default.*Zone.*(current).*/,
277239
triggerFn: () =>
278240
cy.selectAccordionItem([manageIQRegionAccordItem, zoneAccordItem]),
279-
currentApiIntercepts: registeredApiIntercepts,
280241
});
281242
// Select collect logs tab and open edit form
282-
goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts);
243+
goToCollectLogsTabAndOpenEditForm();
283244
});
284245

285246
it('Validate form elements', () => {
@@ -307,12 +268,8 @@ describe('Automate Collect logs Edit form operations', () => {
307268
}
308269
})
309270
.then(() => {
310-
resetProtocolDropdown({
311-
currentApiIntercepts: registeredApiIntercepts,
312-
selectServerListItem: false,
313-
});
271+
resetProtocolDropdown({ selectServerListItem: false });
314272
});
315273
});
316274
});
317275
});
318-

0 commit comments

Comments
 (0)