]>
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'; | |
11fdf7f2 | 10 | import { SharedModule } from '../../../../shared/shared.module'; |
9f95a23c | 11 | import { TablePerformanceCounterComponent } from '../../../performance-counter/table-performance-counter/table-performance-counter.component'; |
f91f0fd5 | 12 | import { CephSharedModule } from '../../../shared/ceph-shared.module'; |
11fdf7f2 TL |
13 | import { OsdPerformanceHistogramComponent } from '../osd-performance-histogram/osd-performance-histogram.component'; |
14 | import { OsdDetailsComponent } from './osd-details.component'; | |
15 | ||
16 | describe('OsdDetailsComponent', () => { | |
17 | let component: OsdDetailsComponent; | |
18 | let fixture: ComponentFixture<OsdDetailsComponent>; | |
19 | let debugElement: DebugElement; | |
20 | let osdService: OsdService; | |
9f95a23c | 21 | let getDetailsSpy: jasmine.Spy; |
11fdf7f2 TL |
22 | |
23 | configureTestBed({ | |
f91f0fd5 | 24 | imports: [HttpClientTestingModule, TabsModule.forRoot(), SharedModule, CephSharedModule], |
9f95a23c TL |
25 | declarations: [ |
26 | OsdDetailsComponent, | |
9f95a23c TL |
27 | TablePerformanceCounterComponent, |
28 | OsdPerformanceHistogramComponent | |
11fdf7f2 | 29 | ], |
11fdf7f2 TL |
30 | providers: i18nProviders |
31 | }); | |
32 | ||
33 | beforeEach(() => { | |
34 | fixture = TestBed.createComponent(OsdDetailsComponent); | |
35 | component = fixture.componentInstance; | |
36 | ||
e306af50 | 37 | component.selection = undefined; |
11fdf7f2 TL |
38 | debugElement = fixture.debugElement; |
39 | osdService = debugElement.injector.get(OsdService); | |
40 | ||
41 | getDetailsSpy = spyOn(osdService, 'getDetails'); | |
42 | ||
43 | fixture.detectChanges(); | |
44 | }); | |
45 | ||
46 | it('should create', () => { | |
47 | expect(component).toBeTruthy(); | |
48 | }); | |
49 | ||
50 | it('should fail creating a histogram', () => { | |
51 | const detailDataWithoutHistogram = { | |
52 | osd_map: {}, | |
53 | osd_metadata: {}, | |
54 | histogram: 'osd down' | |
55 | }; | |
56 | getDetailsSpy.and.returnValue(of(detailDataWithoutHistogram)); | |
57 | component.osd = { tree: { id: 0 } }; | |
58 | component.refresh(); | |
59 | expect(getDetailsSpy).toHaveBeenCalled(); | |
60 | expect(component.osd.histogram_failed).toBe('osd down'); | |
61 | }); | |
62 | ||
63 | it('should succeed creating a histogram', () => { | |
64 | const detailDataWithHistogram = { | |
65 | osd_map: {}, | |
9f95a23c | 66 | osd_metadata: {}, |
11fdf7f2 TL |
67 | histogram: {} |
68 | }; | |
69 | getDetailsSpy.and.returnValue(of(detailDataWithHistogram)); | |
70 | component.osd = { tree: { id: 0 } }; | |
71 | component.refresh(); | |
72 | expect(getDetailsSpy).toHaveBeenCalled(); | |
73 | expect(component.osd.histogram_failed).toBe(''); | |
74 | }); | |
75 | }); |