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 { RouterTestingModule } from '@angular/router/testing';
6 import { BsModalRef } from 'ngx-bootstrap/modal';
7 import { ToastrModule } from 'ngx-toastr';
9 import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
10 import { CdTableColumnFiltersChange } from '../../../../shared/models/cd-table-column-filters-change';
11 import { SharedModule } from '../../../../shared/shared.module';
12 import { InventoryDevice } from '../../inventory/inventory-devices/inventory-device.model';
13 import { InventoryDevicesComponent } from '../../inventory/inventory-devices/inventory-devices.component';
14 import { OsdDevicesSelectionModalComponent } from './osd-devices-selection-modal.component';
16 describe('OsdDevicesSelectionModalComponent', () => {
17 let component: OsdDevicesSelectionModalComponent;
18 let fixture: ComponentFixture<OsdDevicesSelectionModalComponent>;
19 const devices: InventoryDevice[] = [
29 human_readable_size: '1 KB'
32 rejected_reasons: [''],
33 device_id: 'AAA-aaa-id0',
34 human_readable_type: 'nvme/ssd',
39 const expectSubmitButton = (enabled: boolean) => {
40 const nativeElement = fixture.debugElement.nativeElement;
41 const button = nativeElement.querySelector('.modal-footer button');
42 expect(button.disabled).toBe(!enabled);
48 HttpClientTestingModule,
52 ToastrModule.forRoot()
54 providers: [BsModalRef, i18nProviders],
55 declarations: [OsdDevicesSelectionModalComponent, InventoryDevicesComponent]
59 fixture = TestBed.createComponent(OsdDevicesSelectionModalComponent);
60 component = fixture.componentInstance;
61 component.devices = devices;
62 fixture.detectChanges();
65 it('should create', () => {
66 expect(component).toBeTruthy();
69 it('should disable submit button initially', () => {
70 expectSubmitButton(false);
73 it('should enable submit button after filtering some devices', () => {
74 const event: CdTableColumnFiltersChange = {
79 value: { raw: 'node0', formatted: 'node0' }
84 value: { raw: '1024', formatted: '1KiB' }
90 component.onFilterChange(event);
91 fixture.detectChanges();
92 expectSubmitButton(true);