]> 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
update sources to ceph Nautilus 14.2.1
[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 { 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 describe('IscsiTargetDetailsComponent', () => {
11 let component: IscsiTargetDetailsComponent;
12 let fixture: ComponentFixture<IscsiTargetDetailsComponent>;
13
14 configureTestBed({
15 declarations: [IscsiTargetDetailsComponent],
16 imports: [TreeModule, SharedModule],
17 providers: [i18nProviders]
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 = new CdTableSelection();
44 component.selection.selected = [
45 {
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 }
64 ],
65 groups: [],
66 target_controls: { dataout_timeout: 2 }
67 }
68 ];
69 component.selection.update();
70
71 fixture.detectChanges();
72 });
73
74 it('should create', () => {
75 expect(component).toBeTruthy();
76 });
77
78 it('should empty data and generateTree when ngOnChanges is called', () => {
79 const tempData = [{ current: 'baz', default: 'bar', displayName: 'foo' }];
80 component.data = tempData;
81 fixture.detectChanges();
82
83 expect(component.data).toEqual(tempData);
84 expect(component.metadata).toEqual({});
85 expect(component.tree).toEqual(undefined);
86
87 component.ngOnChanges();
88
89 expect(component.data).toBeUndefined();
90 expect(component.metadata).toEqual({
91 'client_iqn.1994-05.com.redhat:rh7-client': { user: 'myiscsiusername' },
92 disk_rbd_disk_1: { backstore: 'backstore:1', controls: { hw_max_sectors: 1 } },
93 root: { dataout_timeout: 2 }
94 });
95 expect(component.tree).toEqual({
96 children: [
97 {
98 children: [{ id: 'disk_rbd_disk_1', value: 'rbd/disk_1' }],
99 settings: {
100 cssClasses: { expanded: 'fa fa-fw fa-hdd-o fa-lg', leaf: 'fa fa-fw fa-hdd-o' },
101 selectionAllowed: false
102 },
103 value: 'Disks'
104 },
105 {
106 children: [{ value: 'node1:192.168.100.201' }],
107 settings: {
108 cssClasses: { expanded: 'fa fa-fw fa-server fa-lg', leaf: 'fa fa-fw fa-server fa-lg' },
109 selectionAllowed: false
110 },
111 value: 'Portals'
112 },
113 {
114 children: [
115 {
116 children: [
117 {
118 id: 'disk_rbd_disk_1',
119 settings: {
120 cssClasses: { expanded: 'fa fa-fw fa-hdd-o fa-lg', leaf: 'fa fa-fw fa-hdd-o' }
121 },
122 value: 'rbd/disk_1'
123 }
124 ],
125 id: 'client_iqn.1994-05.com.redhat:rh7-client',
126 value: 'iqn.1994-05.com.redhat:rh7-client'
127 }
128 ],
129 settings: {
130 cssClasses: { expanded: 'fa fa-fw fa-user fa-lg', leaf: 'fa fa-fw fa-user' },
131 selectionAllowed: false
132 },
133 value: 'Initiators'
134 },
135 {
136 children: [],
137 settings: {
138 cssClasses: { expanded: 'fa fa-fw fa-users fa-lg', leaf: 'fa fa-fw fa-users' },
139 selectionAllowed: false
140 },
141 value: 'Groups'
142 }
143 ],
144 id: 'root',
145 settings: { cssClasses: { expanded: 'fa fa-fw fa-bullseye fa-lg' }, static: true },
146 value: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw'
147 });
148 });
149
150 describe('should update data when onNodeSelected is called', () => {
151 beforeEach(() => {
152 component.ngOnChanges();
153 });
154
155 it('with target selected', () => {
156 const tree = new Tree(component.tree);
157 const node = new NodeEvent(tree);
158 component.onNodeSelected(node);
159 expect(component.data).toEqual([
160 { current: 128, default: 128, displayName: 'cmdsn_depth' },
161 { current: 2, default: 20, displayName: 'dataout_timeout' }
162 ]);
163 });
164
165 it('with disk selected', () => {
166 const tree = new Tree(component.tree.children[0].children[0]);
167 const node = new NodeEvent(tree);
168 component.onNodeSelected(node);
169 expect(component.data).toEqual([
170 { current: 1, default: 1024, displayName: 'hw_max_sectors' },
171 { current: 8, default: 8, displayName: 'max_data_area_mb' },
172 { current: 'backstore:1', default: 'backstore:1', displayName: 'backstore' }
173 ]);
174 });
175
176 it('with initiator selected', () => {
177 const tree = new Tree(component.tree.children[2].children[0]);
178 const node = new NodeEvent(tree);
179 component.onNodeSelected(node);
180 expect(component.data).toEqual([
181 { current: 'myiscsiusername', default: undefined, displayName: 'user' }
182 ]);
183 });
184
185 it('with any other selected', () => {
186 const tree = new Tree(component.tree.children[1].children[0]);
187 const node = new NodeEvent(tree);
188 component.onNodeSelected(node);
189 expect(component.data).toBeUndefined();
190 });
191 });
192 });