blob: 8a37c77ee76be50e4b2c3092d69254bb7dd31a27 [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {TestBed, ComponentFixture, async} from '@angular/core/testing';
2import {HealthStatusComponent} from "./health-status.component";
3import {HealthStatusService} from "../shared/server/healthStatusService/health-status.service";
4import {HttpClientTestingModule} from "@angular/common/http/testing";
5import {ExternalComponentStatus} from "../shared/models/externalComponentStatus";
6import {Observable} from "rxjs";
7import {of} from "rxjs";
8
9export class MockHealthStatusService {
10
11
12 getProbe(): Observable<Array<ExternalComponentStatus>> {
13 return of(new Array<ExternalComponentStatus>(
14 new ExternalComponentStatus("x", true, {y:"r"})));
15 }
16}
17
18describe('HealthStatusComponent', () => {
19 let component: HealthStatusComponent;
20 let fixture: ComponentFixture<HealthStatusComponent>;
21 let mockHealthStatusService : MockHealthStatusService;
22
23 mockHealthStatusService = new MockHealthStatusService();
24
25 beforeAll(done => (async () => {
26
27 TestBed.configureTestingModule({
28 imports: [HttpClientTestingModule],
29 providers: [{provide: HealthStatusService, useValue: mockHealthStatusService}],
30 declarations: [HealthStatusComponent]
31 });
32 await TestBed.compileComponents();
33
34 fixture = TestBed.createComponent(HealthStatusComponent);
35 component = fixture.componentInstance;
36 fixture.detectChanges();
37 })().then(done).catch(done.fail));
38
39 test('isAvailable taken from component status available field', () => {
40 expect(component.isAvailable(new ExternalComponentStatus("a", true, null))).toBeTruthy();
41 expect(component.isAvailable(new ExternalComponentStatus("a", false, null))).toBeFalsy();
42 });
43
44 test('getMetadata filter rawData ', () => {
45 let metadata:string = JSON.stringify(component.getMetadata(new ExternalComponentStatus("a", true, {a:1, rawData:2})));
46 expect(metadata).toContain("1");
47 expect(metadata.indexOf("2")).toEqual(-1);
48 });
49
50 test('componentStatus is initialized on startup ', () => {
51 expect(JSON.stringify(component.componentStatuses[0].metadata)).toContain("y");
52 });
53
54 test('when refresh componentStatus is updated', () => {
55 spyOn(mockHealthStatusService, "getProbe" ).and.returnValue(
56 of(new Array<ExternalComponentStatus>(
57 new ExternalComponentStatus("mySpecialValue", true, {y:"z"}))));
58 component.refreshData();
59 expect(component.componentStatuses[0].component).toEqual("mySpecialValue");
60 expect(mockHealthStatusService.getProbe).toHaveBeenCalledTimes(1);
61
62 });
63
64});