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';
7 import { ToastrModule } from 'ngx-toastr';
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';
15 describe('OsdDevicesSelectionGroupsComponent', () => {
16 let component: OsdDevicesSelectionGroupsComponent;
17 let fixture: ComponentFixture<OsdDevicesSelectionGroupsComponent>;
18 let fixtureHelper: FixtureHelper;
19 const devices: InventoryDevice[] = [Mocks.getInventoryDevice('node0', '1')];
21 const buttonSelector = '.cd-col-form-input button';
22 const getButton = () => {
23 const debugElement = fixtureHelper.getElementByCss(buttonSelector);
24 return debugElement.nativeElement;
26 const clearTextSelector = '.tc_clearSelections';
27 const getClearText = () => {
28 const debugElement = fixtureHelper.getElementByCss(clearTextSelector);
29 return debugElement.nativeElement;
34 BrowserAnimationsModule,
36 HttpClientTestingModule,
38 ToastrModule.forRoot(),
41 declarations: [OsdDevicesSelectionGroupsComponent, InventoryDevicesComponent]
45 fixture = TestBed.createComponent(OsdDevicesSelectionGroupsComponent);
46 fixtureHelper = new FixtureHelper(fixture);
47 component = fixture.componentInstance;
48 component.canSelect = true;
51 describe('without available devices', () => {
53 component.availDevices = [];
54 fixture.detectChanges();
57 it('should create', () => {
58 expect(component).toBeTruthy();
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');
68 it('should not display devices table', () => {
69 fixtureHelper.expectElementVisible('cd-inventory-devices', false);
73 describe('without devices selected', () => {
75 component.availDevices = devices;
76 fixture.detectChanges();
79 it('should create', () => {
80 expect(component).toBeTruthy();
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');
90 it('should not display devices table', () => {
91 fixtureHelper.expectElementVisible('cd-inventory-devices', false);
95 describe('with devices selected', () => {
97 component.isOsdPage = true;
98 component.availDevices = [];
99 component.devices = devices;
100 component.ngOnInit();
101 fixture.detectChanges();
104 it('should display clear link', () => {
105 const text = getClearText();
106 expect(text).toBeTruthy();
107 expect(text.textContent).toBe('Clear');
110 it('should display devices table', () => {
111 fixtureHelper.expectElementVisible('cd-inventory-devices', true);
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> = {
120 clearedDevices: devices
122 expect(component.cleared.emit).toHaveBeenCalledWith(event);