1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4 import { TreeModel, TreeModule } from '@circlon/angular-tree-component';
6 import { configureTestBed } from '~/testing/unit-test-helper';
7 import { SharedModule } from '~/app/shared/shared.module';
8 import { IscsiTargetDetailsComponent } from './iscsi-target-details.component';
10 describe('IscsiTargetDetailsComponent', () => {
11 let component: IscsiTargetDetailsComponent;
12 let fixture: ComponentFixture<IscsiTargetDetailsComponent>;
15 declarations: [IscsiTargetDetailsComponent],
16 imports: [BrowserAnimationsModule, TreeModule, SharedModule]
20 fixture = TestBed.createComponent(IscsiTargetDetailsComponent);
21 component = fixture.componentInstance;
23 component.settings = {
24 config: { minimum_gateways: 2 },
25 disk_default_controls: {
35 target_default_controls: {
39 backstores: ['backstore:1', 'backstore:2'],
40 default_backstore: 'backstore:1'
42 component.selection = undefined;
43 component.selection = {
44 target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
45 portals: [{ host: 'node1', ip: '192.168.100.201' }],
50 backstore: 'backstore:1',
51 controls: { hw_max_sectors: 1 }
56 client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
57 luns: [{ pool: 'rbd', image: 'disk_1' }],
59 user: 'myiscsiusername'
63 ip_address: ['192.168.200.1'],
64 state: { LOGGED_IN: ['node1'] }
69 target_controls: { dataout_timeout: 2 }
72 fixture.detectChanges();
75 it('should create', () => {
76 expect(component).toBeTruthy();
79 it('should empty data and generateTree when ngOnChanges is called', () => {
80 const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
81 component.data = tempData;
82 fixture.detectChanges();
84 expect(component.data).toEqual(tempData);
85 expect(component.metadata).toEqual({});
86 expect(component.nodes).toEqual([]);
88 component.ngOnChanges();
90 expect(component.data).toBeUndefined();
91 expect(component.metadata).toEqual({
92 'client_iqn.1994-05.com.redhat:rh7-client': {
93 user: 'myiscsiusername',
95 ip_address: ['192.168.200.1'],
98 disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
99 root: { dataout_timeout: 2 }
101 expect(component.nodes).toEqual([
103 cdIcon: 'fa fa-lg fa fa-bullseye',
107 cdIcon: 'fa fa-lg fa fa-hdd-o',
110 cdIcon: 'fa fa-hdd-o',
111 cdId: 'disk_rbd_disk_1',
119 cdIcon: 'fa fa-lg fa fa-server',
122 cdIcon: 'fa fa-server',
123 name: 'node1:192.168.100.201'
130 cdIcon: 'fa fa-lg fa fa-user',
133 cdIcon: 'fa fa-user',
134 cdId: 'client_iqn.1994-05.com.redhat:rh7-client',
137 cdIcon: 'fa fa-hdd-o',
138 cdId: 'disk_rbd_disk_1',
142 name: 'iqn.1994-05.com.redhat:rh7-client',
150 cdIcon: 'fa fa-lg fa fa-users',
157 name: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
162 describe('should update data when onNodeSelected is called', () => {
166 component.ngOnChanges();
167 tree = component.tree.treeModel;
168 fixture.detectChanges();
171 it('with target selected', () => {
172 const node = tree.getNodeBy({ data: { cdId: 'root' } });
173 component.onNodeSelected(tree, node);
174 expect(component.data).toEqual([
175 { current: 128, default: 128, displayName: 'cmdsn_depth' },
176 { current: 2, default: 20, displayName: 'dataout_timeout' }
180 it('with disk selected', () => {
181 const node = tree.getNodeBy({ data: { cdId: 'disk_rbd_disk_1' } });
182 component.onNodeSelected(tree, node);
183 expect(component.data).toEqual([
184 { current: 1, default: 1024, displayName: 'hw_max_sectors' },
185 { current: 8, default: 8, displayName: 'max_data_area_mb' },
186 { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
190 it('with initiator selected', () => {
191 const node = tree.getNodeBy({ data: { cdId: 'client_iqn.1994-05.com.redhat:rh7-client' } });
192 component.onNodeSelected(tree, node);
193 expect(component.data).toEqual([
194 { current: 'myiscsiusername', default: undefined, displayName: 'user' },
195 { current: 'myhost', default: undefined, displayName: 'alias' },
196 { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
197 { current: ['node1'], default: undefined, displayName: 'logged_in' }
201 it('with any other selected', () => {
202 const node = tree.getNodeBy({ data: { name: 'Disks' } });
203 component.onNodeSelected(tree, node);
204 expect(component.data).toBeUndefined();