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 { BsModalRef } from 'ngx-bootstrap/modal';
8 import { ToastrModule } from 'ngx-toastr';
10 import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
11 import { CdTableColumnFiltersChange } from '../../../../shared/models/cd-table-column-filters-change';
12 import { SharedModule } from '../../../../shared/shared.module';
13 import { InventoryDevice } from '../../inventory/inventory-devices/inventory-device.model';
14 import { InventoryDevicesComponent } from '../../inventory/inventory-devices/inventory-devices.component';
15 import { OsdDevicesSelectionModalComponent } from './osd-devices-selection-modal.component';
17 describe('OsdDevicesSelectionModalComponent', () => {
18 let component: OsdDevicesSelectionModalComponent;
19 let fixture: ComponentFixture<OsdDevicesSelectionModalComponent>;
20 const devices: InventoryDevice[] = [
30 human_readable_size: '1 KB'
33 rejected_reasons: [''],
34 device_id: 'AAA-aaa-id0',
35 human_readable_type: 'nvme/ssd',
40 const expectSubmitButton = (enabled: boolean) => {
41 const nativeElement = fixture.debugElement.nativeElement;
42 const button = nativeElement.querySelector('.modal-footer button');
43 expect(button.disabled).toBe(!enabled);
48 BrowserAnimationsModule,
50 HttpClientTestingModule,
54 ToastrModule.forRoot()
56 providers: [BsModalRef, i18nProviders],
57 declarations: [OsdDevicesSelectionModalComponent, InventoryDevicesComponent]
61 fixture = TestBed.createComponent(OsdDevicesSelectionModalComponent);
62 component = fixture.componentInstance;
63 component.devices = devices;
64 fixture.detectChanges();
67 it('should create', () => {
68 expect(component).toBeTruthy();
71 it('should disable submit button initially', () => {
72 expectSubmitButton(false);
75 it('should enable submit button after filtering some devices', () => {
76 const event: CdTableColumnFiltersChange = {
81 value: { raw: 'node0', formatted: 'node0' }
86 value: { raw: '1024', formatted: '1KiB' }
92 component.onFilterChange(event);
93 fixture.detectChanges();
94 expectSubmitButton(true);