Skip to content

Commit 3967d77

Browse files
Defined a variable for static strings to reduce duplication
1 parent 7fe6243 commit 3967d77

File tree

1 file changed

+183
-86
lines changed

1 file changed

+183
-86
lines changed

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

Lines changed: 183 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,90 @@
11
/* eslint-disable no-undef */
22

3-
function selectConfigMenu(configuration = 'Add a new Schedule') {
3+
const textConstants = {
4+
// Field values
5+
initialScheduleName: 'Test name',
6+
editedScheduleName: 'Dummy name',
7+
initialDescription: 'Test description',
8+
editedDescription: 'Dummy description',
9+
actionTypeVmAnalysis: 'vm',
10+
actionTypeTemplateAnalysis: 'miq_template',
11+
actionTypeHostAnalysis: 'host',
12+
actionTypeContainerAnalysis: 'container_image',
13+
actionTypeClusterAnalysis: 'emscluster',
14+
actionTypeDataStoreAnalysis: 'storage',
15+
actionTypeVmCompilanceCheck: 'vm_check_compliance',
16+
actionTypeHostCompilanceCheck: 'host_check_compliance',
17+
actionTypeContainerCompilanceCheck: 'container_image_check_compliance',
18+
actionTypeAutomationTasks: 'automation_request',
19+
filterTypeVmCluster: 'cluster',
20+
timerTypeOnce: 'Once',
21+
timerTypeHourly: 'Hourly',
22+
timerTypeDaily: 'Daily',
23+
timerTypeWeekly: 'Weekly',
24+
timerTypeMonthly: 'Monthly',
25+
frequencyTypeHour: '1 Hour',
26+
timezoneTypeHawaii: '(GMT-10:00) Hawaii',
27+
initialStartDate: '06/30/2025',
28+
editedStartDate: '07/21/2025',
29+
startTime: '11:23',
30+
31+
// Buttons
32+
saveButton: 'Save',
33+
cancelButton: 'Cancel',
34+
resetButton: 'Reset',
35+
36+
// Config options
37+
addScheduleConfigOption: 'Add a new Schedule',
38+
deleteScheduleConfigOption: 'Delete this Schedule from the Database',
39+
editScheduleConfigOption: 'Edit this Schedule',
40+
disableScheduleConfigOption: 'Disable this Schedule',
41+
enableScheduleConfigOption: 'Enable this Schedule',
42+
queueScheduleConfigOption: 'Queue up this Schedule to run now',
43+
44+
// Menu options
45+
settingsMenuOption: 'Settings',
46+
appSettingsMenuOption: 'Application Settings',
47+
};
48+
49+
const {
50+
settingsMenuOption,
51+
appSettingsMenuOption,
52+
actionTypeVmAnalysis,
53+
actionTypeTemplateAnalysis,
54+
actionTypeHostAnalysis,
55+
actionTypeContainerAnalysis,
56+
actionTypeClusterAnalysis,
57+
actionTypeDataStoreAnalysis,
58+
actionTypeVmCompilanceCheck,
59+
actionTypeHostCompilanceCheck,
60+
actionTypeContainerCompilanceCheck,
61+
actionTypeAutomationTasks,
62+
timerTypeOnce,
63+
timerTypeHourly,
64+
timerTypeDaily,
65+
timerTypeWeekly,
66+
timerTypeMonthly,
67+
cancelButton,
68+
saveButton,
69+
initialScheduleName,
70+
editScheduleConfigOption,
71+
editedScheduleName,
72+
editedDescription,
73+
editedStartDate,
74+
resetButton,
75+
initialDescription,
76+
initialStartDate,
77+
disableScheduleConfigOption,
78+
enableScheduleConfigOption,
79+
queueScheduleConfigOption,
80+
addScheduleConfigOption,
81+
frequencyTypeHour,
82+
timezoneTypeHawaii,
83+
startTime,
84+
deleteScheduleConfigOption,
85+
} = textConstants;
86+
87+
function selectConfigMenu(configuration = addScheduleConfigOption) {
488
cy.get('#miq_schedule_vmdb_choice').click();
589
cy.get(`ul[aria-label="Configuration"] [title="${configuration}"]`).click();
690
}
@@ -10,31 +94,36 @@ function addSchedule() {
1094
// Checks if Save button is disabled initially
1195
cy.contains(
1296
'#main-content .bx--btn-set button[type="submit"]',
13-
'Save'
97+
saveButton
1498
).should('be.disabled');
1599
// Adding data
16-
cy.get('input#name').type('Test name');
17-
cy.get('input#description').type('Test description');
100+
cy.get('input#name').type(initialScheduleName);
101+
cy.get('input#description').type(initialDescription);
18102
cy.get('input[type="checkbox"]#enabled').check({ force: true });
19-
cy.get('select#action_typ').select('VM Analysis');
20-
cy.get('select#filter_typ').select('A single VM');
21-
cy.get('select#timer_typ').select('Hourly');
22-
cy.get('select#timer_value').select('1 Hour');
103+
// Select Action type option: 'VM Analysis'
104+
cy.get('select#action_typ').select(actionTypeVmAnalysis);
105+
// Select Filter type option: 'A Single VM'
106+
cy.get('select#filter_typ').select(actionTypeVmAnalysis);
107+
// Select Run option: 'Hours'
108+
cy.get('select#timer_typ').select(timerTypeHourly);
109+
// Select Every option: '1 Hour'
110+
cy.get('select#timer_value').select(frequencyTypeHour);
111+
// Select Time zone option: '(GMT-10:00) Hawaii'
23112
cy.get('input[role="combobox"]#time_zone').click();
24-
cy.contains('[role="option"]', '(GMT-10:00) Hawaii')
113+
cy.contains('[role="option"]', timezoneTypeHawaii)
25114
.should('be.visible')
26115
.click();
27-
cy.get('input#start_date').type('06/30/2025');
28-
cy.get('input#start_time').type('11:23');
116+
cy.get('input#start_date').type(initialStartDate);
117+
cy.get('input#start_time').type(startTime);
29118
// Checks if Save button is enabled once all required fields are filled
30-
cy.contains('#main-content .bx--btn-set button[type="submit"]', 'Save')
119+
cy.contains('#main-content .bx--btn-set button[type="submit"]', saveButton)
31120
.should('be.enabled')
32121
.click();
33122
}
34123

35-
function deleteSchedule(scheduleName = 'Test name') {
124+
function deleteSchedule(scheduleName = initialScheduleName) {
36125
// Selecting the schedule
37-
cy.contains('li.list-group-item', scheduleName).click();
126+
cy.accordionItem(scheduleName);
38127
// Listening for the browser confirm alert and confirming
39128
cy.listen_for_browser_confirm_alert();
40129
selectConfigMenu(deleteScheduleConfigOption);
@@ -45,12 +134,12 @@ function invokeCleanupDeletion() {
45134
// Iterate and clean up any leftover schedules created during the test
46135
cy.get('li.list-group-item').each(($el) => {
47136
const text = $el?.text()?.trim();
48-
if (text === 'Test name') {
137+
if (text === initialScheduleName) {
49138
deleteSchedule();
50139
return false;
51140
}
52-
if (text === 'Dummy name') {
53-
deleteSchedule('Dummy name');
141+
if (text === editedScheduleName) {
142+
deleteSchedule(editedScheduleName);
54143
return false;
55144
}
56145
return true;
@@ -83,67 +172,73 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
83172

84173
/* ===== Selecting any option other than "Automation Tasks" from "Action" dropdown does not hide the Filter dropdown ===== */
85174

86-
cy.get('select#action_typ').select('VM Analysis');
87-
cy.get('select#action_typ').should('have.value', 'vm');
175+
cy.get('select#action_typ').select(actionTypeVmAnalysis);
176+
cy.get('select#action_typ').should('have.value', actionTypeVmAnalysis);
88177
// Checking for Filter type dropdown
89-
cy.get('label[for="filter_typ"]').should('exist');
90-
cy.get('select#filter_typ').should('exist');
178+
verifyFilterTypeDropdownExists();
91179

92-
cy.get('select#action_typ').select('Template Analysis');
93-
cy.get('select#action_typ').should('have.value', 'miq_template');
180+
cy.get('select#action_typ').select(actionTypeTemplateAnalysis);
181+
cy.get('select#action_typ').should(
182+
'have.value',
183+
actionTypeTemplateAnalysis
184+
);
94185
// Checking for Filter type dropdown
95-
cy.get('label[for="filter_typ"]').should('exist');
96-
cy.get('select#filter_typ').should('exist');
186+
verifyFilterTypeDropdownExists();
97187

98-
cy.get('select#action_typ').select('Host Analysis');
99-
cy.get('select#action_typ').should('have.value', 'host');
188+
cy.get('select#action_typ').select(actionTypeHostAnalysis);
189+
cy.get('select#action_typ').should('have.value', actionTypeHostAnalysis);
100190
// Checking for Filter type dropdown
101-
cy.get('label[for="filter_typ"]').should('exist');
102-
cy.get('select#filter_typ').should('exist');
191+
verifyFilterTypeDropdownExists();
103192

104-
cy.get('select#action_typ').select('Container Image Analysis');
105-
cy.get('select#action_typ').should('have.value', 'container_image');
193+
cy.get('select#action_typ').select(actionTypeContainerAnalysis);
194+
cy.get('select#action_typ').should(
195+
'have.value',
196+
actionTypeContainerAnalysis
197+
);
106198
// Checking for Filter type dropdown
107-
cy.get('label[for="filter_typ"]').should('exist');
108-
cy.get('select#filter_typ').should('exist');
199+
verifyFilterTypeDropdownExists();
109200

110-
cy.get('select#action_typ').select('Cluster Analysis');
111-
cy.get('select#action_typ').should('have.value', 'emscluster');
201+
cy.get('select#action_typ').select(actionTypeClusterAnalysis);
202+
cy.get('select#action_typ').should('have.value', actionTypeClusterAnalysis);
112203
// Checking for Filter type dropdown
113-
cy.get('label[for="filter_typ"]').should('exist');
114-
cy.get('select#filter_typ').should('exist');
204+
verifyFilterTypeDropdownExists();
115205

116-
cy.get('select#action_typ').select('Datastore Analysis');
117-
cy.get('select#action_typ').should('have.value', 'storage');
206+
cy.get('select#action_typ').select(actionTypeDataStoreAnalysis);
207+
cy.get('select#action_typ').should(
208+
'have.value',
209+
actionTypeDataStoreAnalysis
210+
);
118211
// Checking for Filter type dropdown
119-
cy.get('label[for="filter_typ"]').should('exist');
120-
cy.get('select#filter_typ').should('exist');
212+
verifyFilterTypeDropdownExists();
121213

122-
cy.get('select#action_typ').select('VM Compliance Check');
123-
cy.get('select#action_typ').should('have.value', 'vm_check_compliance');
214+
cy.get('select#action_typ').select(actionTypeVmCompilanceCheck);
215+
cy.get('select#action_typ').should(
216+
'have.value',
217+
actionTypeVmCompilanceCheck
218+
);
124219
// Checking for Filter type dropdown
125-
cy.get('label[for="filter_typ"]').should('exist');
126-
cy.get('select#filter_typ').should('exist');
220+
verifyFilterTypeDropdownExists();
127221

128-
cy.get('select#action_typ').select('Host Compliance Check');
129-
cy.get('select#action_typ').should('have.value', 'host_check_compliance');
222+
cy.get('select#action_typ').select(actionTypeHostCompilanceCheck);
223+
cy.get('select#action_typ').should(
224+
'have.value',
225+
actionTypeHostCompilanceCheck
226+
);
130227
// Checking for Filter type dropdown
131-
cy.get('label[for="filter_typ"]').should('exist');
132-
cy.get('select#filter_typ').should('exist');
228+
verifyFilterTypeDropdownExists();
133229

134-
cy.get('select#action_typ').select('Container Image Compliance Check');
230+
cy.get('select#action_typ').select(actionTypeContainerCompilanceCheck);
135231
cy.get('select#action_typ').should(
136232
'have.value',
137-
'container_image_check_compliance'
233+
actionTypeContainerCompilanceCheck
138234
);
139235
// Checking for Filter type dropdown
140-
cy.get('label[for="filter_typ"]').should('exist');
141-
cy.get('select#filter_typ').should('exist');
236+
verifyFilterTypeDropdownExists();
142237

143238
/* ===== Selecting "Automation Tasks" option from "Action" dropdown shows Zone, Object details & Object fields ===== */
144239

145-
cy.get('select#action_typ').select('Automation Tasks');
146-
cy.get('select#action_typ').should('have.value', 'automation_request');
240+
cy.get('select#action_typ').select(actionTypeAutomationTasks);
241+
cy.get('select#action_typ').should('have.value', actionTypeAutomationTasks);
147242

148243
// Checking for Zone dropdown
149244
cy.get('label[for="zone_id"]').should('exist');
@@ -186,36 +281,35 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
186281

187282
/* ===== Selecting "Once" option from "Run" dropdown does not show the "Every" dropdown ===== */
188283

189-
cy.get('select#timer_typ').select('Once');
284+
cy.get('select#timer_typ').select(timerTypeOnce);
190285
// Checking whether the Every dropdown is hidden
191286
cy.get('input#timer_value').should('not.exist');
192287

193288
/* ===== Selecting any other option other than "Once" from "Run" dropdown shows the "Every" dropdown ===== */
194289

195-
cy.get('select#timer_typ').select('Hours');
290+
cy.get('select#timer_typ').select(timerTypeHourly);
196291
// Checking whether the "Every" dropdown exist
197-
cy.get('label[for="timer_value"]').should('exist');
198-
cy.get('select#timer_value').should('exist');
292+
verifyTimerDropdownExists();
199293

200-
cy.get('select#timer_typ').select('Days');
294+
cy.get('select#timer_typ').select(timerTypeDaily);
201295
// Checking whether the "Every" dropdown exist
202-
cy.get('label[for="timer_value"]').should('exist');
203-
cy.get('select#timer_value').should('exist');
296+
verifyTimerDropdownExists();
204297

205-
cy.get('select#timer_typ').select('Weeks');
298+
cy.get('select#timer_typ').select(timerTypeWeekly);
206299
// Checking whether the "Every" dropdown exist
207-
cy.get('label[for="timer_value"]').should('exist');
208-
cy.get('select#timer_value').should('exist');
300+
verifyTimerDropdownExists();
209301

210-
cy.get('select#timer_typ').select('Months');
302+
cy.get('select#timer_typ').select(timerTypeMonthly);
211303
// Checking whether the "Every" dropdown exist
212-
cy.get('label[for="timer_value"]').should('exist');
213-
cy.get('select#timer_value').should('exist');
304+
verifyTimerDropdownExists();
214305
});
215306

216307
it('Checking whether Cancel button works on the Add form', () => {
217308
selectConfigMenu();
218-
cy.contains('#main-content .bx--btn-set button[type="button"]', 'Cancel')
309+
cy.contains(
310+
'#main-content .bx--btn-set button[type="button"]',
311+
cancelButton
312+
)
219313
.should('be.enabled')
220314
.click();
221315
cy.expect_flash('success');
@@ -228,13 +322,13 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
228322

229323
/* ===== Editing a schedule ===== */
230324
// Selecting the created schedule
231-
cy.contains('li.list-group-item', 'Test name').click();
232-
selectConfigMenu('Edit this Schedule');
325+
cy.accordionItem(initialScheduleName);
326+
selectConfigMenu(editScheduleConfigOption);
233327
// Editing name and description
234-
cy.get('input#name').clear().type('Dummy name');
235-
cy.get('input#description').clear().type('Dummy description');
328+
cy.get('input#name').clear().type(editedScheduleName);
329+
cy.get('input#description').clear().type(editedDescription);
236330
// Confirms Save button is enabled after making edits
237-
cy.contains('#main-content .bx--btn-set button[type="submit"]', 'Save')
331+
cy.contains('#main-content .bx--btn-set button[type="submit"]', saveButton)
238332
.should('be.enabled')
239333
.click();
240334
cy.expect_flash('success');
@@ -248,27 +342,30 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
248342

249343
/* ===== Checking whether Cancel button works ===== */
250344
// Selecting the created schedule
251-
cy.contains('li.list-group-item', 'Test name').click();
252-
selectConfigMenu('Edit this Schedule');
253-
cy.contains('#main-content .bx--btn-set button[type="button"]', 'Cancel')
345+
cy.accordionItem(initialScheduleName);
346+
selectConfigMenu(editScheduleConfigOption);
347+
cy.contains(
348+
'#main-content .bx--btn-set button[type="button"]',
349+
cancelButton
350+
)
254351
.should('be.enabled')
255352
.click();
256353
cy.expect_flash('success');
257354

258355
/* ===== Checking whether Reset button works ===== */
259356
// Selecting the created schedule
260-
cy.contains('li.list-group-item', 'Test name').click();
261-
selectConfigMenu('Edit this Schedule');
357+
cy.accordionItem(initialScheduleName);
358+
selectConfigMenu(editScheduleConfigOption);
262359
// Editing description and start date
263-
cy.get('input#description').clear().type('Dummy description');
264-
cy.get('input#start_date').clear().type('07/21/2025');
265-
cy.contains('#main-content .bx--btn-set button[type="button"]', 'Reset')
360+
cy.get('input#description').clear().type(editedDescription);
361+
cy.get('input#start_date').clear().type(editedStartDate);
362+
cy.contains('#main-content .bx--btn-set button[type="button"]', resetButton)
266363
.should('be.enabled')
267364
.click();
268365
cy.expect_flash('warning');
269366
// Confirming the edited fields contain the old values after resetting
270-
cy.get('input#description').should('have.value', 'Test description');
271-
cy.get('input#start_date').should('have.value', '06/30/2025');
367+
cy.get('input#description').should('have.value', initialDescription);
368+
cy.get('input#start_date').should('have.value', initialStartDate);
272369

273370
// Selecting Schedules menu item to bypass a bug, can be removed once #9505 is merged
274371
cy.get('[title="Schedules"]').click();
@@ -287,7 +384,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
287384
/* ===== Adding a schedule ===== */
288385
addSchedule();
289386
// Selecting the created schedule
290-
cy.contains('li.list-group-item', 'Test name').click();
387+
cy.accordionItem(initialScheduleName);
291388

292389
/* ===== Disabling the schedule ===== */
293390
selectConfigMenu(disableScheduleConfigOption);
@@ -309,7 +406,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
309406
invokeCleanupDeletion();
310407
} else {
311408
// Navigate to Settings -> Application-Settings before looking out for Schedules created during test
312-
cy.menu('Settings', 'Application Settings');
409+
cy.menu(settingsMenuOption, appSettingsMenuOption);
313410
invokeCleanupDeletion();
314411
}
315412
});

0 commit comments

Comments
 (0)