]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
ebe9f097e7204efdc32682444389854d8f4d86f0
[ceph-ci.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { RouterTestingModule } from '@angular/router/testing';
4
5 import { NgBootstrapFormValidationModule } from 'ng-bootstrap-form-validation';
6 import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
7 import { TabsetComponent, TabsModule } from 'ngx-bootstrap/tabs';
8 import { of } from 'rxjs';
9 import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
10 import { CoreModule } from '../../../../core/core.module';
11 import { OrchestratorService } from '../../../../shared/api/orchestrator.service';
12 import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
13 import { Permissions } from '../../../../shared/models/permissions';
14 import { CephModule } from '../../../ceph.module';
15 import { HostDetailsComponent } from './host-details.component';
16
17 describe('HostDetailsComponent', () => {
18   let component: HostDetailsComponent;
19   let fixture: ComponentFixture<HostDetailsComponent>;
20
21   configureTestBed({
22     imports: [
23       HttpClientTestingModule,
24       TabsModule.forRoot(),
25       BsDropdownModule.forRoot(),
26       NgBootstrapFormValidationModule.forRoot(),
27       RouterTestingModule,
28       CephModule,
29       CoreModule
30     ],
31     declarations: [],
32     providers: [i18nProviders]
33   });
34
35   beforeEach(() => {
36     fixture = TestBed.createComponent(HostDetailsComponent);
37     component = fixture.componentInstance;
38     component.selection = new CdTableSelection();
39     component.permissions = new Permissions({
40       hosts: ['read'],
41       grafana: ['read']
42     });
43     const orchService = TestBed.get(OrchestratorService);
44     spyOn(orchService, 'status').and.returnValue(of({ available: true }));
45     spyOn(orchService, 'inventoryDeviceList').and.returnValue(of([]));
46     spyOn(orchService, 'serviceList').and.returnValue(of([]));
47     fixture.detectChanges();
48   });
49
50   it('should create', () => {
51     expect(component).toBeTruthy();
52   });
53
54   describe('Host details tabset', () => {
55     beforeEach(() => {
56       component.selection.selected = [
57         {
58           hostname: 'localhost'
59         }
60       ];
61     });
62
63     it('should recognize a tabset child', () => {
64       fixture.detectChanges();
65       const tabsetChild: TabsetComponent = component.tabsetChild;
66       expect(tabsetChild).toBeDefined();
67     });
68
69     it('should show tabs', () => {
70       fixture.detectChanges();
71       const tabs = component.tabsetChild.tabs.map((tab) => tab.heading);
72       expect(tabs).toEqual(['Devices', 'Inventory', 'Services', 'Performance Details']);
73     });
74   });
75 });