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 }
78 fixture.detectChanges();
81 it('should create', () => {
82 expect(component).toBeTruthy();
85 it('should empty data and generateTree when ngOnChanges is called', () => {
86 const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
87 component.data = tempData;
88 fixture.detectChanges();
90 expect(component.data).toEqual(tempData);
91 expect(component.metadata).toEqual({});
92 expect(component.tree).toEqual(undefined);
94 component.ngOnChanges();
96 expect(component.data).toBeUndefined();
97 expect(component.metadata).toEqual({
98 'client_iqn.1994-05.com.redhat:rh7-client': {
99 user: 'myiscsiusername',
101 ip_address: ['192.168.200.1'],
104 disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
105 root: { dataout_timeout: 2 }
107 expect(component.tree).toEqual({
110 children: [{ id: 'disk_rbd_disk_1', value: 'rbd/disk_1' }],
113 expanded: _.join([Icons.large, Icons.disk], ' '),
114 leaf: _.join([Icons.disk], ' ')
116 selectionAllowed: false
121 children: [{ value: 'node1:192.168.100.201' }],
124 expanded: _.join([Icons.large, Icons.server], ' '),
125 leaf: _.join([Icons.large, Icons.server], ' ')
127 selectionAllowed: false
136 id: 'disk_rbd_disk_1',
139 expanded: _.join([Icons.large, Icons.disk], ' '),
140 leaf: _.join([Icons.disk], ' ')
146 id: 'client_iqn.1994-05.com.redhat:rh7-client',
148 value: 'iqn.1994-05.com.redhat:rh7-client'
153 expanded: _.join([Icons.large, Icons.user], ' '),
154 leaf: _.join([Icons.user], ' ')
156 selectionAllowed: false
164 expanded: _.join([Icons.large, Icons.user], ' '),
165 leaf: _.join([Icons.user], ' ')
167 selectionAllowed: false
174 cssClasses: { expanded: _.join([Icons.large, Icons.bullseye], ' ') },
177 value: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
181 describe('should update data when onNodeSelected is called', () => {
183 component.ngOnChanges();
186 it('with target selected', () => {
187 const tree = new Tree(component.tree);
188 const node = new NodeEvent(tree);
189 component.onNodeSelected(node);
190 expect(component.data).toEqual([
191 { current: 128, default: 128, displayName: 'cmdsn_depth' },
192 { current: 2, default: 20, displayName: 'dataout_timeout' }
196 it('with disk selected', () => {
197 const tree = new Tree(component.tree.children[0].children[0]);
198 const node = new NodeEvent(tree);
199 component.onNodeSelected(node);
200 expect(component.data).toEqual([
201 { current: 1, default: 1024, displayName: 'hw_max_sectors' },
202 { current: 8, default: 8, displayName: 'max_data_area_mb' },
203 { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
207 it('with initiator selected', () => {
208 const tree = new Tree(component.tree.children[2].children[0]);
209 const node = new NodeEvent(tree);
210 component.onNodeSelected(node);
211 expect(component.data).toEqual([
212 { current: 'myiscsiusername', default: undefined, displayName: 'user' },
213 { current: 'myhost', default: undefined, displayName: 'alias' },
214 { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
215 { current: ['node1'], default: undefined, displayName: 'logged_in' }
219 it('with any other selected', () => {
220 const tree = new Tree(component.tree.children[1].children[0]);
221 const node = new NodeEvent(tree);
222 component.onNodeSelected(node);
223 expect(component.data).toBeUndefined();