import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; import { ResultTipComponent } from './result-tip.component'; import { IServiceConfig, SERVICE_CONFIG } from "../../../../lib/entities/service.config"; import { UserPermissionDefaultService, UserPermissionService, VulnerabilitySummary } from "../../../../lib/services"; import { CURRENT_BASE_HREF, VULNERABILITY_SCAN_STATUS } from "../../../../lib/utils/utils"; import { SharedModule } from "../../../../lib/utils/shared/shared.module"; describe('ResultTipComponent (inline template)', () => { let component: ResultTipComponent; let fixture: ComponentFixture; let testConfig: IServiceConfig = { vulnerabilityScanningBaseEndpoint: CURRENT_BASE_HREF + "/vulnerability/testing" }; let mockData: VulnerabilitySummary = { scan_status: VULNERABILITY_SCAN_STATUS.SUCCESS, severity: "High", end_time: new Date(), summary: { total: 124, fixable: 50, summary: { "High": 5, "Low": 5 } } }; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [ SharedModule ], declarations: [ResultTipComponent], providers: [{ provide: SERVICE_CONFIG, useValue: testConfig }, { provide: UserPermissionService, useClass: UserPermissionDefaultService }] }); })); beforeEach(() => { fixture = TestBed.createComponent(ResultTipComponent); component = fixture.componentInstance; component.summary = mockData; fixture.detectChanges(); }); it('should be created', () => { expect(component).toBeTruthy(); }); it('should reader the bar with different width', waitForAsync(() => { fixture.detectChanges(); fixture.whenStable().then(() => { fixture.detectChanges(); let el: HTMLElement = fixture.nativeElement.querySelector('.bar-block-none'); expect(el).not.toBeNull(); expect(el.style.width).toEqual("0px"); let el2: HTMLElement = fixture.nativeElement.querySelector('.bar-block-high'); expect(el2).not.toBeNull(); expect(el2.style.width).toEqual("0px"); }); })); });