Skip to content

Commit bfedae3

Browse files
Defined a constants object for static strings to reduce duplication
1 parent 6c88761 commit bfedae3

File tree

1 file changed

+73
-36
lines changed

1 file changed

+73
-36
lines changed

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

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,54 @@
11
/* eslint-disable no-undef */
22

3+
const textConstants = {
4+
// Menu options
5+
settingsMenuOption: 'Settings',
6+
appSettingsMenuOption: 'Application Settings',
7+
8+
// List items
9+
diagnosticsAccordionItem: 'Diagnostics',
10+
diagnosticsAccordionItemId: 'diagnostics_accord',
11+
manageIQRegionAccordItem: 'ManageIQ Region:',
12+
zoneAccordItem: 'Zone:',
13+
serverAccordItem: 'Server:',
14+
15+
// Buttons
16+
saveButton: 'Save',
17+
cancelButton: 'Cancel',
18+
resetButton: 'Reset',
19+
20+
// Dropdown values
21+
dropdownBlankValue: 'BLANK_VALUE',
22+
sambaDropdownValue: 'FileDepotSmb',
23+
24+
// Component route url
25+
componentRouteUrl: '/ops/explorer',
26+
};
27+
28+
const {
29+
diagnosticsAccordionItem,
30+
dropdownBlankValue,
31+
sambaDropdownValue,
32+
saveButton,
33+
cancelButton,
34+
resetButton,
35+
settingsMenuOption,
36+
appSettingsMenuOption,
37+
diagnosticsAccordionItemId,
38+
manageIQRegionAccordItem,
39+
zoneAccordItem,
40+
serverAccordItem,
41+
componentRouteUrl,
42+
} = textConstants;
43+
344
function invokeAndAwaitDiagnosticsInfo() {
445
let requestFired = false;
546
cy.intercept(
647
'POST',
7-
'/ops/accordion_select?id=diagnostics_accord',
48+
`/ops/accordion_select?id=${diagnosticsAccordionItemId}`,
849
() => (requestFired = true)
950
).as('getDiagnosticsInfo');
10-
cy.accordion('Diagnostics');
51+
cy.accordion(diagnosticsAccordionItem);
1152
cy.then(() => {
1253
// If the request was fired, wait for the alias
1354
if (requestFired) {
@@ -36,44 +77,42 @@ function interceptAndAwaitApi({
3677
cy.wait(`@${alias}`);
3778
}
3879

39-
function invokeAndAwaitRegionInfo({
40-
currentApiIntercepts,
41-
}) {
80+
function invokeAndAwaitRegionInfo({ currentApiIntercepts }) {
4281
interceptAndAwaitApi({
4382
alias: 'getRegionInfo',
4483
urlPattern: /ops\/tree_select\?id=.*&text=.*ManageIQ.*Region.*Region.*/,
4584
triggerFn: () =>
46-
cy.accordionItem('ManageIQ Region:', true, 'diagnostics_accord'),
85+
cy.accordionItem(
86+
manageIQRegionAccordItem,
87+
true,
88+
diagnosticsAccordionItemId
89+
),
4790
currentApiIntercepts,
4891
});
4992
}
5093

51-
function invokeAndAwaitZoneDefaultInfo({
52-
currentApiIntercepts,
53-
}) {
94+
function invokeAndAwaitZoneDefaultInfo({ currentApiIntercepts }) {
5495
interceptAndAwaitApi({
5596
alias: 'getZoneDefaultInfo',
5697
urlPattern:
5798
/ops\/tree_select\?id=.*&text=.*Zone.*Default.*Zone.*(current).*/,
58-
triggerFn: () => cy.accordionItem('Zone:', true, 'diagnostics_accord'),
99+
triggerFn: () =>
100+
cy.accordionItem(zoneAccordItem, true, diagnosticsAccordionItemId),
59101
currentApiIntercepts,
60102
});
61103
}
62104

63-
function invokeAndAwaitServerInfo({
64-
currentApiIntercepts,
65-
}) {
105+
function invokeAndAwaitServerInfo({ currentApiIntercepts }) {
66106
interceptAndAwaitApi({
67107
alias: 'getServerInfo',
68108
urlPattern: /ops\/tree_select\?id=.*&text=.*Server.*EVM.*(current).*/,
69-
triggerFn: () => cy.accordionItem('Server:', true, 'diagnostics_accord'),
109+
triggerFn: () =>
110+
cy.accordionItem(serverAccordItem, true, diagnosticsAccordionItemId),
70111
currentApiIntercepts,
71112
});
72113
}
73114

74-
function invokeAndAwaitCollectLogsTabInfo({
75-
currentApiIntercepts,
76-
}) {
115+
function invokeAndAwaitCollectLogsTabInfo({ currentApiIntercepts }) {
77116
interceptAndAwaitApi({
78117
alias: 'getCollectLogsTabInfo',
79118
urlPattern: '/ops/change_tab?tab_id=diagnostics_collect_logs',
@@ -87,9 +126,7 @@ function invokeAndAwaitCollectLogsTabInfo({
87126
});
88127
}
89128

90-
function invokeAndAwaitEditEventForServer({
91-
currentApiIntercepts,
92-
}) {
129+
function invokeAndAwaitEditEventForServer({ currentApiIntercepts }) {
93130
interceptAndAwaitApi({
94131
alias: 'editEventForServer',
95132
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
@@ -129,10 +166,10 @@ function resetProtocolDropdown({
129166
($select) => {
130167
const currentValue = $select.val();
131168
// If the value is not default one(BLANK_VALUE), then setting it to blank
132-
if (currentValue !== 'BLANK_VALUE') {
133-
cy.wrap($select).select('BLANK_VALUE');
169+
if (currentValue !== dropdownBlankValue) {
170+
cy.wrap($select).select(dropdownBlankValue);
134171
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="Submit"]')
135-
.contains('Save')
172+
.contains(saveButton)
136173
.click();
137174
cy.get('#main_div #flash_msg_div .alert-success').contains(
138175
'Log Depot Settings were saved'
@@ -145,7 +182,7 @@ function resetProtocolDropdown({
145182
function cancelButtonValidation() {
146183
// Click cancel button in the form
147184
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="button"]')
148-
.contains('Cancel')
185+
.contains(cancelButton)
149186
.should('be.enabled')
150187
.click();
151188
// Validating confirmation alert text displayed
@@ -157,36 +194,36 @@ function cancelButtonValidation() {
157194
function resetButtonValidation() {
158195
// Confirm Reset button is disabled initially
159196
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="button"]')
160-
.contains('Reset')
197+
.contains(resetButton)
161198
.should('be.disabled');
162199
// Selecting Samba option from dropdown
163200
cy.get('#log-depot-settings .bx--select select#log_protocol').select(
164-
'FileDepotSmb'
201+
sambaDropdownValue
165202
);
166203
// Confirm Reset button is enabled once dropdown value is changed and then click on Reset
167204
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="button"]')
168-
.contains('Reset')
205+
.contains(resetButton)
169206
.should('be.enabled')
170207
.click();
171208
// Confirm dropdown has the old value
172209
cy.get('#log-depot-settings .bx--select select#log_protocol').should(
173210
'have.value',
174-
'BLANK_VALUE'
211+
dropdownBlankValue
175212
);
176213
}
177214

178215
function saveButtonValidation() {
179216
// Confirm Save button is disabled initially
180217
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="Submit"]')
181-
.contains('Save')
218+
.contains(saveButton)
182219
.should('be.disabled');
183220
// Selecting Samba option from dropdown
184221
cy.get('#log-depot-settings .bx--select select#log_protocol').select(
185-
'FileDepotSmb'
222+
sambaDropdownValue
186223
);
187224
// Confirm Save button is enabled once dropdown value is changed and then click on Save
188225
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="Submit"]')
189-
.contains('Save')
226+
.contains(saveButton)
190227
.should('be.enabled')
191228
.click();
192229
// Validating confirmation alert text displayed
@@ -205,7 +242,7 @@ describe('Automate Collect logs Edit form operations', () => {
205242
registeredApiIntercepts = {};
206243
cy.login();
207244
// Navigate to Application settings and Select Diagnostics
208-
cy.menu('Settings', 'Application Settings');
245+
cy.menu(settingsMenuOption, appSettingsMenuOption);
209246
invokeAndAwaitDiagnosticsInfo();
210247
// Open ManageIQ Region: - list view if not already open
211248
invokeAndAwaitRegionInfo({ currentApiIntercepts: registeredApiIntercepts });
@@ -247,13 +284,13 @@ describe('Automate Collect logs Edit form operations', () => {
247284
after(() => {
248285
cy?.url()?.then((url) => {
249286
// Ensures navigation to Settings -> Application-Settings in the UI
250-
if (url?.includes('/ops/explorer')) {
287+
if (url?.includes(componentRouteUrl)) {
251288
resetProtocolDropdown({
252289
currentApiIntercepts: registeredApiIntercepts,
253290
});
254291
} else {
255292
// Navigate to Settings -> Application-Settings before selecting Diagnostics
256-
cy.menu('Settings', 'Application Settings');
293+
cy.menu(settingsMenuOption, appSettingsMenuOption);
257294
resetProtocolDropdown({
258295
currentApiIntercepts: registeredApiIntercepts,
259296
});
@@ -293,14 +330,14 @@ describe('Automate Collect logs Edit form operations', () => {
293330
after(() => {
294331
cy?.url()?.then((url) => {
295332
// Ensures navigation to Settings -> Application-Settings in the UI
296-
if (url?.includes('/ops/explorer')) {
333+
if (url?.includes(componentRouteUrl)) {
297334
resetProtocolDropdown({
298335
currentApiIntercepts: registeredApiIntercepts,
299336
needsServerInfoFetch: false,
300337
});
301338
} else {
302339
// Navigate to Settings -> Application-Settings before selecting Diagnostics
303-
cy.menu('Settings', 'Application Settings');
340+
cy.menu(settingsMenuOption, appSettingsMenuOption);
304341
resetProtocolDropdown({
305342
currentApiIntercepts: registeredApiIntercepts,
306343
needsServerInfoFetch: false,

0 commit comments

Comments
 (0)