@@ -251,13 +251,21 @@ describe('MachinesPageComponent', () => {
251
251
}
252
252
const getAuthorizedMachinesResp : any = { items : [ { hostname : 'zzz' } , { hostname : 'xxx' } ] , total : 2 }
253
253
const gmSpy = spyOn ( servicesApi , 'getMachines' )
254
+
255
+ // Prepare response for getMachines API being called by refreshUnauthorizedMachinesCount().
256
+ // refreshUnauthorizedMachinesCount() asks for details of only one unauthorized machine.
257
+ // The total unauthorized machines count is essential information here, not the detailed items themselves.
254
258
gmSpy . withArgs ( 0 , 1 , null , null , false ) . and . returnValue (
255
259
of ( {
256
260
items : [ { hostname : 'aaa' , id : 1 , address : 'addr1' } ] ,
257
261
total : 3 ,
258
262
} as any )
259
263
)
264
+ // Prepare response for getMachines API being called by loadMachines(), which lazily loads data for
265
+ // unauthorized machines table. Text and app filters are undefined.
260
266
gmSpy . withArgs ( 0 , 10 , undefined , undefined , false ) . and . returnValue ( of ( getUnauthorizedMachinesResp ) )
267
+ // Prepare response for getMachines API being called by loadMachines(), which lazily loads data for
268
+ // authorized machines table. Text and app filters are undefined.
261
269
gmSpy . withArgs ( 0 , 10 , undefined , undefined , true ) . and . returnValue ( of ( getAuthorizedMachinesResp ) )
262
270
263
271
// show unauthorized machines
@@ -277,6 +285,8 @@ describe('MachinesPageComponent', () => {
277
285
278
286
// get references to rows' checkboxes
279
287
const checkboxes = fixture . nativeElement . querySelectorAll ( '.p-checkbox' )
288
+ expect ( checkboxes ) . toBeTruthy ( )
289
+ expect ( checkboxes . length ) . toBeGreaterThanOrEqual ( 3 )
280
290
// checkboxes[0] is "select all" checkbox, skipped on purpose in this test
281
291
const firstCheckbox = checkboxes [ 1 ]
282
292
const secondCheckbox = checkboxes [ 2 ]
@@ -287,7 +297,12 @@ describe('MachinesPageComponent', () => {
287
297
fixture . detectChanges ( )
288
298
289
299
// get reference to "Authorize selected" button
290
- const bulkAuthorizeBtn = fixture . nativeElement . querySelectorAll ( '#authorize-selected-button' ) ?. [ 0 ]
300
+ const bulkAuthorizeBtnNodeList = fixture . nativeElement . querySelectorAll ( '#authorize-selected-button' )
301
+ expect ( bulkAuthorizeBtnNodeList ) . toBeTruthy ( )
302
+ expect ( bulkAuthorizeBtnNodeList . length ) . toEqual ( 1 )
303
+
304
+ const bulkAuthorizeBtn = bulkAuthorizeBtnNodeList [ 0 ]
305
+ expect ( bulkAuthorizeBtn ) . toBeTruthy ( )
291
306
292
307
// prepare 502 error response for the first machine of the bulk of machines to be authorized
293
308
const umSpy = spyOn ( servicesApi , 'updateMachine' )
@@ -298,7 +313,7 @@ describe('MachinesPageComponent', () => {
298
313
. and . returnValue ( of ( { hostname : 'bbb' , id : 2 , address : 'addr2' , authorized : true } as any ) )
299
314
300
315
// click "Authorize selected" button
301
- bulkAuthorizeBtn ? .dispatchEvent ( new Event ( 'click' ) )
316
+ bulkAuthorizeBtn . dispatchEvent ( new Event ( 'click' ) )
302
317
fixture . detectChanges ( )
303
318
304
319
// we expect that unauthorized machines list was not changed due to 502 error
@@ -362,20 +377,24 @@ describe('MachinesPageComponent', () => {
362
377
const gmSpy = spyOn ( servicesApi , 'getMachines' )
363
378
364
379
// this is only called once after authorizing selected machines
365
- // and after switching back to authorized machines view; in refreshUnauthorizedMachinesCount()
380
+ // and after switching back to authorized machines view; in refreshUnauthorizedMachinesCount().
381
+ // refreshUnauthorizedMachinesCount() asks for details of only one unauthorized machine.
382
+ // The total unauthorized machines count is essential information here, not the detailed items themselves.
366
383
gmSpy . withArgs ( 0 , 1 , null , null , false ) . and . returnValue (
367
384
of ( {
368
385
items : [ { hostname : 'bbb' , id : 2 , address : 'addr2' } ] ,
369
386
total : 2 ,
370
387
} as any )
371
388
)
372
389
373
- // called two times in loadMachines(event)
390
+ // called two times in loadMachines(event), which lazily loads data for
391
+ // unauthorized machines table. Text and app filters are undefined.
374
392
gmSpy
375
393
. withArgs ( 0 , 10 , undefined , undefined , false )
376
394
. and . returnValues ( of ( getUnauthorizedMachinesRespBefore ) , of ( getUnauthorizedMachinesRespAfter ) )
377
395
378
- // called one time in loadMachines(event)
396
+ // called one time in loadMachines(event), which lazily loads data for
397
+ // authorized machines table. Text and app filters are undefined.
379
398
gmSpy . withArgs ( 0 , 10 , undefined , undefined , true ) . and . returnValue ( of ( getAuthorizedMachinesRespAfter ) )
380
399
381
400
// show unauthorized machines
@@ -395,14 +414,21 @@ describe('MachinesPageComponent', () => {
395
414
396
415
// get references to rows' checkboxes
397
416
const checkboxes = fixture . nativeElement . querySelectorAll ( '.p-checkbox' )
417
+ expect ( checkboxes ) . toBeTruthy ( )
418
+ expect ( checkboxes . length ) . toBeGreaterThanOrEqual ( 1 )
398
419
const selectAllCheckbox = checkboxes [ 0 ]
399
420
400
421
// select all unauthorized machines
401
422
selectAllCheckbox . dispatchEvent ( new Event ( 'click' ) )
402
423
fixture . detectChanges ( )
403
424
404
425
// get reference to "Authorize selected" button
405
- const bulkAuthorizeBtn = fixture . nativeElement . querySelectorAll ( '#authorize-selected-button' ) ?. [ 0 ]
426
+ const bulkAuthorizeBtnNodeList = fixture . nativeElement . querySelectorAll ( '#authorize-selected-button' )
427
+ expect ( bulkAuthorizeBtnNodeList ) . toBeTruthy ( )
428
+ expect ( bulkAuthorizeBtnNodeList . length ) . toEqual ( 1 )
429
+
430
+ const bulkAuthorizeBtn = bulkAuthorizeBtnNodeList [ 0 ]
431
+ expect ( bulkAuthorizeBtn ) . toBeTruthy ( )
406
432
407
433
// prepare 502 error response for the second machine of the bulk of machines to be authorized
408
434
// first machine authorization shall succeed, third shall be skipped because it was after the 502 error
@@ -417,7 +443,7 @@ describe('MachinesPageComponent', () => {
417
443
. and . returnValue ( of ( { hostname : 'ccc' , id : 3 , address : 'addr3' , authorized : true } as any ) )
418
444
419
445
// click "Authorize selected" button
420
- bulkAuthorizeBtn ? .dispatchEvent ( new Event ( 'click' ) )
446
+ bulkAuthorizeBtn . dispatchEvent ( new Event ( 'click' ) )
421
447
fixture . detectChanges ( )
422
448
423
449
// we expect that first machine of the bulk was authorized but second and third were not due to 502 error
0 commit comments