Skip to content

Commit b610b33

Browse files
Minor refactor to improve readability
1 parent 1b28afa commit b610b33

File tree

1 file changed

+63
-54
lines changed

1 file changed

+63
-54
lines changed

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

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* eslint-disable no-undef */
2+
import { flashClassMap } from "../../../../support/assertions/assertion_constants";
23

34
const textConstants = {
5+
// Component route url
6+
componentRouteUrl: '/ops/explorer',
7+
48
// Menu options
59
settingsMenuOption: 'Settings',
610
appSettingsMenuOption: 'Application Settings',
@@ -31,42 +35,48 @@ const textConstants = {
3135
dropdownBlankValue: 'BLANK_VALUE',
3236
sambaDropdownValue: 'FileDepotSmb',
3337

34-
// Button types
35-
submitButtonType: 'submit',
36-
37-
// Component route url
38-
componentRouteUrl: '/ops/explorer',
39-
40-
// Flash message types
41-
flashTypeSuccess: 'success',
42-
4338
// Flash message text snippets
4439
flashMessageSettingsSaved: 'saved',
45-
flashMessageOperationCanceled: 'cancel',
40+
flashMessageOperationCancelled: 'cancel',
4641
};
4742

4843
const {
49-
diagnosticsAccordionItem,
50-
dropdownBlankValue,
51-
editToolbarButton,
52-
sambaDropdownValue,
53-
saveButton,
54-
cancelButton,
55-
resetButton,
44+
// Component route url
45+
componentRouteUrl,
46+
47+
// Menu options
5648
settingsMenuOption,
5749
appSettingsMenuOption,
50+
51+
// List items
52+
diagnosticsAccordionItem,
5853
diagnosticsAccordionItemId,
5954
manageIQRegionAccordItem,
6055
zoneAccordItem,
6156
serverAccordItem,
62-
componentRouteUrl,
63-
flashTypeSuccess,
64-
flashMessageSettingsSaved,
65-
flashMessageOperationCanceled,
66-
submitButtonType,
67-
protocolSelectFieldId,
57+
58+
// Field values
6859
formHeader,
6960
formSubheaderSnippet,
61+
62+
// Config options
63+
editToolbarButton,
64+
65+
// Buttons
66+
saveButton,
67+
cancelButton,
68+
resetButton,
69+
70+
// Common element IDs
71+
protocolSelectFieldId,
72+
73+
// Dropdown values
74+
dropdownBlankValue,
75+
sambaDropdownValue,
76+
77+
// Flash message text snippets
78+
flashMessageSettingsSaved,
79+
flashMessageOperationCancelled,
7080
} = textConstants;
7181

7282
function interceptAndAwaitApi({
@@ -89,7 +99,7 @@ function interceptAndAwaitApi({
8999
cy.wait(`@${alias}`);
90100
}
91101

92-
function invokeAndAwaitCollectLogsTabInfo({ currentApiIntercepts }) {
102+
function goToCollectLogsTab({ currentApiIntercepts }) {
93103
interceptAndAwaitApi({
94104
alias: 'getCollectLogsTabInfo',
95105
urlPattern: '/ops/change_tab?tab_id=diagnostics_collect_logs',
@@ -103,10 +113,11 @@ function invokeAndAwaitCollectLogsTabInfo({ currentApiIntercepts }) {
103113
});
104114
}
105115

106-
function invokeAndAwaitEditEventForServer({ currentApiIntercepts }) {
116+
function selectToolbarEditButton() {
107117
interceptAndAwaitApi({
108118
alias: 'editEventForServer',
109-
urlPattern: /\/ops\/x_button\/[^/]+\?pressed=.*log_depot_edit/, // matches both /ops/x_button/1?pressed=log_depot_edit & /ops/x_button/2?pressed=zone_log_depot_edit endpoints
119+
// This pattern matches both /ops/x_button/1?pressed=log_depot_edit & /ops/x_button/2?pressed=zone_log_depot_edit endpoints
120+
urlPattern: /\/ops\/x_button\/[^/]+\?pressed=.*log_depot_edit/,
110121
triggerFn: () => cy.toolbar(editToolbarButton),
111122
currentApiIntercepts,
112123
});
@@ -126,28 +137,28 @@ function resetProtocolDropdown({
126137
]);
127138

128139
// Clicking Edit button
129-
invokeAndAwaitEditEventForServer({ currentApiIntercepts });
140+
selectToolbarEditButton({ currentApiIntercepts });
130141

131142
// Resetting Protocol dropdown value
132-
cy.getFormSelectFieldById(protocolSelectFieldId).then(($select) => {
133-
const currentValue = $select.val();
143+
cy.getFormSelectFieldById(protocolSelectFieldId).then((selectField) => {
144+
const currentValue = selectField.val();
134145
// If the value is not default one(BLANK_VALUE), then setting it to blank
135146
if (currentValue !== dropdownBlankValue) {
136-
cy.wrap($select).select(dropdownBlankValue);
137-
cy.getFormFooterButtonByType(saveButton, submitButtonType).click();
147+
cy.wrap(selectField).select(dropdownBlankValue);
148+
cy.getFormFooterButtonByType(saveButton, 'submit').click();
138149
// Validating confirmation flash message
139-
cy.expect_flash(flashTypeSuccess, flashMessageSettingsSaved);
150+
cy.expect_flash(flashClassMap.success, flashMessageSettingsSaved);
140151
}
141152
});
142153
}
143154

144-
function goToCollectLogsNavbarAndOpenEditForm(registeredApiIntercepts) {
145-
// Selecting Collect Logs nav bar
146-
invokeAndAwaitCollectLogsTabInfo({
155+
function goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts) {
156+
// Selecting Collect Logs tab
157+
goToCollectLogsTab({
147158
currentApiIntercepts: registeredApiIntercepts,
148159
});
149160
// Clicking Edit button
150-
invokeAndAwaitEditEventForServer({
161+
selectToolbarEditButton({
151162
currentApiIntercepts: registeredApiIntercepts,
152163
});
153164
}
@@ -170,7 +181,7 @@ function validateFormElements() {
170181
.should('be.visible')
171182
.and('be.enabled');
172183
// Assert save button is visible and disabled
173-
cy.getFormFooterButtonByType(saveButton, submitButtonType)
184+
cy.getFormFooterButtonByType(saveButton, 'submit')
174185
.should('be.visible')
175186
.and('be.disabled');
176187
// Assert reset button is visible and disabled
@@ -183,7 +194,7 @@ function cancelButtonValidation() {
183194
// Click cancel button in the form
184195
cy.getFormFooterButtonByType(cancelButton).click();
185196
// Validating confirmation flash message
186-
cy.expect_flash(flashTypeSuccess, flashMessageOperationCanceled);
197+
cy.expect_flash(flashClassMap.success, flashMessageOperationCancelled);
187198
}
188199

189200
function resetButtonValidation() {
@@ -202,11 +213,11 @@ function saveButtonValidation() {
202213
// Selecting Samba option from dropdown
203214
cy.getFormSelectFieldById(protocolSelectFieldId).select(sambaDropdownValue);
204215
// Confirm Save button is enabled once dropdown value is changed and then click on Save
205-
cy.getFormFooterButtonByType(saveButton, submitButtonType)
216+
cy.getFormFooterButtonByType(saveButton, 'submit')
206217
.should('be.enabled')
207218
.click();
208219
// Validating confirmation flash message
209-
cy.expect_flash(flashTypeSuccess, flashMessageSettingsSaved);
220+
cy.expect_flash(flashClassMap.success, flashMessageSettingsSaved);
210221
}
211222

212223
describe('Automate Collect logs Edit form operations', () => {
@@ -218,7 +229,7 @@ describe('Automate Collect logs Edit form operations', () => {
218229
beforeEach(() => {
219230
registeredApiIntercepts = {};
220231
cy.login();
221-
// Navigate to Application settings and Select Diagnostics
232+
// Navigate to Application settings and expand Diagnostics accordion
222233
cy.menu(settingsMenuOption, appSettingsMenuOption);
223234
interceptAndAwaitApi({
224235
alias: 'getDiagnosticsInfo',
@@ -237,19 +248,18 @@ describe('Automate Collect logs Edit form operations', () => {
237248
serverAccordItem,
238249
]);
239250
// Select collect logs navbar and open edit form
240-
goToCollectLogsNavbarAndOpenEditForm(registeredApiIntercepts);
251+
goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts);
241252
});
242253

243254
it('Validate form elements', () => {
244255
validateFormElements();
245256
});
246257

247-
it('Validate Cancel button', () => {
248-
cancelButtonValidation();
249-
});
250-
251-
it('Validate Reset button', () => {
258+
it('Validate Reset & Cancel buttons', () => {
259+
// Reset button validation
252260
resetButtonValidation();
261+
// Cancel button validation
262+
cancelButtonValidation();
253263
});
254264

255265
it('Validate Save button', () => {
@@ -284,20 +294,19 @@ describe('Automate Collect logs Edit form operations', () => {
284294
cy.selectAccordionItem([manageIQRegionAccordItem, zoneAccordItem]),
285295
currentApiIntercepts: registeredApiIntercepts,
286296
});
287-
// Select collect logs navbar and open edit form
288-
goToCollectLogsNavbarAndOpenEditForm(registeredApiIntercepts);
297+
// Select collect logs tab and open edit form
298+
goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts);
289299
});
290300

291301
it('Validate form elements', () => {
292302
validateFormElements();
293303
});
294304

295-
it('Validate Cancel button', () => {
296-
cancelButtonValidation();
297-
});
298-
299-
it('Validate Reset button', () => {
305+
it('Validate Reset & Cancel buttons', () => {
306+
// Reset button validation
300307
resetButtonValidation();
308+
// Cancel button validation
309+
cancelButtonValidation();
301310
});
302311

303312
it('Validate Save button', () => {

0 commit comments

Comments
 (0)