1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { DebugElement } from '@angular/core';
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
5 import { TabsModule } from 'ngx-bootstrap/tabs';
6 import { of } from 'rxjs';
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';
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;
25 imports: [HttpClientTestingModule, TabsModule.forRoot(), SharedModule],
30 TablePerformanceCounterComponent,
31 OsdPerformanceHistogramComponent
33 providers: i18nProviders
37 fixture = TestBed.createComponent(OsdDetailsComponent);
38 component = fixture.componentInstance;
40 component.selection = undefined;
41 debugElement = fixture.debugElement;
42 osdService = debugElement.injector.get(OsdService);
44 getDetailsSpy = spyOn(osdService, 'getDetails');
46 fixture.detectChanges();
49 it('should create', () => {
50 expect(component).toBeTruthy();
53 it('should fail creating a histogram', () => {
54 const detailDataWithoutHistogram = {
59 getDetailsSpy.and.returnValue(of(detailDataWithoutHistogram));
60 component.osd = { tree: { id: 0 } };
62 expect(getDetailsSpy).toHaveBeenCalled();
63 expect(component.osd.histogram_failed).toBe('osd down');
66 it('should succeed creating a histogram', () => {
67 const detailDataWithHistogram = {
72 getDetailsSpy.and.returnValue(of(detailDataWithHistogram));
73 component.osd = { tree: { id: 0 } };
75 expect(getDetailsSpy).toHaveBeenCalled();
76 expect(component.osd.histogram_failed).toBe('');