]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
f15f3a0382d1ede5337f23973eb937e79a286f27
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { FormsModule } from '@angular/forms';
3
4 import {
5   configureTestBed,
6   FixtureHelper,
7   i18nProviders
8 } from '../../../../../testing/unit-test-helper';
9 import { SharedModule } from '../../../../shared/shared.module';
10 import { InventoryDevicesComponent } from '../../inventory/inventory-devices/inventory-devices.component';
11 import { OsdDevicesSelectionGroupsComponent } from './osd-devices-selection-groups.component';
12
13 describe('OsdDevicesSelectionGroupsComponent', () => {
14   let component: OsdDevicesSelectionGroupsComponent;
15   let fixture: ComponentFixture<OsdDevicesSelectionGroupsComponent>;
16   let fixtureHelper: FixtureHelper;
17   const devices = [
18     {
19       hostname: 'node0',
20       uid: '1',
21       path: 'sda',
22       sys_api: {
23         vendor: 'AAA',
24         model: 'aaa',
25         size: 1024,
26         rotational: 'false',
27         human_readable_size: '1 KB'
28       },
29       available: false,
30       rejected_reasons: [''],
31       device_id: 'AAA-aaa-id0',
32       human_readable_type: 'nvme/ssd',
33       osd_ids: []
34     }
35   ];
36
37   const buttonSelector = '.col-sm-9 button';
38   const getButton = () => {
39     const debugElement = fixtureHelper.getElementByCss(buttonSelector);
40     return debugElement.nativeElement;
41   };
42   const clearTextSelector = '.tc_clearSelections';
43   const getClearText = () => {
44     const debugElement = fixtureHelper.getElementByCss(clearTextSelector);
45     return debugElement.nativeElement;
46   };
47
48   configureTestBed({
49     imports: [FormsModule, SharedModule],
50     providers: [i18nProviders],
51     declarations: [OsdDevicesSelectionGroupsComponent, InventoryDevicesComponent]
52   });
53
54   beforeEach(() => {
55     fixture = TestBed.createComponent(OsdDevicesSelectionGroupsComponent);
56     fixtureHelper = new FixtureHelper(fixture);
57     component = fixture.componentInstance;
58     component.canSelect = true;
59   });
60
61   describe('without available devices', () => {
62     beforeEach(() => {
63       component.availDevices = [];
64       fixture.detectChanges();
65     });
66
67     it('should create', () => {
68       expect(component).toBeTruthy();
69     });
70
71     it('should display Add button in disabled state', () => {
72       const button = getButton();
73       expect(button).toBeTruthy();
74       expect(button.disabled).toBe(true);
75       expect(button.textContent).toBe('Add');
76     });
77
78     it('should not display devices table', () => {
79       fixtureHelper.expectElementVisible('cd-inventory-devices', false);
80     });
81   });
82
83   describe('without devices selected', () => {
84     beforeEach(() => {
85       component.availDevices = devices;
86       fixture.detectChanges();
87     });
88
89     it('should create', () => {
90       expect(component).toBeTruthy();
91     });
92
93     it('should display Add button in enabled state', () => {
94       const button = getButton();
95       expect(button).toBeTruthy();
96       expect(button.disabled).toBe(false);
97       expect(button.textContent).toBe('Add');
98     });
99
100     it('should not display devices table', () => {
101       fixtureHelper.expectElementVisible('cd-inventory-devices', false);
102     });
103   });
104
105   describe('with devices selected', () => {
106     beforeEach(() => {
107       component.availDevices = [];
108       component.devices = devices;
109       fixture.detectChanges();
110     });
111
112     it('should display clear link', () => {
113       const text = getClearText();
114       expect(text).toBeTruthy();
115       expect(text.textContent).toBe('Clear');
116     });
117
118     it('should display devices table', () => {
119       fixtureHelper.expectElementVisible('cd-inventory-devices', true);
120     });
121
122     it('should clear devices by clicking Clear link', () => {
123       spyOn(component.cleared, 'emit');
124       fixtureHelper.clickElement(clearTextSelector);
125       fixtureHelper.expectElementVisible('cd-inventory-devices', false);
126       const event = {
127         type: undefined,
128         clearedDevices: devices
129       };
130       expect(component.cleared.emit).toHaveBeenCalledWith(event);
131     });
132   });
133 });