11/* eslint-disable no-undef */
22
3- function addSchedule ( ) {
3+ function selectConfigMenu ( configuration = 'Add a new Schedule' ) {
44 cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
5- cy . get ( 'ul[aria-label="Configuration"] [title="Add a new Schedule"]' ) . click ( ) ;
5+ cy . get ( `ul[aria-label="Configuration"] [title="${ configuration } "]` ) . click ( ) ;
6+ }
7+
8+ function addSchedule ( ) {
9+ selectConfigMenu ( ) ;
610 // Checks if Save button is disabled initially
711 cy . contains (
812 '#main-content .bx--btn-set button[type="submit"]' ,
@@ -28,19 +32,30 @@ function addSchedule() {
2832 . click ( ) ;
2933}
3034
35+ function deleteSchedule ( scheduleName = 'Test name' ) {
36+ // Selecting the schedule
37+ cy . contains ( 'li.list-group-item' , scheduleName ) . click ( ) ;
38+ cy . on ( 'window:confirm' , ( text ) => {
39+ expect ( text ) . to . eq (
40+ 'Warning: This Schedule and ALL of its components will be permanently removed!'
41+ ) ;
42+ return true ;
43+ } ) ;
44+ selectConfigMenu ( 'Delete this Schedule from the Database' ) ;
45+ cy . get ( '#main_div #flash_msg_div .alert-success' ) . contains (
46+ `Schedule "${ scheduleName } ": Delete successful`
47+ ) ;
48+ }
49+
3150describe ( 'Automate Schedule form operations: Settings > Application Settings > Settings > Schedules > Configuration > Add a new schedule' , ( ) => {
3251 beforeEach ( ( ) => {
3352 cy . login ( ) ;
3453 cy . menu ( 'Settings' , 'Application Settings' ) ;
35- cy . get ( '[title="Schedules"]' )
36- . click ( ) ;
54+ cy . get ( '[title="Schedules"]' ) . click ( ) ;
3755 } ) ;
3856
3957 it ( 'Validate visibility of elements based on dropdown selections' , ( ) => {
40- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
41- cy . get (
42- 'ul[aria-label="Configuration"] [title="Add a new Schedule"]'
43- ) . click ( ) ;
58+ selectConfigMenu ( ) ;
4459
4560 /* ===== Selecting any option other than "Automation Tasks" from "Action" dropdown does not hide the Filter dropdown ===== */
4661
@@ -175,10 +190,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
175190 } ) ;
176191
177192 it ( 'Checking whether Cancel button works on the Add form' , ( ) => {
178- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
179- cy . get (
180- 'ul[aria-label="Configuration"] [title="Add a new Schedule"]'
181- ) . click ( ) ;
193+ selectConfigMenu ( ) ;
182194 cy . contains ( '#main-content .bx--btn-set button[type="button"]' , 'Cancel' )
183195 . should ( 'be.enabled' )
184196 . click ( ) ;
@@ -187,42 +199,51 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
187199 ) ;
188200 } ) ;
189201
190- it ( 'Checking whether adding a schedule works' , ( ) => {
202+ it ( 'Checking whether add, edit & delete schedule works' , ( ) => {
203+ /* ===== Adding a schedule ===== */
191204 addSchedule ( ) ;
192205 cy . get ( '#main_div #flash_msg_div .alert-success' ) . contains (
193206 'Schedule "Test name" was saved'
194207 ) ;
195- } ) ;
196208
197- it ( 'Checking whether creating a duplicate record is restricted' , ( ) => {
198- addSchedule ( ) ;
199- cy . get ( '#main_div #flash_msg_div .alert-danger' ) . contains (
200- 'Error when adding a new schedule: Validation failed: MiqSchedule: Name has already been taken'
209+ /* ===== Editing a schedule ===== */
210+ // Selecting the created schedule
211+ cy . contains ( 'li.list-group-item' , 'Test name' ) . click ( ) ;
212+ selectConfigMenu ( 'Edit this Schedule' ) ;
213+ // Editing name and description
214+ cy . get ( 'input#name' ) . clear ( ) . type ( 'Dummy name' ) ;
215+ cy . get ( 'input#description' ) . clear ( ) . type ( 'Dummy description' ) ;
216+ // Confirms Save button is enabled after making edits
217+ cy . contains ( '#main-content .bx--btn-set button[type="submit"]' , 'Save' )
218+ . should ( 'be.enabled' )
219+ . click ( ) ;
220+ cy . get ( '#main_div #flash_msg_div .alert-success' ) . contains (
221+ 'Schedule "Dummy name" was saved'
201222 ) ;
223+
224+ /* ===== Deleting schedule ===== */
225+ deleteSchedule ( 'Dummy name' ) ;
202226 } ) ;
203227
204- it ( 'Checking whether Cancel button works on the Edit form' , ( ) => {
228+ it ( 'Checking whether Cancel & Reset buttons work fine in the Edit form' , ( ) => {
229+ /* ===== Adding a schedule ===== */
230+ addSchedule ( ) ;
231+
232+ /* ===== Checking whether Cancel button works ===== */
205233 // Selecting the created schedule
206234 cy . contains ( 'li.list-group-item' , 'Test name' ) . click ( ) ;
207- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
208- cy . get (
209- 'ul[aria-label="Configuration"] [title="Edit this Schedule"]'
210- ) . click ( ) ;
235+ selectConfigMenu ( 'Edit this Schedule' ) ;
211236 cy . contains ( '#main-content .bx--btn-set button[type="button"]' , 'Cancel' )
212237 . should ( 'be.enabled' )
213238 . click ( ) ;
214239 cy . get ( '#main_div #flash_msg_div .alert-success' ) . contains (
215240 'Edit of "Test name" was cancelled by the user'
216241 ) ;
217- } ) ;
218242
219- it ( ' Checking whether Reset button works on the Edit form' , ( ) => {
243+ /* ===== Checking whether Reset button works ===== */
220244 // Selecting the created schedule
221245 cy . contains ( 'li.list-group-item' , 'Test name' ) . click ( ) ;
222- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
223- cy . get (
224- 'ul[aria-label="Configuration"] [title="Edit this Schedule"]'
225- ) . click ( ) ;
246+ selectConfigMenu ( 'Edit this Schedule' ) ;
226247 // Editing description and start date
227248 cy . get ( 'input#description' ) . clear ( ) . type ( 'Dummy description' ) ;
228249 cy . get ( 'input#start_date' ) . clear ( ) . type ( '07/21/2025' , { force : true } ) ;
@@ -235,77 +256,51 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
235256 // Confirming the edited fields contain the old values after resetting
236257 cy . get ( 'input#description' ) . should ( 'have.value' , 'Test description' ) ;
237258 cy . get ( 'input#start_date' ) . should ( 'have.value' , '06/30/2025' ) ;
259+
260+ /* ===== Deleting schedule ===== */
261+ cy . get ( '[title="Schedules"]' ) . click ( ) ;
262+ deleteSchedule ( ) ;
238263 } ) ;
239264
240- it ( 'Checking whether Edit functionality works' , ( ) => {
241- // Selecting the created schedule
242- cy . contains ( 'li.list-group-item' , 'Test name' ) . click ( ) ;
243- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
244- cy . get (
245- 'ul[aria-label="Configuration"] [title="Edit this Schedule"]'
246- ) . click ( ) ;
247- // Editing name and description
248- cy . get ( 'input#name' ) . clear ( ) . type ( 'Dummy name' ) ;
249- cy . get ( 'input#description' ) . clear ( ) . type ( 'Dummy description' ) ;
250- // Confirms Save button is enabled after making edits
251- cy . contains ( '#main-content .bx--btn-set button[type="submit"]' , 'Save' )
252- . should ( 'be.enabled' )
253- . click ( ) ;
254- cy . get ( '#main_div #flash_msg_div .alert-success' ) . contains (
255- 'Schedule "Dummy name" was saved'
265+ it ( 'Checking whether creating a duplicate record is restricted' , ( ) => {
266+ /* ===== Adding schedule ===== */
267+ addSchedule ( ) ;
268+
269+ /* ===== Trying to add the same schedule again ===== */
270+ addSchedule ( ) ;
271+ cy . get ( '#main_div #flash_msg_div .alert-danger' ) . contains (
272+ 'Error when adding a new schedule: Validation failed: MiqSchedule: Name has already been taken'
256273 ) ;
274+
275+ /* ===== Deleting schedule ===== */
276+ deleteSchedule ( ) ;
257277 } ) ;
258278
259279 it ( 'Checking whether Disabling, Enabling & Queueing up the schedule works' , ( ) => {
260- // Selecting the schedule
261- cy . contains ( 'li.list-group-item' , 'Dummy name' ) . click ( ) ;
262-
263- /* ===== Disabling the Schedule ===== */
280+ /* ===== Adding a schedule ===== */
281+ addSchedule ( ) ;
282+ // Selecting the created schedule
283+ cy . contains ( 'li.list-group-item' , 'Test name' ) . click ( ) ;
264284
265- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
266- cy . get (
267- 'ul[aria-label="Configuration"] [title="Disable this Schedule"]'
268- ) . click ( ) ;
285+ /* ===== Disabling the schedule ===== */
286+ selectConfigMenu ( 'Disable this Schedule' ) ;
269287 cy . get ( '#main_div #flash_msg_div .alert-info' ) . contains (
270288 'The selected Schedules were disabled'
271289 ) ;
272290
273- /* ===== Enabling the Schedule ===== */
274-
275- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
276- cy . get (
277- 'ul[aria-label="Configuration"] [title="Enable this Schedule"]'
278- ) . click ( ) ;
291+ /* ===== Enabling the schedule ===== */
292+ selectConfigMenu ( 'Enable this Schedule' ) ;
279293 cy . get ( '#main_div #flash_msg_div .alert-info' ) . contains (
280294 'The selected Schedules were enabled'
281295 ) ;
282296
283- /* ===== Queueing-up the Schedule ===== */
284-
285- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
286- cy . get (
287- 'ul[aria-label="Configuration"] [title="Queue up this Schedule to run now"]'
288- ) . click ( ) ;
297+ /* ===== Queueing-up the schedule ===== */
298+ selectConfigMenu ( 'Queue up this Schedule to run now' ) ;
289299 cy . get ( '#main_div #flash_msg_div .alert-success' ) . contains (
290300 'The selected Schedule has been queued to run'
291301 ) ;
292- } ) ;
293302
294- it ( 'Checking whether Deleting the schedule works' , ( ) => {
295- // Selecting the schedule
296- cy . contains ( 'li.list-group-item' , 'Dummy name' ) . click ( ) ;
297- cy . get ( '#miq_schedule_vmdb_choice' ) . click ( ) ;
298- cy . on ( 'window:confirm' , ( text ) => {
299- expect ( text ) . to . eq (
300- 'Warning: This Schedule and ALL of its components will be permanently removed!'
301- ) ;
302- return true ;
303- } ) ;
304- cy . get (
305- 'ul[aria-label="Configuration"] [title="Delete this Schedule from the Database"]'
306- ) . click ( ) ;
307- cy . get ( '#main_div #flash_msg_div .alert-success' ) . contains (
308- 'Schedule "Dummy name": Delete successful'
309- ) ;
303+ /* ===== Deleting schedule ===== */
304+ deleteSchedule ( ) ;
310305 } ) ;
311306} ) ;
0 commit comments