]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-details/osd-details.component.spec.ts
16b7f20e331a1719a8486a382c67b5e2c8744f46
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / osd / osd-details / osd-details.component.spec.ts
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 { CdTableSelection } from '../../../../shared/models/cd-table-selection';
11 import { SharedModule } from '../../../../shared/shared.module';
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';
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;
23 let getDetailsSpy: jasmine.Spy;
24
25 configureTestBed({
26 imports: [HttpClientTestingModule, TabsModule.forRoot(), SharedModule],
27 declarations: [
28 OsdDetailsComponent,
29 DeviceListComponent,
30 SmartListComponent,
31 TablePerformanceCounterComponent,
32 OsdPerformanceHistogramComponent
33 ],
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: {},
70 osd_metadata: {},
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 });