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