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 { 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';
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;
26 imports: [HttpClientTestingModule, TabsModule.forRoot(), SharedModule],
31 TablePerformanceCounterComponent,
32 OsdPerformanceHistogramComponent
34 providers: i18nProviders
38 fixture = TestBed.createComponent(OsdDetailsComponent);
39 component = fixture.componentInstance;
41 component.selection = new CdTableSelection();
42 debugElement = fixture.debugElement;
43 osdService = debugElement.injector.get(OsdService);
45 getDetailsSpy = spyOn(osdService, 'getDetails');
47 fixture.detectChanges();
50 it('should create', () => {
51 expect(component).toBeTruthy();
54 it('should fail creating a histogram', () => {
55 const detailDataWithoutHistogram = {
60 getDetailsSpy.and.returnValue(of(detailDataWithoutHistogram));
61 component.osd = { tree: { id: 0 } };
63 expect(getDetailsSpy).toHaveBeenCalled();
64 expect(component.osd.histogram_failed).toBe('osd down');
67 it('should succeed creating a histogram', () => {
68 const detailDataWithHistogram = {
73 getDetailsSpy.and.returnValue(of(detailDataWithHistogram));
74 component.osd = { tree: { id: 0 } };
76 expect(getDetailsSpy).toHaveBeenCalled();
77 expect(component.osd.histogram_failed).toBe('');