]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.spec.ts
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / inventory / inventory.component.spec.ts
CommitLineData
9f95a23c
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { FormsModule } from '@angular/forms';
e306af50 4import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
9f95a23c
TL
5import { RouterTestingModule } from '@angular/router/testing';
6
7import { ToastrModule } from 'ngx-toastr';
8import { of } from 'rxjs';
9
f67539c2
TL
10import { HostService } from '~/app/shared/api/host.service';
11import { OrchestratorService } from '~/app/shared/api/orchestrator.service';
12import { SharedModule } from '~/app/shared/shared.module';
13import { configureTestBed } from '~/testing/unit-test-helper';
9f95a23c
TL
14import { InventoryDevicesComponent } from './inventory-devices/inventory-devices.component';
15import { InventoryComponent } from './inventory.component';
16
17describe('InventoryComponent', () => {
18 let component: InventoryComponent;
19 let fixture: ComponentFixture<InventoryComponent>;
20 let orchService: OrchestratorService;
f67539c2 21 let hostService: HostService;
9f95a23c
TL
22
23 configureTestBed({
24 imports: [
e306af50 25 BrowserAnimationsModule,
9f95a23c
TL
26 FormsModule,
27 SharedModule,
28 HttpClientTestingModule,
29 RouterTestingModule,
30 ToastrModule.forRoot()
31 ],
9f95a23c
TL
32 declarations: [InventoryComponent, InventoryDevicesComponent]
33 });
34
35 beforeEach(() => {
36 fixture = TestBed.createComponent(InventoryComponent);
37 component = fixture.componentInstance;
f67539c2
TL
38 orchService = TestBed.inject(OrchestratorService);
39 hostService = TestBed.inject(HostService);
9f95a23c 40 spyOn(orchService, 'status').and.returnValue(of({ available: true }));
f67539c2 41 spyOn(hostService, 'inventoryDeviceList').and.callThrough();
9f95a23c
TL
42 });
43
44 it('should create', () => {
45 expect(component).toBeTruthy();
46 });
47
adb31ebb
TL
48 it('should not display doc panel if orchestrator is available', () => {
49 expect(component.showDocPanel).toBeFalsy();
50 });
51
9f95a23c
TL
52 describe('after ngOnInit', () => {
53 it('should load devices', () => {
54 fixture.detectChanges();
f67539c2 55 component.refresh(); // click refresh button
a4b75251 56 expect(hostService.inventoryDeviceList).toHaveBeenNthCalledWith(1, undefined, false);
9f95a23c 57
f67539c2
TL
58 const newHost = 'host0';
59 component.hostname = newHost;
9f95a23c 60 fixture.detectChanges();
f67539c2 61 component.ngOnChanges();
a4b75251 62 expect(hostService.inventoryDeviceList).toHaveBeenNthCalledWith(2, newHost, false);
f67539c2 63 component.refresh(); // click refresh button
a4b75251 64 expect(hostService.inventoryDeviceList).toHaveBeenNthCalledWith(3, newHost, true);
9f95a23c
TL
65 });
66 });
67});