1 import { HttpClientModule } from '@angular/common/http';
2 import { DebugElement } from '@angular/core';
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
5 import { of } from 'rxjs';
7 import { TabsModule } from 'ngx-bootstrap/tabs';
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';
17 describe('OsdDetailsComponent', () => {
18 let component: OsdDetailsComponent;
19 let fixture: ComponentFixture<OsdDetailsComponent>;
20 let debugElement: DebugElement;
21 let osdService: OsdService;
25 imports: [HttpClientModule, TabsModule.forRoot(), PerformanceCounterModule, SharedModule],
26 declarations: [OsdDetailsComponent, OsdPerformanceHistogramComponent]
30 fixture = TestBed.createComponent(OsdDetailsComponent);
31 component = fixture.componentInstance;
33 component.selection = new CdTableSelection();
34 debugElement = fixture.debugElement;
35 osdService = debugElement.injector.get(OsdService);
37 getDetailsSpy = spyOn(osdService, 'getDetails');
39 fixture.detectChanges();
42 it('should create', () => {
43 expect(component).toBeTruthy();
46 it('should fail creating a histogram', () => {
47 const detailDataWithoutHistogram = {
52 getDetailsSpy.and.returnValue(of(detailDataWithoutHistogram));
53 component.osd = { tree: { id: 0 } };
55 expect(getDetailsSpy).toHaveBeenCalled();
56 expect(component.osd.histogram_failed).toBe('osd down');
59 it('should succeed creating a histogram', () => {
60 const detailDataWithHistogram = {
65 getDetailsSpy.and.returnValue(of(detailDataWithHistogram));
66 component.osd = { tree: { id: 0 } };
68 expect(getDetailsSpy).toHaveBeenCalled();
69 expect(component.osd.histogram_failed).toBe('');