Skip to content

Commit 32ac42a

Browse files
CXIEP-7764: Adjust unit test for refactored code
1 parent 8e85907 commit 32ac42a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

integration-libs/s4om/components/order-detail-attachments/attachments-dialog/attachments-dialog.component.spec.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
S4OMOrderAttachmentsPreviewMimeTypesConfig,
1717
} from '../../config/order-attachments-mime-types.config';
1818
import { By } from '@angular/platform-browser';
19-
import { ChangeDetectorRef } from '@angular/core';
19+
import { ChangeDetectorRef, DebugElement } from '@angular/core';
2020
import createSpy = jasmine.createSpy;
2121

2222
const orderCode = '00001004';
@@ -60,6 +60,17 @@ class MockLaunchDialogService implements Partial<LaunchDialogService> {
6060
}
6161
}
6262

63+
const countHiddenElementsFn = (debugElements: DebugElement[]) => {
64+
let result = 0;
65+
for (let i = 0; i < debugElements.length; i++) {
66+
if (debugElements[i].nativeElement.classList.contains('hidden')) {
67+
result++;
68+
}
69+
}
70+
71+
return result;
72+
};
73+
6374
describe('AttachmentsDialogComponent', () => {
6475
let component: AttachmentsDialogComponent;
6576
let fixture: ComponentFixture<AttachmentsDialogComponent>;
@@ -433,25 +444,25 @@ describe('AttachmentsDialogComponent', () => {
433444

434445
fixture.detectChanges();
435446
let inlineSpinnerEls = fixture.debugElement.queryAll(By.css('.inline-spinner'));
436-
expect(inlineSpinnerEls.length).toBe(0);
447+
expect(countHiddenElementsFn(inlineSpinnerEls)).toBe(3);
437448

438449
component.openOrderAttachment(attachmentId, 'mock name');
439450
fixture.detectChanges();
440451
inlineSpinnerEls = fixture.debugElement.queryAll(By.css('.inline-spinner'));
441-
expect(inlineSpinnerEls.length).toBe(1);
452+
expect(countHiddenElementsFn(inlineSpinnerEls)).toBe(2);
442453

443454
// duplicated attachment id should not display duplicated spinners
444455
component.openOrderAttachment(attachmentId2, 'mock name');
445456
tick(50);
446457
component.openOrderAttachment(attachmentId2, 'mock name');
447458
fixture.detectChanges();
448459
inlineSpinnerEls = fixture.debugElement.queryAll(By.css('.inline-spinner'));
449-
expect(inlineSpinnerEls.length).toBe(2);
460+
expect(countHiddenElementsFn(inlineSpinnerEls)).toBe(1);
450461

451462
tick(1000);
452463
fixture.detectChanges();
453464
inlineSpinnerEls = fixture.debugElement.queryAll(By.css('.inline-spinner'));
454-
expect(inlineSpinnerEls.length).toBe(0);
465+
expect(countHiddenElementsFn(inlineSpinnerEls)).toBe(3);
455466
}));
456467

457468
it('should close modal when cancel is clicked', () => {

0 commit comments

Comments
 (0)