]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
852c7619926784739bee049f223f170d56a3c713
[ceph-ci.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     component.selection.update();
78
79     fixture.detectChanges();
80   });
81
82   it('should create', () => {
83     expect(component).toBeTruthy();
84   });
85
86   it('should empty data and generateTree when ngOnChanges is called', () => {
87     const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
88     component.data = tempData;
89     fixture.detectChanges();
90
91     expect(component.data).toEqual(tempData);
92     expect(component.metadata).toEqual({});
93     expect(component.tree).toEqual(undefined);
94
95     component.ngOnChanges();
96
97     expect(component.data).toBeUndefined();
98     expect(component.metadata).toEqual({
99       'client_iqn.1994-05.com.redhat:rh7-client': {
100         user: 'myiscsiusername',
101         alias: 'myhost',
102         ip_address: ['192.168.200.1'],
103         logged_in: ['node1']
104       },
105       disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
106       root: { dataout_timeout: 2 }
107     });
108     expect(component.tree).toEqual({
109       children: [
110         {
111           children: [{ id: 'disk_rbd_disk_1', value: 'rbd/disk_1' }],
112           settings: {
113             cssClasses: {
114               expanded: _.join([Icons.large, Icons.disk], ' '),
115               leaf: _.join([Icons.disk], ' ')
116             },
117             selectionAllowed: false
118           },
119           value: 'Disks'
120         },
121         {
122           children: [{ value: 'node1:192.168.100.201' }],
123           settings: {
124             cssClasses: {
125               expanded: _.join([Icons.large, Icons.server], ' '),
126               leaf: _.join([Icons.large, Icons.server], ' ')
127             },
128             selectionAllowed: false
129           },
130           value: 'Portals'
131         },
132         {
133           children: [
134             {
135               children: [
136                 {
137                   id: 'disk_rbd_disk_1',
138                   settings: {
139                     cssClasses: {
140                       expanded: _.join([Icons.large, Icons.disk], ' '),
141                       leaf: _.join([Icons.disk], ' ')
142                     }
143                   },
144                   value: 'rbd/disk_1'
145                 }
146               ],
147               id: 'client_iqn.1994-05.com.redhat:rh7-client',
148               status: 'logged_in',
149               value: 'iqn.1994-05.com.redhat:rh7-client'
150             }
151           ],
152           settings: {
153             cssClasses: {
154               expanded: _.join([Icons.large, Icons.user], ' '),
155               leaf: _.join([Icons.user], ' ')
156             },
157             selectionAllowed: false
158           },
159           value: 'Initiators'
160         },
161         {
162           children: [],
163           settings: {
164             cssClasses: {
165               expanded: _.join([Icons.large, Icons.user], ' '),
166               leaf: _.join([Icons.user], ' ')
167             },
168             selectionAllowed: false
169           },
170           value: 'Groups'
171         }
172       ],
173       id: 'root',
174       settings: {
175         cssClasses: { expanded: _.join([Icons.large, Icons.bullseye], ' ') },
176         static: true
177       },
178       value: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
179     });
180   });
181
182   describe('should update data when onNodeSelected is called', () => {
183     beforeEach(() => {
184       component.ngOnChanges();
185     });
186
187     it('with target selected', () => {
188       const tree = new Tree(component.tree);
189       const node = new NodeEvent(tree);
190       component.onNodeSelected(node);
191       expect(component.data).toEqual([
192         { current: 128, default: 128, displayName: 'cmdsn_depth' },
193         { current: 2, default: 20, displayName: 'dataout_timeout' }
194       ]);
195     });
196
197     it('with disk selected', () => {
198       const tree = new Tree(component.tree.children[0].children[0]);
199       const node = new NodeEvent(tree);
200       component.onNodeSelected(node);
201       expect(component.data).toEqual([
202         { current: 1, default: 1024, displayName: 'hw_max_sectors' },
203         { current: 8, default: 8, displayName: 'max_data_area_mb' },
204         { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
205       ]);
206     });
207
208     it('with initiator selected', () => {
209       const tree = new Tree(component.tree.children[2].children[0]);
210       const node = new NodeEvent(tree);
211       component.onNodeSelected(node);
212       expect(component.data).toEqual([
213         { current: 'myiscsiusername', default: undefined, displayName: 'user' },
214         { current: 'myhost', default: undefined, displayName: 'alias' },
215         { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
216         { current: ['node1'], default: undefined, displayName: 'logged_in' }
217       ]);
218     });
219
220     it('with any other selected', () => {
221       const tree = new Tree(component.tree.children[1].children[0]);
222       const node = new NodeEvent(tree);
223       component.onNodeSelected(node);
224       expect(component.data).toBeUndefined();
225     });
226   });
227 });