1 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { TreeModel, TreeModule } from 'angular-tree-component';
4 import * as _ from 'lodash';
6 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
7 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
8 import { SharedModule } from '../../../shared/shared.module';
9 import { IscsiTargetDetailsComponent } from './iscsi-target-details.component';
11 describe('IscsiTargetDetailsComponent', () => {
12 let component: IscsiTargetDetailsComponent;
13 let fixture: ComponentFixture<IscsiTargetDetailsComponent>;
16 declarations: [IscsiTargetDetailsComponent],
17 imports: [TreeModule.forRoot(), SharedModule],
18 providers: [i18nProviders]
22 fixture = TestBed.createComponent(IscsiTargetDetailsComponent);
23 component = fixture.componentInstance;
25 component.settings = {
26 config: { minimum_gateways: 2 },
27 disk_default_controls: {
37 target_default_controls: {
41 backstores: ['backstore:1', 'backstore:2'],
42 default_backstore: 'backstore:1'
44 component.selection = new CdTableSelection();
45 component.selection.selected = [
47 target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
48 portals: [{ host: 'node1', ip: '192.168.100.201' }],
53 backstore: 'backstore:1',
54 controls: { hw_max_sectors: 1 }
59 client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
60 luns: [{ pool: 'rbd', image: 'disk_1' }],
62 user: 'myiscsiusername'
66 ip_address: ['192.168.200.1'],
67 state: { LOGGED_IN: ['node1'] }
72 target_controls: { dataout_timeout: 2 }
76 fixture.detectChanges();
79 it('should create', () => {
80 expect(component).toBeTruthy();
83 it('should empty data and generateTree when ngOnChanges is called', () => {
84 const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
85 component.data = tempData;
86 fixture.detectChanges();
88 expect(component.data).toEqual(tempData);
89 expect(component.metadata).toEqual({});
90 expect(component.nodes).toEqual([]);
92 component.ngOnChanges();
94 expect(component.data).toBeUndefined();
95 expect(component.metadata).toEqual({
96 'client_iqn.1994-05.com.redhat:rh7-client': {
97 user: 'myiscsiusername',
99 ip_address: ['192.168.200.1'],
102 disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
103 root: { dataout_timeout: 2 }
105 expect(component.nodes).toEqual([
107 cdIcon: 'fa fa-lg fa fa-bullseye',
111 cdIcon: 'fa fa-lg fa fa-hdd-o',
114 cdIcon: 'fa fa-hdd-o',
115 cdId: 'disk_rbd_disk_1',
123 cdIcon: 'fa fa-lg fa fa-server',
126 cdIcon: 'fa fa-server',
127 name: 'node1:192.168.100.201'
134 cdIcon: 'fa fa-lg fa fa-user',
137 cdIcon: 'fa fa-user',
138 cdId: 'client_iqn.1994-05.com.redhat:rh7-client',
141 cdIcon: 'fa fa-hdd-o',
142 cdId: 'disk_rbd_disk_1',
146 name: 'iqn.1994-05.com.redhat:rh7-client',
154 cdIcon: 'fa fa-lg fa fa-users',
161 name: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
166 describe('should update data when onNodeSelected is called', () => {
170 component.ngOnChanges();
171 tree = component.tree.treeModel;
172 fixture.detectChanges();
175 it('with target selected', () => {
176 const node = tree.getNodeBy({ data: { cdId: 'root' } });
177 component.onNodeSelected(tree, node);
178 expect(component.data).toEqual([
179 { current: 128, default: 128, displayName: 'cmdsn_depth' },
180 { current: 2, default: 20, displayName: 'dataout_timeout' }
184 it('with disk selected', () => {
185 const node = tree.getNodeBy({ data: { cdId: 'disk_rbd_disk_1' } });
186 component.onNodeSelected(tree, node);
187 expect(component.data).toEqual([
188 { current: 1, default: 1024, displayName: 'hw_max_sectors' },
189 { current: 8, default: 8, displayName: 'max_data_area_mb' },
190 { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
194 it('with initiator selected', () => {
195 const node = tree.getNodeBy({ data: { cdId: 'client_iqn.1994-05.com.redhat:rh7-client' } });
196 component.onNodeSelected(tree, node);
197 expect(component.data).toEqual([
198 { current: 'myiscsiusername', default: undefined, displayName: 'user' },
199 { current: 'myhost', default: undefined, displayName: 'alias' },
200 { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
201 { current: ['node1'], default: undefined, displayName: 'logged_in' }
205 it('with any other selected', () => {
206 const node = tree.getNodeBy({ data: { name: 'Disks' } });
207 component.onNodeSelected(tree, node);
208 expect(component.data).toBeUndefined();