]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
bbab68c092505f90b5aa04d2aa868109ccb216b1
[ceph-ci.git] /
1 import { HttpClientModule } from '@angular/common/http';
2 import { DebugElement } from '@angular/core';
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
4
5 import { of } from 'rxjs';
6
7 import { TabsModule } from 'ngx-bootstrap/tabs';
8
9 import { configureTestBed } from '../../../../../testing/unit-test-helper';
10 import { OsdService } from '../../../../shared/api/osd.service';
11 import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
12 import { SharedModule } from '../../../../shared/shared.module';
13 import { PerformanceCounterModule } from '../../../performance-counter/performance-counter.module';
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;
23
24   configureTestBed({
25     imports: [HttpClientModule, TabsModule.forRoot(), PerformanceCounterModule, SharedModule],
26     declarations: [OsdDetailsComponent, OsdPerformanceHistogramComponent]
27   });
28
29   beforeEach(() => {
30     fixture = TestBed.createComponent(OsdDetailsComponent);
31     component = fixture.componentInstance;
32
33     component.selection = new CdTableSelection();
34     debugElement = fixture.debugElement;
35     osdService = debugElement.injector.get(OsdService);
36
37     getDetailsSpy = spyOn(osdService, 'getDetails');
38
39     fixture.detectChanges();
40   });
41
42   it('should create', () => {
43     expect(component).toBeTruthy();
44   });
45
46   it('should fail creating a histogram', () => {
47     const detailDataWithoutHistogram = {
48       osd_map: {},
49       osd_metadata: {},
50       histogram: 'osd down'
51     };
52     getDetailsSpy.and.returnValue(of(detailDataWithoutHistogram));
53     component.osd = { tree: { id: 0 } };
54     component.refresh();
55     expect(getDetailsSpy).toHaveBeenCalled();
56     expect(component.osd.histogram_failed).toBe('osd down');
57   });
58
59   it('should succeed creating a histogram', () => {
60     const detailDataWithHistogram = {
61       osd_map: {},
62       osd_metdata: {},
63       histogram: {}
64     };
65     getDetailsSpy.and.returnValue(of(detailDataWithHistogram));
66     component.osd = { tree: { id: 0 } };
67     component.refresh();
68     expect(getDetailsSpy).toHaveBeenCalled();
69     expect(component.osd.histogram_failed).toBe('');
70   });
71 });