@@ -5,8 +5,8 @@ const textConstants = {
5
5
schedulesAccordionItem : 'Schedules' ,
6
6
7
7
// Field values
8
- initialScheduleName : 'Test name' ,
9
- editedScheduleName : 'Dummy name' ,
8
+ initialScheduleName : 'Test- name' ,
9
+ editedScheduleName : 'Dummy- name' ,
10
10
initialDescription : 'Test description' ,
11
11
editedDescription : 'Dummy description' ,
12
12
actionTypeVmAnalysis : 'vm' ,
@@ -152,15 +152,20 @@ function addSchedule() {
152
152
. click ( ) ;
153
153
cy . get ( 'input#start_date' ) . type ( initialStartDate ) ;
154
154
cy . get ( 'input#start_time' ) . type ( startTime ) ;
155
- // Checks if Save button is enabled once all required fields are filled
155
+ // Intercepting the API call for adding a new schedule
156
+ cy . intercept ( 'POST' , '/ops/schedule_edit/new?button=save' ) . as (
157
+ 'addScheduleApi'
158
+ ) ;
156
159
cy . contains ( '#main-content .bx--btn-set button[type="submit"]' , saveButton )
157
- . should ( 'be.enabled' )
160
+ . should ( 'be.enabled' ) // Checks if Save button is enabled once all required fields are filled
158
161
. click ( ) ;
162
+ // Wait for the API call to complete
163
+ cy . wait ( '@addScheduleApi' ) ;
159
164
}
160
165
161
166
function deleteSchedule ( scheduleName = initialScheduleName ) {
162
- // Selecting the schedule
163
- cy . accordionItem ( scheduleName ) ;
167
+ // Selecting the schedule and intercepting the API call to get schedule details
168
+ interceptGetScheduleDetailsApi ( scheduleName ) ;
164
169
// Listening for the browser confirm alert and confirming deletion
165
170
cy . expect_browser_confirm_with_text ( {
166
171
confirmTriggerFn : ( ) => selectConfigMenu ( deleteScheduleConfigOption ) ,
@@ -169,6 +174,33 @@ function deleteSchedule(scheduleName = initialScheduleName) {
169
174
cy . expect_flash ( flashTypeSuccess , flashMessageScheduleDeleted ) ;
170
175
}
171
176
177
+ function interceptGetScheduleDetailsApi ( scheduleName = initialScheduleName ) {
178
+ // Flag to check if the request is fired
179
+ let requestFired = false ;
180
+ // Intercepting the API call
181
+ cy . intercept (
182
+ {
183
+ method : 'POST' ,
184
+ pathname : '/ops/tree_select' ,
185
+ query : { text : scheduleName } ,
186
+ } ,
187
+ // This callback function will be called when the request is fired,
188
+ // from which the requestFired flag will be set to true
189
+ ( ) => ( requestFired = true )
190
+ ) . as ( 'getCreatedScheduleApi' ) ;
191
+ // Triggering the action that will fire the API call,
192
+ // which is selecting the created schedule
193
+ cy . accordionItem ( scheduleName ) ;
194
+ // Wait for the API call to complete if it was fired
195
+ // This is to ensure that the test does not fail if the request was not fired
196
+ cy . then ( ( ) => {
197
+ // If the request was fired, wait for the alias
198
+ if ( requestFired ) {
199
+ cy . wait ( '@getCreatedScheduleApi' ) ;
200
+ }
201
+ } ) ;
202
+ }
203
+
172
204
function invokeCleanupDeletion ( ) {
173
205
// Iterate and clean up any leftover schedules created during the test
174
206
cy . get ( 'li.list-group-item' ) . each ( ( $el ) => {
@@ -199,9 +231,13 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
199
231
beforeEach ( ( ) => {
200
232
cy . login ( ) ;
201
233
cy . menu ( settingsMenuOption , appSettingsMenuOption ) ;
202
- cy . intercept ( 'POST' , '/ops/tree_select?id=xx-msc&text=Schedules' ) . as (
203
- 'getSchedules'
204
- ) ;
234
+ cy . intercept (
235
+ {
236
+ method : 'POST' ,
237
+ pathname : '/ops/tree_select' ,
238
+ query : { text : schedulesAccordionItem } ,
239
+ } ,
240
+ ) . as ( 'getSchedules' ) ;
205
241
cy . accordionItem ( schedulesAccordionItem ) ;
206
242
cy . wait ( '@getSchedules' ) ;
207
243
} ) ;
@@ -360,8 +396,8 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
360
396
cy . expect_flash ( flashTypeSuccess , flashMessageScheduleSaved ) ;
361
397
362
398
/* ===== Editing a schedule ===== */
363
- // Selecting the created schedule
364
- cy . accordionItem ( initialScheduleName ) ;
399
+ // Selecting the schedule and intercepting the API call to get schedule details
400
+ interceptGetScheduleDetailsApi ( ) ;
365
401
selectConfigMenu ( editScheduleConfigOption ) ;
366
402
// Editing name and description
367
403
cy . get ( 'input#name' ) . clear ( ) . type ( editedScheduleName ) ;
@@ -380,8 +416,8 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
380
416
addSchedule ( ) ;
381
417
382
418
/* ===== Checking whether Cancel button works ===== */
383
- // Selecting the created schedule
384
- cy . accordionItem ( initialScheduleName ) ;
419
+ // Selecting the schedule and intercepting the API call to get schedule details
420
+ interceptGetScheduleDetailsApi ( ) ;
385
421
selectConfigMenu ( editScheduleConfigOption ) ;
386
422
cy . contains (
387
423
'#main-content .bx--btn-set button[type="button"]' ,
@@ -392,8 +428,8 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
392
428
cy . expect_flash ( flashTypeSuccess , flashMessageOperationCanceled ) ;
393
429
394
430
/* ===== Checking whether Reset button works ===== */
395
- // Selecting the created schedule
396
- cy . accordionItem ( initialScheduleName ) ;
431
+ // Selecting the schedule and intercepting the API call to get schedule details
432
+ interceptGetScheduleDetailsApi ( ) ;
397
433
selectConfigMenu ( editScheduleConfigOption ) ;
398
434
// Editing description and start date
399
435
cy . get ( 'input#description' ) . clear ( ) . type ( editedDescription ) ;
@@ -422,8 +458,8 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
422
458
it ( 'Checking whether Disabling, Enabling & Queueing up the schedule works' , ( ) => {
423
459
/* ===== Adding a schedule ===== */
424
460
addSchedule ( ) ;
425
- // Selecting the created schedule
426
- cy . accordionItem ( initialScheduleName ) ;
461
+ // Selecting the schedule and intercepting the API call to get schedule details
462
+ interceptGetScheduleDetailsApi ( ) ;
427
463
428
464
/* ===== Disabling the schedule ===== */
429
465
selectConfigMenu ( disableScheduleConfigOption ) ;
0 commit comments