result-tip.component.spec.ts 2.12 KB
Newer Older
1
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
2
import { ResultTipComponent } from './result-tip.component';
3 4
import { IServiceConfig, SERVICE_CONFIG } from "../../../../lib/entities/service.config";
import { UserPermissionDefaultService, UserPermissionService, VulnerabilitySummary } from "../../../../lib/services";
AllForNothing's avatar
AllForNothing committed
5
import { CURRENT_BASE_HREF, VULNERABILITY_SCAN_STATUS } from "../../../../lib/utils/utils";
6
import { SharedModule } from "../../../../lib/utils/shared/shared.module";
7

8

9 10 11
describe('ResultTipComponent (inline template)', () => {
  let component: ResultTipComponent;
  let fixture: ComponentFixture<ResultTipComponent>;
12
  let testConfig: IServiceConfig = {
AllForNothing's avatar
AllForNothing committed
13
    vulnerabilityScanningBaseEndpoint: CURRENT_BASE_HREF + "/vulnerability/testing"
14
  };
Steven Zou's avatar
Steven Zou committed
15
  let mockData: VulnerabilitySummary = {
AllForNothing's avatar
AllForNothing committed
16 17 18 19
    scan_status: VULNERABILITY_SCAN_STATUS.SUCCESS,
    severity: "High",
    end_time: new Date(),
    summary: {
Steven Zou's avatar
Steven Zou committed
20
      total: 124,
sshijun's avatar
sshijun committed
21
      fixable: 50,
AllForNothing's avatar
AllForNothing committed
22 23 24 25
      summary: {
        "High": 5,
        "Low": 5
      }
Steven Zou's avatar
Steven Zou committed
26
    }
27
  };
28

29
  beforeEach(waitForAsync(() => {
30 31 32 33
    TestBed.configureTestingModule({
      imports: [
        SharedModule
      ],
34
      declarations: [ResultTipComponent],
System Administrator's avatar
System Administrator committed
35 36
      providers: [{ provide: SERVICE_CONFIG, useValue: testConfig },
      { provide: UserPermissionService, useClass: UserPermissionDefaultService }]
37 38 39 40 41 42 43
    });

  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ResultTipComponent);
    component = fixture.componentInstance;
44
    component.summary = mockData;
45 46 47 48 49 50 51 52

    fixture.detectChanges();
  });

  it('should be created', () => {
    expect(component).toBeTruthy();
  });

53
  it('should reader the bar with different width', waitForAsync(() => {
54 55 56 57 58
    fixture.detectChanges();
    fixture.whenStable().then(() => {
      fixture.detectChanges();
      let el: HTMLElement = fixture.nativeElement.querySelector('.bar-block-none');
      expect(el).not.toBeNull();
AllForNothing's avatar
AllForNothing committed
59
      expect(el.style.width).toEqual("0px");
60 61
      let el2: HTMLElement = fixture.nativeElement.querySelector('.bar-block-high');
      expect(el2).not.toBeNull();
AllForNothing's avatar
AllForNothing committed
62
      expect(el2.style.width).toEqual("0px");
63 64 65
    });
  }));

66
});