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