]> 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
import 15.2.4
[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 { BrowserAnimationsModule } from '@angular/platform-browser/animations';
7 import { configureTestBed, i18nProviders } 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 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 = undefined;
45 component.selection = {
46 target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
47 portals: [{ host: 'node1', ip: '192.168.100.201' }],
48 disks: [
49 {
50 pool: 'rbd',
51 image: 'disk_1',
52 backstore: 'backstore:1',
53 controls: { hw_max_sectors: 1 }
54 }
55 ],
56 clients: [
57 {
58 client_iqn: 'iqn.1994-05.com.redhat:rh7-client',
59 luns: [{ pool: 'rbd', image: 'disk_1' }],
60 auth: {
61 user: 'myiscsiusername'
62 },
63 info: {
64 alias: 'myhost',
65 ip_address: ['192.168.200.1'],
66 state: { LOGGED_IN: ['node1'] }
67 }
68 }
69 ],
70 groups: [],
71 target_controls: { dataout_timeout: 2 }
72 };
73
74 fixture.detectChanges();
75 });
76
77 it('should create', () => {
78 expect(component).toBeTruthy();
79 });
80
81 it('should empty data and generateTree when ngOnChanges is called', () => {
82 const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
83 component.data = tempData;
84 fixture.detectChanges();
85
86 expect(component.data).toEqual(tempData);
87 expect(component.metadata).toEqual({});
88 expect(component.nodes).toEqual([]);
89
90 component.ngOnChanges();
91
92 expect(component.data).toBeUndefined();
93 expect(component.metadata).toEqual({
94 'client_iqn.1994-05.com.redhat:rh7-client': {
95 user: 'myiscsiusername',
96 alias: 'myhost',
97 ip_address: ['192.168.200.1'],
98 logged_in: ['node1']
99 },
100 disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
101 root: { dataout_timeout: 2 }
102 });
103 expect(component.nodes).toEqual([
104 {
105 cdIcon: 'fa fa-lg fa fa-bullseye',
106 cdId: 'root',
107 children: [
108 {
109 cdIcon: 'fa fa-lg fa fa-hdd-o',
110 children: [
111 {
112 cdIcon: 'fa fa-hdd-o',
113 cdId: 'disk_rbd_disk_1',
114 name: 'rbd/disk_1'
115 }
116 ],
117 isExpanded: true,
118 name: 'Disks'
119 },
120 {
121 cdIcon: 'fa fa-lg fa fa-server',
122 children: [
123 {
124 cdIcon: 'fa fa-server',
125 name: 'node1:192.168.100.201'
126 }
127 ],
128 isExpanded: true,
129 name: 'Portals'
130 },
131 {
132 cdIcon: 'fa fa-lg fa fa-user',
133 children: [
134 {
135 cdIcon: 'fa fa-user',
136 cdId: 'client_iqn.1994-05.com.redhat:rh7-client',
137 children: [
138 {
139 cdIcon: 'fa fa-hdd-o',
140 cdId: 'disk_rbd_disk_1',
141 name: 'rbd/disk_1'
142 }
143 ],
144 name: 'iqn.1994-05.com.redhat:rh7-client',
145 status: 'logged_in'
146 }
147 ],
148 isExpanded: true,
149 name: 'Initiators'
150 },
151 {
152 cdIcon: 'fa fa-lg fa fa-users',
153 children: [],
154 isExpanded: true,
155 name: 'Groups'
156 }
157 ],
158 isExpanded: true,
159 name: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
160 }
161 ]);
162 });
163
164 describe('should update data when onNodeSelected is called', () => {
165 let tree: TreeModel;
166
167 beforeEach(() => {
168 component.ngOnChanges();
169 tree = component.tree.treeModel;
170 fixture.detectChanges();
171 });
172
173 it('with target selected', () => {
174 const node = tree.getNodeBy({ data: { cdId: 'root' } });
175 component.onNodeSelected(tree, node);
176 expect(component.data).toEqual([
177 { current: 128, default: 128, displayName: 'cmdsn_depth' },
178 { current: 2, default: 20, displayName: 'dataout_timeout' }
179 ]);
180 });
181
182 it('with disk selected', () => {
183 const node = tree.getNodeBy({ data: { cdId: 'disk_rbd_disk_1' } });
184 component.onNodeSelected(tree, node);
185 expect(component.data).toEqual([
186 { current: 1, default: 1024, displayName: 'hw_max_sectors' },
187 { current: 8, default: 8, displayName: 'max_data_area_mb' },
188 { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
189 ]);
190 });
191
192 it('with initiator selected', () => {
193 const node = tree.getNodeBy({ data: { cdId: 'client_iqn.1994-05.com.redhat:rh7-client' } });
194 component.onNodeSelected(tree, node);
195 expect(component.data).toEqual([
196 { current: 'myiscsiusername', default: undefined, displayName: 'user' },
197 { current: 'myhost', default: undefined, displayName: 'alias' },
198 { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
199 { current: ['node1'], default: undefined, displayName: 'logged_in' }
200 ]);
201 });
202
203 it('with any other selected', () => {
204 const node = tree.getNodeBy({ data: { name: 'Disks' } });
205 component.onNodeSelected(tree, node);
206 expect(component.data).toBeUndefined();
207 });
208 });
209 });