1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4 import { TreeModel, TreeModule } from 'angular-tree-component';
5 import * as _ from 'lodash';
7 import { configureTestBed } from '../../../../testing/unit-test-helper';
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: [BrowserAnimationsModule, TreeModule.forRoot(), SharedModule]
21 fixture = TestBed.createComponent(IscsiTargetDetailsComponent);
22 component = fixture.componentInstance;
24 component.settings = {
25 config: { minimum_gateways: 2 },
26 disk_default_controls: {
36 target_default_controls: {
40 backstores: ['backstore:1', 'backstore:2'],
41 default_backstore: 'backstore:1'
43 component.selection = undefined;
44 component.selection = {
45 target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
46 portals: [{ host: 'node1', ip: '192.168.100.201' }],
51 backstore: 'backstore:1',
52 controls: { hw_max_sectors: 1 }
57 client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
58 luns: [{ pool: 'rbd', image: 'disk_1' }],
60 user: 'myiscsiusername'
64 ip_address: ['192.168.200.1'],
65 state: { LOGGED_IN: ['node1'] }
70 target_controls: { dataout_timeout: 2 }
73 fixture.detectChanges();
76 it('should create', () => {
77 expect(component).toBeTruthy();
80 it('should empty data and generateTree when ngOnChanges is called', () => {
81 const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
82 component.data = tempData;
83 fixture.detectChanges();
85 expect(component.data).toEqual(tempData);
86 expect(component.metadata).toEqual({});
87 expect(component.nodes).toEqual([]);
89 component.ngOnChanges();
91 expect(component.data).toBeUndefined();
92 expect(component.metadata).toEqual({
93 'client_iqn.1994-05.com.redhat:rh7-client': {
94 user: 'myiscsiusername',
96 ip_address: ['192.168.200.1'],
99 disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
100 root: { dataout_timeout: 2 }
102 expect(component.nodes).toEqual([
104 cdIcon: 'fa fa-lg fa fa-bullseye',
108 cdIcon: 'fa fa-lg fa fa-hdd-o',
111 cdIcon: 'fa fa-hdd-o',
112 cdId: 'disk_rbd_disk_1',
120 cdIcon: 'fa fa-lg fa fa-server',
123 cdIcon: 'fa fa-server',
124 name: 'node1:192.168.100.201'
131 cdIcon: 'fa fa-lg fa fa-user',
134 cdIcon: 'fa fa-user',
135 cdId: 'client_iqn.1994-05.com.redhat:rh7-client',
138 cdIcon: 'fa fa-hdd-o',
139 cdId: 'disk_rbd_disk_1',
143 name: 'iqn.1994-05.com.redhat:rh7-client',
151 cdIcon: 'fa fa-lg fa fa-users',
158 name: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
163 describe('should update data when onNodeSelected is called', () => {
167 component.ngOnChanges();
168 tree = component.tree.treeModel;
169 fixture.detectChanges();
172 it('with target selected', () => {
173 const node = tree.getNodeBy({ data: { cdId: 'root' } });
174 component.onNodeSelected(tree, node);
175 expect(component.data).toEqual([
176 { current: 128, default: 128, displayName: 'cmdsn_depth' },
177 { current: 2, default: 20, displayName: 'dataout_timeout' }
181 it('with disk selected', () => {
182 const node = tree.getNodeBy({ data: { cdId: 'disk_rbd_disk_1' } });
183 component.onNodeSelected(tree, node);
184 expect(component.data).toEqual([
185 { current: 1, default: 1024, displayName: 'hw_max_sectors' },
186 { current: 8, default: 8, displayName: 'max_data_area_mb' },
187 { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
191 it('with initiator selected', () => {
192 const node = tree.getNodeBy({ data: { cdId: 'client_iqn.1994-05.com.redhat:rh7-client' } });
193 component.onNodeSelected(tree, node);
194 expect(component.data).toEqual([
195 { current: 'myiscsiusername', default: undefined, displayName: 'user' },
196 { current: 'myhost', default: undefined, displayName: 'alias' },
197 { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
198 { current: ['node1'], default: undefined, displayName: 'logged_in' }
202 it('with any other selected', () => {
203 const node = tree.getNodeBy({ data: { name: 'Disks' } });
204 component.onNodeSelected(tree, node);
205 expect(component.data).toBeUndefined();