]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
5ab90157ed95f83e773cd5c92197c12e101f1ef6
[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 { of } from 'rxjs';
6
7 import { TabsModule } from 'ngx-bootstrap/tabs';
8
9 import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
10 import { CoreModule } from '../../../../core/core.module';
11 import { OsdService } from '../../../../shared/api/osd.service';
12 import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
13 import { CephModule } from '../../../ceph.module';
14 import { PerformanceCounterModule } from '../../../performance-counter/performance-counter.module';
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: [
26       HttpClientTestingModule,
27       TabsModule.forRoot(),
28       PerformanceCounterModule,
29       CephModule,
30       CoreModule
31     ],
32     declarations: [],
33     providers: i18nProviders
34   });
35
36   beforeEach(() => {
37     fixture = TestBed.createComponent(OsdDetailsComponent);
38     component = fixture.componentInstance;
39
40     component.selection = new CdTableSelection();
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 });