]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
2 | import { DebugElement } from '@angular/core'; | |
3 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
4 | ||
11fdf7f2 | 5 | import { TabsModule } from 'ngx-bootstrap/tabs'; |
9f95a23c | 6 | import { of } from 'rxjs'; |
11fdf7f2 TL |
7 | |
8 | import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper'; | |
9 | import { OsdService } from '../../../../shared/api/osd.service'; | |
10 | import { CdTableSelection } from '../../../../shared/models/cd-table-selection'; | |
11 | import { SharedModule } from '../../../../shared/shared.module'; | |
9f95a23c TL |
12 | import { TablePerformanceCounterComponent } from '../../../performance-counter/table-performance-counter/table-performance-counter.component'; |
13 | import { DeviceListComponent } from '../../../shared/device-list/device-list.component'; | |
14 | import { SmartListComponent } from '../../../shared/smart-list/smart-list.component'; | |
11fdf7f2 TL |
15 | import { OsdPerformanceHistogramComponent } from '../osd-performance-histogram/osd-performance-histogram.component'; |
16 | import { OsdDetailsComponent } from './osd-details.component'; | |
17 | ||
18 | describe('OsdDetailsComponent', () => { | |
19 | let component: OsdDetailsComponent; | |
20 | let fixture: ComponentFixture<OsdDetailsComponent>; | |
21 | let debugElement: DebugElement; | |
22 | let osdService: OsdService; | |
9f95a23c | 23 | let getDetailsSpy: jasmine.Spy; |
11fdf7f2 TL |
24 | |
25 | configureTestBed({ | |
9f95a23c TL |
26 | imports: [HttpClientTestingModule, TabsModule.forRoot(), SharedModule], |
27 | declarations: [ | |
28 | OsdDetailsComponent, | |
29 | DeviceListComponent, | |
30 | SmartListComponent, | |
31 | TablePerformanceCounterComponent, | |
32 | OsdPerformanceHistogramComponent | |
11fdf7f2 | 33 | ], |
11fdf7f2 TL |
34 | providers: i18nProviders |
35 | }); | |
36 | ||
37 | beforeEach(() => { | |
38 | fixture = TestBed.createComponent(OsdDetailsComponent); | |
39 | component = fixture.componentInstance; | |
40 | ||
41 | component.selection = new CdTableSelection(); | |
42 | debugElement = fixture.debugElement; | |
43 | osdService = debugElement.injector.get(OsdService); | |
44 | ||
45 | getDetailsSpy = spyOn(osdService, 'getDetails'); | |
46 | ||
47 | fixture.detectChanges(); | |
48 | }); | |
49 | ||
50 | it('should create', () => { | |
51 | expect(component).toBeTruthy(); | |
52 | }); | |
53 | ||
54 | it('should fail creating a histogram', () => { | |
55 | const detailDataWithoutHistogram = { | |
56 | osd_map: {}, | |
57 | osd_metadata: {}, | |
58 | histogram: 'osd down' | |
59 | }; | |
60 | getDetailsSpy.and.returnValue(of(detailDataWithoutHistogram)); | |
61 | component.osd = { tree: { id: 0 } }; | |
62 | component.refresh(); | |
63 | expect(getDetailsSpy).toHaveBeenCalled(); | |
64 | expect(component.osd.histogram_failed).toBe('osd down'); | |
65 | }); | |
66 | ||
67 | it('should succeed creating a histogram', () => { | |
68 | const detailDataWithHistogram = { | |
69 | osd_map: {}, | |
9f95a23c | 70 | osd_metadata: {}, |
11fdf7f2 TL |
71 | histogram: {} |
72 | }; | |
73 | getDetailsSpy.and.returnValue(of(detailDataWithHistogram)); | |
74 | component.osd = { tree: { id: 0 } }; | |
75 | component.refresh(); | |
76 | expect(getDetailsSpy).toHaveBeenCalled(); | |
77 | expect(component.osd.histogram_failed).toBe(''); | |
78 | }); | |
79 | }); |