Skip to content

Commit dfca759

Browse files
committed
[#1324] addressed review comments
1 parent 0f5a5b1 commit dfca759

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

webui/src/app/machines-page/machines-page.component.spec.ts

+33-7
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,21 @@ describe('MachinesPageComponent', () => {
251251
}
252252
const getAuthorizedMachinesResp: any = { items: [{ hostname: 'zzz' }, { hostname: 'xxx' }], total: 2 }
253253
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.
254258
gmSpy.withArgs(0, 1, null, null, false).and.returnValue(
255259
of({
256260
items: [{ hostname: 'aaa', id: 1, address: 'addr1' }],
257261
total: 3,
258262
} as any)
259263
)
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.
260266
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.
261269
gmSpy.withArgs(0, 10, undefined, undefined, true).and.returnValue(of(getAuthorizedMachinesResp))
262270

263271
// show unauthorized machines
@@ -277,6 +285,8 @@ describe('MachinesPageComponent', () => {
277285

278286
// get references to rows' checkboxes
279287
const checkboxes = fixture.nativeElement.querySelectorAll('.p-checkbox')
288+
expect(checkboxes).toBeTruthy()
289+
expect(checkboxes.length).toBeGreaterThanOrEqual(3)
280290
// checkboxes[0] is "select all" checkbox, skipped on purpose in this test
281291
const firstCheckbox = checkboxes[1]
282292
const secondCheckbox = checkboxes[2]
@@ -287,7 +297,12 @@ describe('MachinesPageComponent', () => {
287297
fixture.detectChanges()
288298

289299
// 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()
291306

292307
// prepare 502 error response for the first machine of the bulk of machines to be authorized
293308
const umSpy = spyOn(servicesApi, 'updateMachine')
@@ -298,7 +313,7 @@ describe('MachinesPageComponent', () => {
298313
.and.returnValue(of({ hostname: 'bbb', id: 2, address: 'addr2', authorized: true } as any))
299314

300315
// click "Authorize selected" button
301-
bulkAuthorizeBtn?.dispatchEvent(new Event('click'))
316+
bulkAuthorizeBtn.dispatchEvent(new Event('click'))
302317
fixture.detectChanges()
303318

304319
// we expect that unauthorized machines list was not changed due to 502 error
@@ -362,20 +377,24 @@ describe('MachinesPageComponent', () => {
362377
const gmSpy = spyOn(servicesApi, 'getMachines')
363378

364379
// 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.
366383
gmSpy.withArgs(0, 1, null, null, false).and.returnValue(
367384
of({
368385
items: [{ hostname: 'bbb', id: 2, address: 'addr2' }],
369386
total: 2,
370387
} as any)
371388
)
372389

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.
374392
gmSpy
375393
.withArgs(0, 10, undefined, undefined, false)
376394
.and.returnValues(of(getUnauthorizedMachinesRespBefore), of(getUnauthorizedMachinesRespAfter))
377395

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.
379398
gmSpy.withArgs(0, 10, undefined, undefined, true).and.returnValue(of(getAuthorizedMachinesRespAfter))
380399

381400
// show unauthorized machines
@@ -395,14 +414,21 @@ describe('MachinesPageComponent', () => {
395414

396415
// get references to rows' checkboxes
397416
const checkboxes = fixture.nativeElement.querySelectorAll('.p-checkbox')
417+
expect(checkboxes).toBeTruthy()
418+
expect(checkboxes.length).toBeGreaterThanOrEqual(1)
398419
const selectAllCheckbox = checkboxes[0]
399420

400421
// select all unauthorized machines
401422
selectAllCheckbox.dispatchEvent(new Event('click'))
402423
fixture.detectChanges()
403424

404425
// 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()
406432

407433
// prepare 502 error response for the second machine of the bulk of machines to be authorized
408434
// first machine authorization shall succeed, third shall be skipped because it was after the 502 error
@@ -417,7 +443,7 @@ describe('MachinesPageComponent', () => {
417443
.and.returnValue(of({ hostname: 'ccc', id: 3, address: 'addr3', authorized: true } as any))
418444

419445
// click "Authorize selected" button
420-
bulkAuthorizeBtn?.dispatchEvent(new Event('click'))
446+
bulkAuthorizeBtn.dispatchEvent(new Event('click'))
421447
fixture.detectChanges()
422448

423449
// we expect that first machine of the bulk was authorized but second and third were not due to 502 error

0 commit comments

Comments
 (0)