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