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';
7 import { ToastrModule } from 'ngx-toastr';
8 import { of } from 'rxjs';
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';
17 describe('InventoryComponent', () => {
18 let component: InventoryComponent;
19 let fixture: ComponentFixture<InventoryComponent>;
20 let orchService: OrchestratorService;
21 let hostService: HostService;
25 BrowserAnimationsModule,
28 HttpClientTestingModule,
30 ToastrModule.forRoot()
32 declarations: [InventoryComponent, InventoryDevicesComponent]
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();
44 it('should create', () => {
45 expect(component).toBeTruthy();
48 it('should not display doc panel if orchestrator is available', () => {
49 expect(component.showDocPanel).toBeFalsy();
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);
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);