1 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { TreeModel, TreeModule } from 'angular-tree-component';
4 import * as _ from 'lodash';
6 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
7 import { configureTestBed, i18nProviders } 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],
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 = undefined;
45 component.selection = {
46 target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
47 portals: [{ host: 'node1', ip: '192.168.100.201' }],
52 backstore: 'backstore:1',
53 controls: { hw_max_sectors: 1 }
58 client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
59 luns: [{ pool: 'rbd', image: 'disk_1' }],
61 user: 'myiscsiusername'
65 ip_address: ['192.168.200.1'],
66 state: { LOGGED_IN: ['node1'] }
71 target_controls: { dataout_timeout: 2 }
74 fixture.detectChanges();
77 it('should create', () => {
78 expect(component).toBeTruthy();
81 it('should empty data and generateTree when ngOnChanges is called', () => {
82 const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
83 component.data = tempData;
84 fixture.detectChanges();
86 expect(component.data).toEqual(tempData);
87 expect(component.metadata).toEqual({});
88 expect(component.nodes).toEqual([]);
90 component.ngOnChanges();
92 expect(component.data).toBeUndefined();
93 expect(component.metadata).toEqual({
94 'client_iqn.1994-05.com.redhat:rh7-client': {
95 user: 'myiscsiusername',
97 ip_address: ['192.168.200.1'],
100 disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
101 root: { dataout_timeout: 2 }
103 expect(component.nodes).toEqual([
105 cdIcon: 'fa fa-lg fa fa-bullseye',
109 cdIcon: 'fa fa-lg fa fa-hdd-o',
112 cdIcon: 'fa fa-hdd-o',
113 cdId: 'disk_rbd_disk_1',
121 cdIcon: 'fa fa-lg fa fa-server',
124 cdIcon: 'fa fa-server',
125 name: 'node1:192.168.100.201'
132 cdIcon: 'fa fa-lg fa fa-user',
135 cdIcon: 'fa fa-user',
136 cdId: 'client_iqn.1994-05.com.redhat:rh7-client',
139 cdIcon: 'fa fa-hdd-o',
140 cdId: 'disk_rbd_disk_1',
144 name: 'iqn.1994-05.com.redhat:rh7-client',
152 cdIcon: 'fa fa-lg fa fa-users',
159 name: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
164 describe('should update data when onNodeSelected is called', () => {
168 component.ngOnChanges();
169 tree = component.tree.treeModel;
170 fixture.detectChanges();
173 it('with target selected', () => {
174 const node = tree.getNodeBy({ data: { cdId: 'root' } });
175 component.onNodeSelected(tree, node);
176 expect(component.data).toEqual([
177 { current: 128, default: 128, displayName: 'cmdsn_depth' },
178 { current: 2, default: 20, displayName: 'dataout_timeout' }
182 it('with disk selected', () => {
183 const node = tree.getNodeBy({ data: { cdId: 'disk_rbd_disk_1' } });
184 component.onNodeSelected(tree, node);
185 expect(component.data).toEqual([
186 { current: 1, default: 1024, displayName: 'hw_max_sectors' },
187 { current: 8, default: 8, displayName: 'max_data_area_mb' },
188 { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
192 it('with initiator selected', () => {
193 const node = tree.getNodeBy({ data: { cdId: 'client_iqn.1994-05.com.redhat:rh7-client' } });
194 component.onNodeSelected(tree, node);
195 expect(component.data).toEqual([
196 { current: 'myiscsiusername', default: undefined, displayName: 'user' },
197 { current: 'myhost', default: undefined, displayName: 'alias' },
198 { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
199 { current: ['node1'], default: undefined, displayName: 'logged_in' }
203 it('with any other selected', () => {
204 const node = tree.getNodeBy({ data: { name: 'Disks' } });
205 component.onNodeSelected(tree, node);
206 expect(component.data).toBeUndefined();