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';
6 import { ToastrModule } from 'ngx-toastr';
7 import { of } from 'rxjs';
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';
15 describe('InventoryComponent', () => {
16 let component: InventoryComponent;
17 let fixture: ComponentFixture<InventoryComponent>;
18 let orchService: OrchestratorService;
24 HttpClientTestingModule,
26 ToastrModule.forRoot()
28 providers: [i18nProviders],
29 declarations: [InventoryComponent, InventoryDevicesComponent]
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();
40 it('should create', () => {
41 expect(component).toBeTruthy();
44 describe('after ngOnInit', () => {
45 it('should load devices', () => {
46 fixture.detectChanges();
47 expect(orchService.inventoryDeviceList).toHaveBeenCalledWith(undefined);
50 it('should load devices for a host', () => {
51 component.hostname = 'host0';
52 fixture.detectChanges();
53 expect(orchService.inventoryDeviceList).toHaveBeenCalledWith('host0');