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