Skip to content

Commit 9509dbd

Browse files
authored
Merge pull request #9575 from asirvadAbrahamVarghese/edit-collect-logs-form-cypress-refactor
Split textConstants object into individual variables
2 parents 893118b + d3b3a50 commit 9509dbd

File tree

1 file changed

+67
-108
lines changed

1 file changed

+67
-108
lines changed

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

Lines changed: 67 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,39 @@
11
/* eslint-disable no-undef */
2-
import { flashClassMap } from "../../../../support/assertions/assertion_constants";
2+
import { flashClassMap } from '../../../../support/assertions/assertion_constants';
33

4-
const textConstants = {
5-
// Component route url
6-
componentRouteUrl: '/ops/explorer',
4+
// Component route url
5+
const COMPONENT_ROUTE_URL = '/ops/explorer';
76

8-
// Menu options
9-
settingsMenuOption: 'Settings',
10-
appSettingsMenuOption: 'Application Settings',
7+
// Menu options
8+
const SETTINGS_MENU_OPTION = 'Settings';
9+
const APP_SETTINGS_MENU_OPTION = 'Application Settings';
1110

12-
// List items
13-
diagnosticsAccordionItem: 'Diagnostics',
14-
diagnosticsAccordionItemId: 'diagnostics_accord',
15-
manageIQRegionAccordItem: /^ManageIQ Region:/,
16-
zoneAccordItem: /^Zone:/,
17-
serverAccordItem: /^Server:/,
11+
// List items
12+
const DIAGNOSTICS_ACCORDION_ITEM = 'Diagnostics';
13+
const DIAGNOSTICS_ACCORDION_ITEM_ID = 'diagnostics_accord';
14+
const MANAGEIQ_REGION_ACCORDION_ITEM = /^ManageIQ Region:/;
15+
const ZONE_ACCORDION_ITEM = /^Zone:/;
16+
const SERVER_ACCORDION_ITEM = /^Server:/;
1817

19-
// Field values
20-
formHeader: 'Editing Log Depot settings',
21-
formSubheaderSnippet: 'Editing Log Depot Settings',
18+
// Field values
19+
const FORM_HEADER = 'Editing Log Depot settings';
20+
const FORM_SUBHEADER_SNIPPET = 'Editing Log Depot Settings';
2221

23-
// Config options
24-
editToolbarButton: 'Edit',
22+
// Config options
23+
const EDIT_TOOLBAR_BUTTON = 'Edit';
2524

26-
// Buttons
27-
saveButton: 'Save',
28-
cancelButton: 'Cancel',
29-
resetButton: 'Reset',
25+
// Buttons
26+
const SAVE_BUTTON_TEXT = 'Save';
27+
const CANCEL_BUTTON_TEXT = 'Cancel';
28+
const RESET_BUTTON_TEXT = 'Reset';
3029

31-
// Common element IDs
32-
protocolSelectFieldId: 'log_protocol',
30+
// Dropdown values
31+
const DROPDOWN_BLANK_VALUE = 'BLANK_VALUE';
32+
const SAMBA_DROPDOWN_VALUE = 'FileDepotSmb';
3333

34-
// Dropdown values
35-
dropdownBlankValue: 'BLANK_VALUE',
36-
sambaDropdownValue: 'FileDepotSmb',
37-
38-
// Flash message text snippets
39-
flashMessageSettingsSaved: 'saved',
40-
flashMessageOperationCancelled: 'cancel',
41-
};
42-
43-
const {
44-
// Component route url
45-
componentRouteUrl,
46-
47-
// Menu options
48-
settingsMenuOption,
49-
appSettingsMenuOption,
50-
51-
// List items
52-
diagnosticsAccordionItem,
53-
diagnosticsAccordionItemId,
54-
manageIQRegionAccordItem,
55-
zoneAccordItem,
56-
serverAccordItem,
57-
58-
// Field values
59-
formHeader,
60-
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,
80-
} = textConstants;
34+
// Flash message text snippets
35+
const FLASH_MESSAGE_SETTINGS_SAVED = 'saved';
36+
const FLASH_MESSAGE_OPERATION_CANCELLED = 'cancel';
8137

8238
function goToCollectLogsTab() {
8339
cy.interceptApi({
@@ -97,32 +53,32 @@ function selectToolbarEditButton() {
9753
alias: 'editEventForServer',
9854
// This pattern matches both /ops/x_button/1?pressed=log_depot_edit & /ops/x_button/2?pressed=zone_log_depot_edit endpoints
9955
urlPattern: /\/ops\/x_button\/[^/]+\?pressed=.*log_depot_edit/,
100-
triggerFn: () => cy.toolbar(editToolbarButton),
56+
triggerFn: () => cy.toolbar(EDIT_TOOLBAR_BUTTON),
10157
});
10258
}
10359

10460
function resetProtocolDropdown({ selectServerListItem = true } = {}) {
10561
// Select Diagnostics
106-
cy.accordion(diagnosticsAccordionItem);
62+
cy.accordion(DIAGNOSTICS_ACCORDION_ITEM);
10763
// Select "Zone:" or "Server:" accordion item
10864
cy.selectAccordionItem([
109-
manageIQRegionAccordItem,
110-
zoneAccordItem,
111-
...(selectServerListItem ? [serverAccordItem] : []),
65+
MANAGEIQ_REGION_ACCORDION_ITEM,
66+
ZONE_ACCORDION_ITEM,
67+
...(selectServerListItem ? [SERVER_ACCORDION_ITEM] : []),
11268
]);
11369

11470
// Clicking Edit button
11571
selectToolbarEditButton();
11672

11773
// Resetting Protocol dropdown value
118-
cy.getFormSelectFieldById(protocolSelectFieldId).then((selectField) => {
74+
cy.getFormSelectFieldById('log_protocol').then((selectField) => {
11975
const currentValue = selectField.val();
12076
// If the value is not default one(BLANK_VALUE), then setting it to blank
121-
if (currentValue !== dropdownBlankValue) {
122-
cy.wrap(selectField).select(dropdownBlankValue);
123-
cy.getFormFooterButtonByType(saveButton, 'submit').click();
77+
if (currentValue !== DROPDOWN_BLANK_VALUE) {
78+
cy.wrap(selectField).select(DROPDOWN_BLANK_VALUE);
79+
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit').click();
12480
// Validating confirmation flash message
125-
cy.expect_flash(flashClassMap.success, flashMessageSettingsSaved);
81+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SETTINGS_SAVED);
12682
}
12783
});
12884
}
@@ -136,80 +92,80 @@ function goToCollectLogsTabAndOpenEditForm() {
13692

13793
function validateFormElements() {
13894
// Assert form header is visible
139-
cy.expect_explorer_title(formHeader).should('be.visible');
95+
cy.expect_explorer_title(FORM_HEADER).should('be.visible');
14096
// Assert form sub-header is visible
141-
cy.contains('#main-content .bx--form h3', formSubheaderSnippet).should(
97+
cy.contains('#main-content .bx--form h3', FORM_SUBHEADER_SNIPPET).should(
14298
'be.visible'
14399
);
144100
// Assert protocol field label is visible
145-
cy.getFormLabelByInputId(protocolSelectFieldId).should('be.visible');
101+
cy.getFormLabelByInputId('log_protocol').should('be.visible');
146102
// Assert protocol field is visible and enabled
147-
cy.getFormSelectFieldById(protocolSelectFieldId)
103+
cy.getFormSelectFieldById('log_protocol')
148104
.should('be.visible')
149105
.and('be.enabled');
150106
// Assert cancel button is visible and enabled
151-
cy.getFormFooterButtonByType(cancelButton)
107+
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT)
152108
.should('be.visible')
153109
.and('be.enabled');
154110
// Assert save button is visible and disabled
155-
cy.getFormFooterButtonByType(saveButton, 'submit')
111+
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
156112
.should('be.visible')
157113
.and('be.disabled');
158114
// Assert reset button is visible and disabled
159-
cy.getFormFooterButtonByType(resetButton)
115+
cy.getFormFooterButtonByType(RESET_BUTTON_TEXT)
160116
.should('be.visible')
161117
.and('be.disabled');
162118
}
163119

164120
function cancelButtonValidation() {
165121
// Click cancel button in the form
166-
cy.getFormFooterButtonByType(cancelButton).click();
122+
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT).click();
167123
// Validating confirmation flash message
168-
cy.expect_flash(flashClassMap.success, flashMessageOperationCancelled);
124+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_OPERATION_CANCELLED);
169125
}
170126

171127
function resetButtonValidation() {
172128
// Selecting Samba option from dropdown
173-
cy.getFormSelectFieldById(protocolSelectFieldId).select(sambaDropdownValue);
129+
cy.getFormSelectFieldById('log_protocol').select(SAMBA_DROPDOWN_VALUE);
174130
// Confirm Reset button is enabled once dropdown value is changed and then click on Reset
175-
cy.getFormFooterButtonByType(resetButton).should('be.enabled').click();
131+
cy.getFormFooterButtonByType(RESET_BUTTON_TEXT).should('be.enabled').click();
176132
// Confirm dropdown has the old value
177-
cy.getFormSelectFieldById(protocolSelectFieldId).should(
133+
cy.getFormSelectFieldById('log_protocol').should(
178134
'have.value',
179-
dropdownBlankValue
135+
DROPDOWN_BLANK_VALUE
180136
);
181137
}
182138

183139
function saveButtonValidation() {
184140
// Selecting Samba option from dropdown
185-
cy.getFormSelectFieldById(protocolSelectFieldId).select(sambaDropdownValue);
141+
cy.getFormSelectFieldById('log_protocol').select(SAMBA_DROPDOWN_VALUE);
186142
// Confirm Save button is enabled once dropdown value is changed and then click on Save
187-
cy.getFormFooterButtonByType(saveButton, 'submit')
143+
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
188144
.should('be.enabled')
189145
.click();
190146
// Validating confirmation flash message
191-
cy.expect_flash(flashClassMap.success, flashMessageSettingsSaved);
147+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SETTINGS_SAVED);
192148
}
193149

194150
describe('Automate Collect logs Edit form operations', () => {
195151
beforeEach(() => {
196152
cy.login();
197153
// Navigate to Application settings and expand Diagnostics accordion
198-
cy.menu(settingsMenuOption, appSettingsMenuOption);
154+
cy.menu(SETTINGS_MENU_OPTION, APP_SETTINGS_MENU_OPTION);
199155
cy.interceptApi({
200156
alias: 'getDiagnosticsInfo',
201-
urlPattern: `/ops/accordion_select?id=${diagnosticsAccordionItemId}`,
202-
triggerFn: () => cy.accordion(diagnosticsAccordionItem),
157+
urlPattern: `/ops/accordion_select?id=${DIAGNOSTICS_ACCORDION_ITEM_ID}`,
158+
triggerFn: () => cy.accordion(DIAGNOSTICS_ACCORDION_ITEM),
203159
});
204160
});
205161

206162
describe('Settings > Application Settings > Diagnostics > Manage IQ Region > Zone > Server > Collect logs > Edit', () => {
207163
beforeEach(() => {
208164
// Select "Server:" accordion item
209165
cy.selectAccordionItem([
210-
manageIQRegionAccordItem,
211-
zoneAccordItem,
212-
serverAccordItem,
166+
MANAGEIQ_REGION_ACCORDION_ITEM,
167+
ZONE_ACCORDION_ITEM,
168+
SERVER_ACCORDION_ITEM,
213169
]);
214170
// Select collect logs navbar and open edit form
215171
goToCollectLogsTabAndOpenEditForm();
@@ -234,9 +190,9 @@ describe('Automate Collect logs Edit form operations', () => {
234190
cy.url()
235191
?.then((url) => {
236192
// Ensures navigation to Settings -> Application-Settings in the UI
237-
if (!url?.includes(componentRouteUrl)) {
193+
if (!url?.includes(COMPONENT_ROUTE_URL)) {
238194
// Navigate to Settings -> Application-Settings before cleanup
239-
cy.menu(settingsMenuOption, appSettingsMenuOption);
195+
cy.menu(SETTINGS_MENU_OPTION, APP_SETTINGS_MENU_OPTION);
240196
}
241197
})
242198
.then(() => {
@@ -253,7 +209,10 @@ describe('Automate Collect logs Edit form operations', () => {
253209
urlPattern:
254210
/ops\/tree_select\?id=.*&text=.*Zone.*Default.*Zone.*(current).*/,
255211
triggerFn: () =>
256-
cy.selectAccordionItem([manageIQRegionAccordItem, zoneAccordItem]),
212+
cy.selectAccordionItem([
213+
MANAGEIQ_REGION_ACCORDION_ITEM,
214+
ZONE_ACCORDION_ITEM,
215+
]),
257216
});
258217
// Select collect logs tab and open edit form
259218
goToCollectLogsTabAndOpenEditForm();
@@ -278,9 +237,9 @@ describe('Automate Collect logs Edit form operations', () => {
278237
cy.url()
279238
?.then((url) => {
280239
// Ensures navigation to Settings -> Application-Settings in the UI
281-
if (!url?.includes(componentRouteUrl)) {
240+
if (!url?.includes(COMPONENT_ROUTE_URL)) {
282241
// Navigate to Settings -> Application-Settings before cleanup
283-
cy.menu(settingsMenuOption, appSettingsMenuOption);
242+
cy.menu(SETTINGS_MENU_OPTION, APP_SETTINGS_MENU_OPTION);
284243
}
285244
})
286245
.then(() => {

0 commit comments

Comments
 (0)