]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
28765ca8ee440117a855d6e421a331fe9d99f44f
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormsModule } from '@angular/forms';
4 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5
6 import { ToastrModule } from 'ngx-toastr';
7
8 import { configureTestBed, FixtureHelper, Mocks } from '~/testing/unit-test-helper';
9 import { SharedModule } from '~/app/shared/shared.module';
10 import { InventoryDevice } from '~/app/ceph/cluster/inventory/inventory-devices/inventory-device.model';
11 import { InventoryDevicesComponent } from '~/app/ceph/cluster/inventory/inventory-devices/inventory-devices.component';
12 import { OsdDevicesSelectionGroupsComponent } from './osd-devices-selection-groups.component';
13
14 describe('OsdDevicesSelectionGroupsComponent', () => {
15   let component: OsdDevicesSelectionGroupsComponent;
16   let fixture: ComponentFixture<OsdDevicesSelectionGroupsComponent>;
17   let fixtureHelper: FixtureHelper;
18   const devices: InventoryDevice[] = [Mocks.getInventoryDevice('node0', '1')];
19
20   const buttonSelector = '.cd-col-form-input button';
21   const getButton = () => {
22     const debugElement = fixtureHelper.getElementByCss(buttonSelector);
23     return debugElement.nativeElement;
24   };
25   const clearTextSelector = '.tc_clearSelections';
26   const getClearText = () => {
27     const debugElement = fixtureHelper.getElementByCss(clearTextSelector);
28     return debugElement.nativeElement;
29   };
30
31   configureTestBed({
32     imports: [
33       BrowserAnimationsModule,
34       FormsModule,
35       HttpClientTestingModule,
36       SharedModule,
37       ToastrModule.forRoot()
38     ],
39     declarations: [OsdDevicesSelectionGroupsComponent, InventoryDevicesComponent]
40   });
41
42   beforeEach(() => {
43     fixture = TestBed.createComponent(OsdDevicesSelectionGroupsComponent);
44     fixtureHelper = new FixtureHelper(fixture);
45     component = fixture.componentInstance;
46     component.canSelect = true;
47   });
48
49   describe('without available devices', () => {
50     beforeEach(() => {
51       component.availDevices = [];
52       fixture.detectChanges();
53     });
54
55     it('should create', () => {
56       expect(component).toBeTruthy();
57     });
58
59     it('should display Add button in disabled state', () => {
60       const button = getButton();
61       expect(button).toBeTruthy();
62       expect(button.disabled).toBe(true);
63       expect(button.textContent).toBe('Add');
64     });
65
66     it('should not display devices table', () => {
67       fixtureHelper.expectElementVisible('cd-inventory-devices', false);
68     });
69   });
70
71   describe('without devices selected', () => {
72     beforeEach(() => {
73       component.availDevices = devices;
74       fixture.detectChanges();
75     });
76
77     it('should create', () => {
78       expect(component).toBeTruthy();
79     });
80
81     it('should display Add button in enabled state', () => {
82       const button = getButton();
83       expect(button).toBeTruthy();
84       expect(button.disabled).toBe(false);
85       expect(button.textContent).toBe('Add');
86     });
87
88     it('should not display devices table', () => {
89       fixtureHelper.expectElementVisible('cd-inventory-devices', false);
90     });
91   });
92
93   describe('with devices selected', () => {
94     beforeEach(() => {
95       component.availDevices = [];
96       component.devices = devices;
97       fixture.detectChanges();
98     });
99
100     it('should display clear link', () => {
101       const text = getClearText();
102       expect(text).toBeTruthy();
103       expect(text.textContent).toBe('Clear');
104     });
105
106     it('should display devices table', () => {
107       fixtureHelper.expectElementVisible('cd-inventory-devices', true);
108     });
109
110     it('should clear devices by clicking Clear link', () => {
111       spyOn(component.cleared, 'emit');
112       fixtureHelper.clickElement(clearTextSelector);
113       fixtureHelper.expectElementVisible('cd-inventory-devices', false);
114       const event: Record<string, any> = {
115         type: undefined,
116         clearedDevices: devices
117       };
118       expect(component.cleared.emit).toHaveBeenCalledWith(event);
119     });
120   });
121 });