]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.spec.ts
10a930f5b58c0022db20d642350d4b906feaa63a
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / inventory / inventory.component.spec.ts
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormsModule } from '@angular/forms';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { ToastrModule } from 'ngx-toastr';
7 import { of } from 'rxjs';
8
9 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
10 import { OrchestratorService } from '../../../shared/api/orchestrator.service';
11 import { SharedModule } from '../../../shared/shared.module';
12 import { InventoryDevicesComponent } from './inventory-devices/inventory-devices.component';
13 import { InventoryComponent } from './inventory.component';
14
15 describe('InventoryComponent', () => {
16 let component: InventoryComponent;
17 let fixture: ComponentFixture<InventoryComponent>;
18 let orchService: OrchestratorService;
19
20 configureTestBed({
21 imports: [
22 FormsModule,
23 SharedModule,
24 HttpClientTestingModule,
25 RouterTestingModule,
26 ToastrModule.forRoot()
27 ],
28 providers: [i18nProviders],
29 declarations: [InventoryComponent, InventoryDevicesComponent]
30 });
31
32 beforeEach(() => {
33 fixture = TestBed.createComponent(InventoryComponent);
34 component = fixture.componentInstance;
35 orchService = TestBed.get(OrchestratorService);
36 spyOn(orchService, 'status').and.returnValue(of({ available: true }));
37 spyOn(orchService, 'inventoryDeviceList').and.callThrough();
38 });
39
40 it('should create', () => {
41 expect(component).toBeTruthy();
42 });
43
44 describe('after ngOnInit', () => {
45 it('should load devices', () => {
46 fixture.detectChanges();
47 expect(orchService.inventoryDeviceList).toHaveBeenCalledWith(undefined);
48 });
49
50 it('should load devices for a host', () => {
51 component.hostname = 'host0';
52 fixture.detectChanges();
53 expect(orchService.inventoryDeviceList).toHaveBeenCalledWith('host0');
54 });
55 });
56 });