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