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