1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormsModule, ReactiveFormsModule } from '@angular/forms';
4 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5 import { RouterTestingModule } from '@angular/router/testing';
7 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
8 import { ToastrModule } from 'ngx-toastr';
10 import { InventoryDevice } from '~/app/ceph/cluster/inventory/inventory-devices/inventory-device.model';
11 import { InventoryDevicesComponent } from '~/app/ceph/cluster/inventory/inventory-devices/inventory-devices.component';
12 import { CdTableColumnFiltersChange } from '~/app/shared/models/cd-table-column-filters-change';
13 import { SharedModule } from '~/app/shared/shared.module';
14 import { configureTestBed, Mocks } from '~/testing/unit-test-helper';
15 import { OsdDevicesSelectionModalComponent } from './osd-devices-selection-modal.component';
17 describe('OsdDevicesSelectionModalComponent', () => {
18 let component: OsdDevicesSelectionModalComponent;
19 let fixture: ComponentFixture<OsdDevicesSelectionModalComponent>;
20 let timeoutFn: Function;
22 const devices: InventoryDevice[] = [Mocks.getInventoryDevice('node0', '1')];
24 const expectSubmitButton = (enabled: boolean) => {
25 const nativeElement = fixture.debugElement.nativeElement;
26 const button = nativeElement.querySelector('.modal-footer .tc_submitButton');
27 expect(button.disabled).toBe(!enabled);
32 BrowserAnimationsModule,
34 HttpClientTestingModule,
38 ToastrModule.forRoot()
40 providers: [NgbActiveModal],
41 declarations: [OsdDevicesSelectionModalComponent, InventoryDevicesComponent]
45 spyOn(window, 'setTimeout').and.callFake((fn) => (timeoutFn = fn));
47 fixture = TestBed.createComponent(OsdDevicesSelectionModalComponent);
48 component = fixture.componentInstance;
49 component.devices = devices;
51 // Mocks InventoryDeviceComponent
52 component.inventoryDevices = {
54 { name: 'Device path', prop: 'path' },
57 prop: 'human_readable_type'
64 } as InventoryDevicesComponent;
65 // Mocks the update from the above component
66 component.filterColumns = ['path', 'human_readable_type'];
67 fixture.detectChanges();
70 it('should create', () => {
71 expect(component).toBeTruthy();
74 it('should disable submit button initially', () => {
75 expectSubmitButton(false);
79 'should update requiredFilters after ngAfterViewInit is called to prevent ' +
80 'ExpressionChangedAfterItHasBeenCheckedError',
82 expect(component.requiredFilters).toEqual([]);
84 expect(component.requiredFilters).toEqual(['Device path', 'Type']);
88 it('should enable submit button after filtering some devices', () => {
89 const event: CdTableColumnFiltersChange = {
94 value: { raw: 'node0', formatted: 'node0' }
99 value: { raw: '1024', formatted: '1KiB' }
105 component.onFilterChange(event);
106 fixture.detectChanges();
107 expectSubmitButton(true);