1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { FormsModule } from '@angular/forms';
8 } from '../../../../../testing/unit-test-helper';
9 import { SharedModule } from '../../../../shared/shared.module';
10 import { InventoryDevicesComponent } from '../../inventory/inventory-devices/inventory-devices.component';
11 import { OsdDevicesSelectionGroupsComponent } from './osd-devices-selection-groups.component';
13 describe('OsdDevicesSelectionGroupsComponent', () => {
14 let component: OsdDevicesSelectionGroupsComponent;
15 let fixture: ComponentFixture<OsdDevicesSelectionGroupsComponent>;
16 let fixtureHelper: FixtureHelper;
27 human_readable_size: '1 KB'
30 rejected_reasons: [''],
31 device_id: 'AAA-aaa-id0',
32 human_readable_type: 'nvme/ssd',
37 const buttonSelector = '.col-sm-9 button';
38 const getButton = () => {
39 const debugElement = fixtureHelper.getElementByCss(buttonSelector);
40 return debugElement.nativeElement;
42 const clearTextSelector = '.tc_clearSelections';
43 const getClearText = () => {
44 const debugElement = fixtureHelper.getElementByCss(clearTextSelector);
45 return debugElement.nativeElement;
49 imports: [FormsModule, SharedModule],
50 providers: [i18nProviders],
51 declarations: [OsdDevicesSelectionGroupsComponent, InventoryDevicesComponent]
55 fixture = TestBed.createComponent(OsdDevicesSelectionGroupsComponent);
56 fixtureHelper = new FixtureHelper(fixture);
57 component = fixture.componentInstance;
58 component.canSelect = true;
61 describe('without available devices', () => {
63 component.availDevices = [];
64 fixture.detectChanges();
67 it('should create', () => {
68 expect(component).toBeTruthy();
71 it('should display Add button in disabled state', () => {
72 const button = getButton();
73 expect(button).toBeTruthy();
74 expect(button.disabled).toBe(true);
75 expect(button.textContent).toBe('Add');
78 it('should not display devices table', () => {
79 fixtureHelper.expectElementVisible('cd-inventory-devices', false);
83 describe('without devices selected', () => {
85 component.availDevices = devices;
86 fixture.detectChanges();
89 it('should create', () => {
90 expect(component).toBeTruthy();
93 it('should display Add button in enabled state', () => {
94 const button = getButton();
95 expect(button).toBeTruthy();
96 expect(button.disabled).toBe(false);
97 expect(button.textContent).toBe('Add');
100 it('should not display devices table', () => {
101 fixtureHelper.expectElementVisible('cd-inventory-devices', false);
105 describe('with devices selected', () => {
107 component.availDevices = [];
108 component.devices = devices;
109 fixture.detectChanges();
112 it('should display clear link', () => {
113 const text = getClearText();
114 expect(text).toBeTruthy();
115 expect(text.textContent).toBe('Clear');
118 it('should display devices table', () => {
119 fixtureHelper.expectElementVisible('cd-inventory-devices', true);
122 it('should clear devices by clicking Clear link', () => {
123 spyOn(component.cleared, 'emit');
124 fixtureHelper.clickElement(clearTextSelector);
125 fixtureHelper.expectElementVisible('cd-inventory-devices', false);
128 clearedDevices: devices
130 expect(component.cleared.emit).toHaveBeenCalledWith(event);