]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
95fb5b9589549d735119cfdf9e2420fbaf3c3e34
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2
3 import { NodeEvent, Tree, TreeModule } from 'ng2-tree';
4
5 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
6 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
7 import { SharedModule } from '../../../shared/shared.module';
8 import { IscsiTargetDetailsComponent } from './iscsi-target-details.component';
9
10 import * as _ from 'lodash';
11 import { Icons } from '../../../shared/enum/icons.enum';
12
13 describe('IscsiTargetDetailsComponent', () => {
14   let component: IscsiTargetDetailsComponent;
15   let fixture: ComponentFixture<IscsiTargetDetailsComponent>;
16
17   configureTestBed({
18     declarations: [IscsiTargetDetailsComponent],
19     imports: [TreeModule, SharedModule],
20     providers: [i18nProviders]
21   });
22
23   beforeEach(() => {
24     fixture = TestBed.createComponent(IscsiTargetDetailsComponent);
25     component = fixture.componentInstance;
26
27     component.settings = {
28       config: { minimum_gateways: 2 },
29       disk_default_controls: {
30         'backstore:1': {
31           hw_max_sectors: 1024,
32           max_data_area_mb: 8
33         },
34         'backstore:2': {
35           hw_max_sectors: 1024,
36           max_data_area_mb: 8
37         }
38       },
39       target_default_controls: {
40         cmdsn_depth: 128,
41         dataout_timeout: 20
42       },
43       backstores: ['backstore:1', 'backstore:2'],
44       default_backstore: 'backstore:1'
45     };
46     component.selection = new CdTableSelection();
47     component.selection.selected = [
48       {
49         target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
50         portals: [{ host: 'node1', ip: '192.168.100.201' }],
51         disks: [
52           {
53             pool: 'rbd',
54             image: 'disk_1',
55             backstore: 'backstore:1',
56             controls: { hw_max_sectors: 1 }
57           }
58         ],
59         clients: [
60           {
61             client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
62             luns: [{ pool: 'rbd', image: 'disk_1' }],
63             auth: {
64               user: 'myiscsiusername'
65             },
66             info: {
67               alias: 'myhost',
68               ip_address: ['192.168.200.1'],
69               state: { LOGGED_IN: ['node1'] }
70             }
71           }
72         ],
73         groups: [],
74         target_controls: { dataout_timeout: 2 }
75       }
76     ];
77
78     fixture.detectChanges();
79   });
80
81   it('should create', () => {
82     expect(component).toBeTruthy();
83   });
84
85   it('should empty data and generateTree when ngOnChanges is called', () => {
86     const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
87     component.data = tempData;
88     fixture.detectChanges();
89
90     expect(component.data).toEqual(tempData);
91     expect(component.metadata).toEqual({});
92     expect(component.tree).toEqual(undefined);
93
94     component.ngOnChanges();
95
96     expect(component.data).toBeUndefined();
97     expect(component.metadata).toEqual({
98       'client_iqn.1994-05.com.redhat:rh7-client': {
99         user: 'myiscsiusername',
100         alias: 'myhost',
101         ip_address: ['192.168.200.1'],
102         logged_in: ['node1']
103       },
104       disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
105       root: { dataout_timeout: 2 }
106     });
107     expect(component.tree).toEqual({
108       children: [
109         {
110           children: [{ id: 'disk_rbd_disk_1', value: 'rbd/disk_1' }],
111           settings: {
112             cssClasses: {
113               expanded: _.join([Icons.large, Icons.disk], ' '),
114               leaf: _.join([Icons.disk], ' ')
115             },
116             selectionAllowed: false
117           },
118           value: 'Disks'
119         },
120         {
121           children: [{ value: 'node1:192.168.100.201' }],
122           settings: {
123             cssClasses: {
124               expanded: _.join([Icons.large, Icons.server], ' '),
125               leaf: _.join([Icons.large, Icons.server], ' ')
126             },
127             selectionAllowed: false
128           },
129           value: 'Portals'
130         },
131         {
132           children: [
133             {
134               children: [
135                 {
136                   id: 'disk_rbd_disk_1',
137                   settings: {
138                     cssClasses: {
139                       expanded: _.join([Icons.large, Icons.disk], ' '),
140                       leaf: _.join([Icons.disk], ' ')
141                     }
142                   },
143                   value: 'rbd/disk_1'
144                 }
145               ],
146               id: 'client_iqn.1994-05.com.redhat:rh7-client',
147               status: 'logged_in',
148               value: 'iqn.1994-05.com.redhat:rh7-client'
149             }
150           ],
151           settings: {
152             cssClasses: {
153               expanded: _.join([Icons.large, Icons.user], ' '),
154               leaf: _.join([Icons.user], ' ')
155             },
156             selectionAllowed: false
157           },
158           value: 'Initiators'
159         },
160         {
161           children: [],
162           settings: {
163             cssClasses: {
164               expanded: _.join([Icons.large, Icons.user], ' '),
165               leaf: _.join([Icons.user], ' ')
166             },
167             selectionAllowed: false
168           },
169           value: 'Groups'
170         }
171       ],
172       id: 'root',
173       settings: {
174         cssClasses: { expanded: _.join([Icons.large, Icons.bullseye], ' ') },
175         static: true
176       },
177       value: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
178     });
179   });
180
181   describe('should update data when onNodeSelected is called', () => {
182     beforeEach(() => {
183       component.ngOnChanges();
184     });
185
186     it('with target selected', () => {
187       const tree = new Tree(component.tree);
188       const node = new NodeEvent(tree);
189       component.onNodeSelected(node);
190       expect(component.data).toEqual([
191         { current: 128, default: 128, displayName: 'cmdsn_depth' },
192         { current: 2, default: 20, displayName: 'dataout_timeout' }
193       ]);
194     });
195
196     it('with disk selected', () => {
197       const tree = new Tree(component.tree.children[0].children[0]);
198       const node = new NodeEvent(tree);
199       component.onNodeSelected(node);
200       expect(component.data).toEqual([
201         { current: 1, default: 1024, displayName: 'hw_max_sectors' },
202         { current: 8, default: 8, displayName: 'max_data_area_mb' },
203         { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
204       ]);
205     });
206
207     it('with initiator selected', () => {
208       const tree = new Tree(component.tree.children[2].children[0]);
209       const node = new NodeEvent(tree);
210       component.onNodeSelected(node);
211       expect(component.data).toEqual([
212         { current: 'myiscsiusername', default: undefined, displayName: 'user' },
213         { current: 'myhost', default: undefined, displayName: 'alias' },
214         { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
215         { current: ['node1'], default: undefined, displayName: 'logged_in' }
216       ]);
217     });
218
219     it('with any other selected', () => {
220       const tree = new Tree(component.tree.children[1].children[0]);
221       const node = new NodeEvent(tree);
222       component.onNodeSelected(node);
223       expect(component.data).toBeUndefined();
224     });
225   });
226 });