Skip to content

Commit fd1f7ff

Browse files
Minor refactor to improve readability
1 parent 41e7366 commit fd1f7ff

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

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

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ const textConstants = {
3131
dropdownBlankValue: 'BLANK_VALUE',
3232
sambaDropdownValue: 'FileDepotSmb',
3333

34-
// Button types
35-
submitButtonType: 'submit',
36-
3734
// Component route url
3835
componentRouteUrl: '/ops/explorer',
3936

@@ -42,7 +39,7 @@ const textConstants = {
4239

4340
// Flash message text snippets
4441
flashMessageSettingsSaved: 'saved',
45-
flashMessageOperationCanceled: 'cancel',
42+
flashMessageOperationCancelled: 'cancel',
4643
};
4744

4845
const {
@@ -62,8 +59,7 @@ const {
6259
componentRouteUrl,
6360
flashTypeSuccess,
6461
flashMessageSettingsSaved,
65-
flashMessageOperationCanceled,
66-
submitButtonType,
62+
flashMessageOperationCancelled,
6763
protocolSelectFieldId,
6864
formHeader,
6965
formSubheaderSnippet,
@@ -89,7 +85,7 @@ function interceptAndAwaitApi({
8985
cy.wait(`@${alias}`);
9086
}
9187

92-
function invokeAndAwaitCollectLogsTabInfo({ currentApiIntercepts }) {
88+
function goToCollectLogsTab({ currentApiIntercepts }) {
9389
interceptAndAwaitApi({
9490
alias: 'getCollectLogsTabInfo',
9591
urlPattern: '/ops/change_tab?tab_id=diagnostics_collect_logs',
@@ -103,10 +99,11 @@ function invokeAndAwaitCollectLogsTabInfo({ currentApiIntercepts }) {
10399
});
104100
}
105101

106-
function invokeAndAwaitEditEventForServer({ currentApiIntercepts }) {
102+
function selectToolbarEditButton() {
107103
interceptAndAwaitApi({
108104
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
105+
// This pattern matches both /ops/x_button/1?pressed=log_depot_edit & /ops/x_button/2?pressed=zone_log_depot_edit endpoints
106+
urlPattern: /\/ops\/x_button\/[^/]+\?pressed=.*log_depot_edit/,
110107
triggerFn: () => cy.toolbar(editToolbarButton),
111108
currentApiIntercepts,
112109
});
@@ -126,28 +123,28 @@ function resetProtocolDropdown({
126123
]);
127124

128125
// Clicking Edit button
129-
invokeAndAwaitEditEventForServer({ currentApiIntercepts });
126+
selectToolbarEditButton({ currentApiIntercepts });
130127

131128
// Resetting Protocol dropdown value
132-
cy.getFormSelectFieldById(protocolSelectFieldId).then(($select) => {
133-
const currentValue = $select.val();
129+
cy.getFormSelectFieldById(protocolSelectFieldId).then((selectField) => {
130+
const currentValue = selectField.val();
134131
// If the value is not default one(BLANK_VALUE), then setting it to blank
135132
if (currentValue !== dropdownBlankValue) {
136-
cy.wrap($select).select(dropdownBlankValue);
137-
cy.getFormFooterButtonByType(saveButton, submitButtonType).click();
133+
cy.wrap(selectField).select(dropdownBlankValue);
134+
cy.getFormFooterButtonByType(saveButton, 'submit').click();
138135
// Validating confirmation flash message
139136
cy.expect_flash(flashTypeSuccess, flashMessageSettingsSaved);
140137
}
141138
});
142139
}
143140

144-
function goToCollectLogsNavbarAndOpenEditForm(registeredApiIntercepts) {
145-
// Selecting Collect Logs nav bar
146-
invokeAndAwaitCollectLogsTabInfo({
141+
function goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts) {
142+
// Selecting Collect Logs tab
143+
goToCollectLogsTab({
147144
currentApiIntercepts: registeredApiIntercepts,
148145
});
149146
// Clicking Edit button
150-
invokeAndAwaitEditEventForServer({
147+
selectToolbarEditButton({
151148
currentApiIntercepts: registeredApiIntercepts,
152149
});
153150
}
@@ -168,7 +165,7 @@ function validateFormElements() {
168165
.should('be.visible')
169166
.and('be.enabled');
170167
// Assert save button is visible and disabled
171-
cy.getFormFooterButtonByType(saveButton, submitButtonType)
168+
cy.getFormFooterButtonByType(saveButton, 'submit')
172169
.should('be.visible')
173170
.and('be.disabled');
174171
// Assert reset button is visible and disabled
@@ -181,7 +178,7 @@ function cancelButtonValidation() {
181178
// Click cancel button in the form
182179
cy.getFormFooterButtonByType(cancelButton).click();
183180
// Validating confirmation flash message
184-
cy.expect_flash(flashTypeSuccess, flashMessageOperationCanceled);
181+
cy.expect_flash(flashTypeSuccess, flashMessageOperationCancelled);
185182
}
186183

187184
function resetButtonValidation() {
@@ -200,7 +197,7 @@ function saveButtonValidation() {
200197
// Selecting Samba option from dropdown
201198
cy.getFormSelectFieldById(protocolSelectFieldId).select(sambaDropdownValue);
202199
// Confirm Save button is enabled once dropdown value is changed and then click on Save
203-
cy.getFormFooterButtonByType(saveButton, submitButtonType)
200+
cy.getFormFooterButtonByType(saveButton, 'submit')
204201
.should('be.enabled')
205202
.click();
206203
// Validating confirmation flash message
@@ -216,7 +213,7 @@ describe('Automate Collect logs Edit form operations', () => {
216213
beforeEach(() => {
217214
registeredApiIntercepts = {};
218215
cy.login();
219-
// Navigate to Application settings and Select Diagnostics
216+
// Navigate to Application settings and expand Diagnostics accordion
220217
cy.menu(settingsMenuOption, appSettingsMenuOption);
221218
interceptAndAwaitApi({
222219
alias: 'getDiagnosticsInfo',
@@ -235,19 +232,18 @@ describe('Automate Collect logs Edit form operations', () => {
235232
serverAccordItem,
236233
]);
237234
// Select collect logs navbar and open edit form
238-
goToCollectLogsNavbarAndOpenEditForm(registeredApiIntercepts);
235+
goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts);
239236
});
240237

241238
it('Validate form elements', () => {
242239
validateFormElements();
243240
});
244241

245-
it('Validate Cancel button', () => {
246-
cancelButtonValidation();
247-
});
248-
249-
it('Validate Reset button', () => {
242+
it('Validate Reset & Cancel buttons', () => {
243+
// Reset button validation
250244
resetButtonValidation();
245+
// Cancel button validation
246+
cancelButtonValidation();
251247
});
252248

253249
it('Validate Save button', () => {
@@ -282,20 +278,19 @@ describe('Automate Collect logs Edit form operations', () => {
282278
cy.selectAccordionItem([manageIQRegionAccordItem, zoneAccordItem]),
283279
currentApiIntercepts: registeredApiIntercepts,
284280
});
285-
// Select collect logs navbar and open edit form
286-
goToCollectLogsNavbarAndOpenEditForm(registeredApiIntercepts);
281+
// Select collect logs tab and open edit form
282+
goToCollectLogsTabAndOpenEditForm(registeredApiIntercepts);
287283
});
288284

289285
it('Validate form elements', () => {
290286
validateFormElements();
291287
});
292288

293-
it('Validate Cancel button', () => {
294-
cancelButtonValidation();
295-
});
296-
297-
it('Validate Reset button', () => {
289+
it('Validate Reset & Cancel buttons', () => {
290+
// Reset button validation
298291
resetButtonValidation();
292+
// Cancel button validation
293+
cancelButtonValidation();
299294
});
300295

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

0 commit comments

Comments
 (0)