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