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