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';
6 import { ToastrModule } from 'ngx-toastr';
8 import { InventoryDevice } from '~/app/ceph/cluster/inventory/inventory-devices/inventory-device.model';
9 import { InventoryDevicesComponent } from '~/app/ceph/cluster/inventory/inventory-devices/inventory-devices.component';
10 import { SharedModule } from '~/app/shared/shared.module';
11 import { configureTestBed, FixtureHelper, Mocks } from '~/testing/unit-test-helper';
12 import { OsdDevicesSelectionGroupsComponent } from './osd-devices-selection-groups.component';
14 describe('OsdDevicesSelectionGroupsComponent', () => {
15 let component: OsdDevicesSelectionGroupsComponent;
16 let fixture: ComponentFixture<OsdDevicesSelectionGroupsComponent>;
17 let fixtureHelper: FixtureHelper;
18 const devices: InventoryDevice[] = [Mocks.getInventoryDevice('node0', '1')];
20 const buttonSelector = '.cd-col-form-input button';
21 const getButton = () => {
22 const debugElement = fixtureHelper.getElementByCss(buttonSelector);
23 return debugElement.nativeElement;
25 const clearTextSelector = '.tc_clearSelections';
26 const getClearText = () => {
27 const debugElement = fixtureHelper.getElementByCss(clearTextSelector);
28 return debugElement.nativeElement;
33 BrowserAnimationsModule,
35 HttpClientTestingModule,
37 ToastrModule.forRoot()
39 declarations: [OsdDevicesSelectionGroupsComponent, InventoryDevicesComponent]
43 fixture = TestBed.createComponent(OsdDevicesSelectionGroupsComponent);
44 fixtureHelper = new FixtureHelper(fixture);
45 component = fixture.componentInstance;
46 component.canSelect = true;
49 describe('without available devices', () => {
51 component.availDevices = [];
52 fixture.detectChanges();
55 it('should create', () => {
56 expect(component).toBeTruthy();
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');
66 it('should not display devices table', () => {
67 fixtureHelper.expectElementVisible('cd-inventory-devices', false);
71 describe('without devices selected', () => {
73 component.availDevices = devices;
74 fixture.detectChanges();
77 it('should create', () => {
78 expect(component).toBeTruthy();
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');
88 it('should not display devices table', () => {
89 fixtureHelper.expectElementVisible('cd-inventory-devices', false);
93 describe('with devices selected', () => {
95 component.availDevices = [];
96 component.devices = devices;
97 fixture.detectChanges();
100 it('should display clear link', () => {
101 const text = getClearText();
102 expect(text).toBeTruthy();
103 expect(text.textContent).toBe('Clear');
106 it('should display devices table', () => {
107 fixtureHelper.expectElementVisible('cd-inventory-devices', true);
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> = {
116 clearedDevices: devices
118 expect(component.cleared.emit).toHaveBeenCalledWith(event);