]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
0cf0d67ebf41df5f3219590b2f1809b72af9423b
[ceph.git] /
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';
6
7 import { BsModalRef } from 'ngx-bootstrap/modal';
8 import { ToastrModule } from 'ngx-toastr';
9
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';
16
17 describe('OsdDevicesSelectionModalComponent', () => {
18   let component: OsdDevicesSelectionModalComponent;
19   let fixture: ComponentFixture<OsdDevicesSelectionModalComponent>;
20   const devices: InventoryDevice[] = [
21     {
22       hostname: 'node0',
23       uid: '1',
24       path: 'sda',
25       sys_api: {
26         vendor: 'AAA',
27         model: 'aaa',
28         size: 1024,
29         rotational: 'false',
30         human_readable_size: '1 KB'
31       },
32       available: false,
33       rejected_reasons: [''],
34       device_id: 'AAA-aaa-id0',
35       human_readable_type: 'nvme/ssd',
36       osd_ids: []
37     }
38   ];
39
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);
44   };
45
46   configureTestBed({
47     imports: [
48       BrowserAnimationsModule,
49       FormsModule,
50       HttpClientTestingModule,
51       SharedModule,
52       ReactiveFormsModule,
53       RouterTestingModule,
54       ToastrModule.forRoot()
55     ],
56     providers: [BsModalRef, i18nProviders],
57     declarations: [OsdDevicesSelectionModalComponent, InventoryDevicesComponent]
58   });
59
60   beforeEach(() => {
61     fixture = TestBed.createComponent(OsdDevicesSelectionModalComponent);
62     component = fixture.componentInstance;
63     component.devices = devices;
64     fixture.detectChanges();
65   });
66
67   it('should create', () => {
68     expect(component).toBeTruthy();
69   });
70
71   it('should disable submit button initially', () => {
72     expectSubmitButton(false);
73   });
74
75   it('should enable submit button after filtering some devices', () => {
76     const event: CdTableColumnFiltersChange = {
77       filters: [
78         {
79           name: 'hostname',
80           prop: 'hostname',
81           value: { raw: 'node0', formatted: 'node0' }
82         },
83         {
84           name: 'size',
85           prop: 'size',
86           value: { raw: '1024', formatted: '1KiB' }
87         }
88       ],
89       data: devices,
90       dataOut: []
91     };
92     component.onFilterChange(event);
93     fixture.detectChanges();
94     expectSubmitButton(true);
95   });
96 });