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