import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { VulnerabilitySummary } from '../service/index'; import { ResultTipComponent } from './result-tip.component'; import { SharedModule } from '../shared/shared.module'; import { SERVICE_CONFIG, IServiceConfig } from '../service.config'; import { VULNERABILITY_SCAN_STATUS } from '../utils'; describe('ResultTipComponent (inline template)', () => { let component: ResultTipComponent; let fixture: ComponentFixture; let testConfig: IServiceConfig = { vulnerabilityScanningBaseEndpoint: "/api/vulnerability/testing" }; let mockData: VulnerabilitySummary = { scan_status: VULNERABILITY_SCAN_STATUS.finished, severity: 5, update_time: new Date(), components: { total: 124, summary: [{ severity: 1, count: 90 }, { severity: 3, count: 10 }, { severity: 4, count: 10 }, { severity: 5, count: 13 }] } }; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ SharedModule ], declarations: [ResultTipComponent], providers: [{ provide: SERVICE_CONFIG, useValue: testConfig }] }); })); 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', async(() => { 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("73px"); let el2: HTMLElement = fixture.nativeElement.querySelector('.bar-block-high'); expect(el2).not.toBeNull(); expect(el2.style.width).toEqual("10px"); }); })); });