1 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { NodeEvent, Tree, TreeModule } from 'ng2-tree';
5 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
6 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
7 import { SharedModule } from '../../../shared/shared.module';
8 import { IscsiTargetDetailsComponent } from './iscsi-target-details.component';
10 import * as _ from 'lodash';
11 import { Icons } from '../../../shared/enum/icons.enum';
13 describe('IscsiTargetDetailsComponent', () => {
14 let component: IscsiTargetDetailsComponent;
15 let fixture: ComponentFixture<IscsiTargetDetailsComponent>;
18 declarations: [IscsiTargetDetailsComponent],
19 imports: [TreeModule, SharedModule],
20 providers: [i18nProviders]
24 fixture = TestBed.createComponent(IscsiTargetDetailsComponent);
25 component = fixture.componentInstance;
27 component.settings = {
28 config: { minimum_gateways: 2 },
29 disk_default_controls: {
39 target_default_controls: {
43 backstores: ['backstore:1', 'backstore:2'],
44 default_backstore: 'backstore:1'
46 component.selection = new CdTableSelection();
47 component.selection.selected = [
49 target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
50 portals: [{ host: 'node1', ip: '192.168.100.201' }],
55 backstore: 'backstore:1',
56 controls: { hw_max_sectors: 1 }
61 client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
62 luns: [{ pool: 'rbd', image: 'disk_1' }],
64 user: 'myiscsiusername'
68 ip_address: ['192.168.200.1'],
69 state: { LOGGED_IN: ['node1'] }
74 target_controls: { dataout_timeout: 2 }
77 component.selection.update();
79 fixture.detectChanges();
82 it('should create', () => {
83 expect(component).toBeTruthy();
86 it('should empty data and generateTree when ngOnChanges is called', () => {
87 const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
88 component.data = tempData;
89 fixture.detectChanges();
91 expect(component.data).toEqual(tempData);
92 expect(component.metadata).toEqual({});
93 expect(component.tree).toEqual(undefined);
95 component.ngOnChanges();
97 expect(component.data).toBeUndefined();
98 expect(component.metadata).toEqual({
99 'client_iqn.1994-05.com.redhat:rh7-client': {
100 user: 'myiscsiusername',
102 ip_address: ['192.168.200.1'],
105 disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
106 root: { dataout_timeout: 2 }
108 expect(component.tree).toEqual({
111 children: [{ id: 'disk_rbd_disk_1', value: 'rbd/disk_1' }],
114 expanded: _.join([Icons.large, Icons.disk], ' '),
115 leaf: _.join([Icons.disk], ' ')
117 selectionAllowed: false
122 children: [{ value: 'node1:192.168.100.201' }],
125 expanded: _.join([Icons.large, Icons.server], ' '),
126 leaf: _.join([Icons.large, Icons.server], ' ')
128 selectionAllowed: false
137 id: 'disk_rbd_disk_1',
140 expanded: _.join([Icons.large, Icons.disk], ' '),
141 leaf: _.join([Icons.disk], ' ')
147 id: 'client_iqn.1994-05.com.redhat:rh7-client',
149 value: 'iqn.1994-05.com.redhat:rh7-client'
154 expanded: _.join([Icons.large, Icons.user], ' '),
155 leaf: _.join([Icons.user], ' ')
157 selectionAllowed: false
165 expanded: _.join([Icons.large, Icons.user], ' '),
166 leaf: _.join([Icons.user], ' ')
168 selectionAllowed: false
175 cssClasses: { expanded: _.join([Icons.large, Icons.bullseye], ' ') },
178 value: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
182 describe('should update data when onNodeSelected is called', () => {
184 component.ngOnChanges();
187 it('with target selected', () => {
188 const tree = new Tree(component.tree);
189 const node = new NodeEvent(tree);
190 component.onNodeSelected(node);
191 expect(component.data).toEqual([
192 { current: 128, default: 128, displayName: 'cmdsn_depth' },
193 { current: 2, default: 20, displayName: 'dataout_timeout' }
197 it('with disk selected', () => {
198 const tree = new Tree(component.tree.children[0].children[0]);
199 const node = new NodeEvent(tree);
200 component.onNodeSelected(node);
201 expect(component.data).toEqual([
202 { current: 1, default: 1024, displayName: 'hw_max_sectors' },
203 { current: 8, default: 8, displayName: 'max_data_area_mb' },
204 { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
208 it('with initiator selected', () => {
209 const tree = new Tree(component.tree.children[2].children[0]);
210 const node = new NodeEvent(tree);
211 component.onNodeSelected(node);
212 expect(component.data).toEqual([
213 { current: 'myiscsiusername', default: undefined, displayName: 'user' },
214 { current: 'myhost', default: undefined, displayName: 'alias' },
215 { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
216 { current: ['node1'], default: undefined, displayName: 'logged_in' }
220 it('with any other selected', () => {
221 const tree = new Tree(component.tree.children[1].children[0]);
222 const node = new NodeEvent(tree);
223 component.onNodeSelected(node);
224 expect(component.data).toBeUndefined();