]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
e0cef596b6a320bed29e7a1b986cbba8fd660075
[ceph-ci.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3
4 import { TreeModel, TreeModule } from 'angular-tree-component';
5 import * as _ from 'lodash';
6
7 import { configureTestBed } from '../../../../testing/unit-test-helper';
8 import { SharedModule } from '../../../shared/shared.module';
9 import { IscsiTargetDetailsComponent } from './iscsi-target-details.component';
10
11 describe('IscsiTargetDetailsComponent', () => {
12   let component: IscsiTargetDetailsComponent;
13   let fixture: ComponentFixture<IscsiTargetDetailsComponent>;
14
15   configureTestBed({
16     declarations: [IscsiTargetDetailsComponent],
17     imports: [BrowserAnimationsModule, TreeModule.forRoot(), SharedModule]
18   });
19
20   beforeEach(() => {
21     fixture = TestBed.createComponent(IscsiTargetDetailsComponent);
22     component = fixture.componentInstance;
23
24     component.settings = {
25       config: { minimum_gateways: 2 },
26       disk_default_controls: {
27         'backstore:1': {
28           hw_max_sectors: 1024,
29           max_data_area_mb: 8
30         },
31         'backstore:2': {
32           hw_max_sectors: 1024,
33           max_data_area_mb: 8
34         }
35       },
36       target_default_controls: {
37         cmdsn_depth: 128,
38         dataout_timeout: 20
39       },
40       backstores: ['backstore:1', 'backstore:2'],
41       default_backstore: 'backstore:1'
42     };
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' }],
47       disks: [
48         {
49           pool: 'rbd',
50           image: 'disk_1',
51           backstore: 'backstore:1',
52           controls: { hw_max_sectors: 1 }
53         }
54       ],
55       clients: [
56         {
57           client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
58           luns: [{ pool: 'rbd', image: 'disk_1' }],
59           auth: {
60             user: 'myiscsiusername'
61           },
62           info: {
63             alias: 'myhost',
64             ip_address: ['192.168.200.1'],
65             state: { LOGGED_IN: ['node1'] }
66           }
67         }
68       ],
69       groups: [],
70       target_controls: { dataout_timeout: 2 }
71     };
72
73     fixture.detectChanges();
74   });
75
76   it('should create', () => {
77     expect(component).toBeTruthy();
78   });
79
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();
84
85     expect(component.data).toEqual(tempData);
86     expect(component.metadata).toEqual({});
87     expect(component.nodes).toEqual([]);
88
89     component.ngOnChanges();
90
91     expect(component.data).toBeUndefined();
92     expect(component.metadata).toEqual({
93       'client_iqn.1994-05.com.redhat:rh7-client': {
94         user: 'myiscsiusername',
95         alias: 'myhost',
96         ip_address: ['192.168.200.1'],
97         logged_in: ['node1']
98       },
99       disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
100       root: { dataout_timeout: 2 }
101     });
102     expect(component.nodes).toEqual([
103       {
104         cdIcon: 'fa fa-lg fa fa-bullseye',
105         cdId: 'root',
106         children: [
107           {
108             cdIcon: 'fa fa-lg fa fa-hdd-o',
109             children: [
110               {
111                 cdIcon: 'fa fa-hdd-o',
112                 cdId: 'disk_rbd_disk_1',
113                 name: 'rbd/disk_1'
114               }
115             ],
116             isExpanded: true,
117             name: 'Disks'
118           },
119           {
120             cdIcon: 'fa fa-lg fa fa-server',
121             children: [
122               {
123                 cdIcon: 'fa fa-server',
124                 name: 'node1:192.168.100.201'
125               }
126             ],
127             isExpanded: true,
128             name: 'Portals'
129           },
130           {
131             cdIcon: 'fa fa-lg fa fa-user',
132             children: [
133               {
134                 cdIcon: 'fa fa-user',
135                 cdId: 'client_iqn.1994-05.com.redhat:rh7-client',
136                 children: [
137                   {
138                     cdIcon: 'fa fa-hdd-o',
139                     cdId: 'disk_rbd_disk_1',
140                     name: 'rbd/disk_1'
141                   }
142                 ],
143                 name: 'iqn.1994-05.com.redhat:rh7-client',
144                 status: 'logged_in'
145               }
146             ],
147             isExpanded: true,
148             name: 'Initiators'
149           },
150           {
151             cdIcon: 'fa fa-lg fa fa-users',
152             children: [],
153             isExpanded: true,
154             name: 'Groups'
155           }
156         ],
157         isExpanded: true,
158         name: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
159       }
160     ]);
161   });
162
163   describe('should update data when onNodeSelected is called', () => {
164     let tree: TreeModel;
165
166     beforeEach(() => {
167       component.ngOnChanges();
168       tree = component.tree.treeModel;
169       fixture.detectChanges();
170     });
171
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' }
178       ]);
179     });
180
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' }
188       ]);
189     });
190
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' }
199       ]);
200     });
201
202     it('with any other selected', () => {
203       const node = tree.getNodeBy({ data: { name: 'Disks' } });
204       component.onNodeSelected(tree, node);
205       expect(component.data).toBeUndefined();
206     });
207   });
208 });