Visualization of the VF Module Sequencing
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / drawing-board-tree / dragAndDrop / dragAndDrop.service.spec.ts
1 import {getTestBed, TestBed} from '@angular/core/testing';
2 import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
3 import {NgRedux} from "@angular-redux/store";
4 import {DragAndDropService} from "./dragAndDrop.service";
5 import {AppState} from "../../../../shared/store/reducers";
6
7 class MockAppStore<T> {
8   dispatch() {
9
10   }
11
12   getState() {
13     return {
14       global: {
15         flags: {
16           "FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE": true,
17           "FLAG_2008_DISABLE_DRAG_FOR_BASE_MODULE":true
18         }
19       },
20       service: {
21         serviceHierarchy:{
22           "serviceInstanceId":{
23             vfModules: {
24               "vfModulesName":{
25                 properties:{
26                   baseModule:true
27                 }
28               }
29             }
30           }
31         },
32         serviceInstance: {
33           "serviceInstanceId": {
34             vnfs: {
35               "vnfStoreKey": {
36                 isMissingData: true,
37                 vfModules: {
38                   "vfModulesName": {
39                     "vfModulesName": {
40                       isMissingData: true
41                     }
42                   }
43                 }
44               },
45
46               "vnfStoreKey1": {
47                 isMissingData: false,
48                 vfModules: {
49                   "vfModulesName": {
50                     "vfModulesName": {
51                       isMissingData: false
52                     }
53                   }
54                 }
55               }
56             }
57           }
58         }
59       }
60     }
61   }
62 }
63
64 describe('Drag and drop service', () => {
65   let injector;
66   let service: DragAndDropService;
67   let httpMock: HttpTestingController;
68   let store: NgRedux<AppState>;
69   let nodes;
70
71   beforeAll(done => (async () => {
72     TestBed.configureTestingModule({
73       imports: [HttpClientTestingModule],
74       providers: [
75         DragAndDropService,
76         {provide: NgRedux, useClass: MockAppStore}]
77     });
78     await TestBed.compileComponents();
79
80     injector = getTestBed();
81     service = injector.get(DragAndDropService);
82     httpMock = injector.get(HttpTestingController);
83     store = injector.get(NgRedux);
84
85
86   })().then(done).catch(done.fail));
87
88   beforeEach(() => {
89     nodes = [
90       {
91         "trackById": "ckfqe3sb3y8",
92         "componentInfoType": "VNF",
93         "parentType": "",
94         "type": "VF",
95         "typeName": "VNF",
96         "instanceName": "2017-488_PASQUALE-vPE",
97         "id": "04686zg11ur2",
98         "children": [
99           {
100             "id": "1150884479608",
101             "action": "Create",
102             "instanceName": "puwesovabe",
103             "name": "puwesovabe",
104             "type": "VFmodule",
105             "trackById": "d5if1906rqa",
106             "parentType": "VNF",
107             "position": 1,
108             "componentInfoType": "VFModule",
109             "errors": {},
110             "updatePoistionFunction": () => {
111             },
112           },
113           {
114             "id": "4637423092446",
115             "action": "Create",
116             "instanceName": "bnmgtrx",
117             "name": "bnmgtrx",
118             "type": "VFmodule",
119             "trackById": "9ei9adlh27e",
120             "parentType": "VNF",
121             "position": 2,
122             "componentInfoType": "VFModule",
123             "updatePoistionFunction": () => {
124             }
125           }
126         ],
127         "errors": {},
128       }
129     ];
130   })
131   test('drag should execute array_move when the nodes parent are same', () => {
132
133     let from = {
134       id: "04686zg11ur2",
135       index: 0,
136       data: {
137         instanceName: 'puwesovabe',
138         modelName: 'vocggrapitesting0..VocgGrapiTesting..ocgmgr..module-1'
139       },
140       parent: {
141         data: {
142           type: 'VF',
143           index: 0,
144           trackById: 'ckfqe3sb3y8',
145           vnfStoreKey: '2017-488_PASQUALE-vPE 0',
146         }
147       }
148     };
149
150     let to = {
151       parent: {
152         id: "4637423092446",
153         index: 1,
154         data: {
155           instanceName: 'bnmgtrx',
156         },
157         parent: {
158           data: {
159             type: 'VF',
160             trackById: 'ckfqe3sb3y8',
161             vnfStoreKey: '2017-488_PASQUALE-vPE 0',
162           }
163         }
164       }
165     };
166
167     jest.spyOn(service, 'array_move');
168
169     service.drop(store, "serviceInstanceId", nodes, {from, to});
170
171     expect(service.array_move).toHaveBeenCalled();
172
173   });
174
175
176   test('drag shouldnt execute array_move when the nodes parent are different', () => {
177
178     let from = {
179       id: 1150884479608,
180       index: 0,
181       data: {
182         instanceName: '2017-488_PASQUALE-vPE',
183         modelName: 'vocggrapitesting0..VocgGrapiTesting..ocgmgr..module-1'
184       },
185       parent: {}
186     };
187
188     let to = {
189       parent: {
190         id: 4637423092446,
191         index: 1,
192         data: {
193           instanceName: 'bnmgtrx',
194         },
195         parent: {
196           data: {
197             type: 'VF',
198             trackById: '1111',
199             vnfStoreKey: '2017-488_PASQUALE-vPE 0',
200           }
201         }
202       }
203     };
204
205
206     jest.spyOn(service, 'array_move');
207
208     service.drop(store, "serviceInstanceId", nodes, {from, to});
209
210     jest.clearAllMocks();
211
212     expect(service.array_move).not.toHaveBeenCalled();
213
214   });
215
216   test('drop should change nodes index and position', () => {
217
218     let arr: Array<any> = service.array_move(nodes[0].children, 0, 1, "serviceInstanceId", '')
219
220     expect(arr[0]).toMatchObject({instanceName: "bnmgtrx", position: 1});
221     expect(arr[1]).toMatchObject({instanceName: "puwesovabe", position: 2});
222
223   });
224
225   test('drag shouldnt execute isAllowDrop when the to index is 0 & the drop node is a base module', () => {
226
227     let from = {
228       id: "04686zg11ur2",
229       index: 1,
230       data: {
231         instanceName: 'puwesovabe',
232         modelName: 'vocggrapitesting0..VocgGrapiTesting..ocgmgr..module-1'
233       },
234       parent: {
235         data: {
236           type: 'VF',
237           index: 0,
238           trackById: 'ckfqe3sb3y8',
239           vnfStoreKey: '2017-488_PASQUALE-vPE 0',
240         }
241       }
242     };
243
244     let to = {
245       parent: {
246         id: "4637423092446",
247         index: 0,
248         data: {
249           instanceName: 'bnmgtrx',
250         },
251         parent: {
252           data: {
253             type: 'VF',
254             trackById: 'ckfqe3sb3y8',
255             vnfStoreKey: '2017-488_PASQUALE-vPE 0',
256           }
257         }
258       }
259     };
260
261
262     jest.spyOn(service, 'isAllowDrop');
263
264     service.drop(store, "serviceInstanceId", nodes, {from, to});
265
266     jest.clearAllMocks();
267
268     expect(service.isAllowDrop).not.toHaveBeenCalled();
269
270   });
271
272   test('drag shouldnt execute isAllowDrop when the from node is base module', () => {
273
274     let from = {
275       id: "04686zg11ur2",
276       index: 0,
277       data: {
278         instanceName: 'puwesovabe',
279         modelName: 'vocggrapitesting0..VocgGrapiTesting..ocgmgr..module-1'
280       },
281       parent: {
282         data: {
283           type: 'VF',
284           index: 0,
285           trackById: 'ckfqe3sb3y8',
286           vnfStoreKey: '2017-488_PASQUALE-vPE 0',
287         }
288       }
289     };
290
291     let to = {
292       parent: {
293         id: "4637423092446",
294         index: 1,
295         data: {
296           instanceName: 'bnmgtrx',
297         },
298         parent: {
299           data: {
300             type: 'VF',
301             trackById: 'ckfqe3sb3y8',
302             vnfStoreKey: '2017-488_PASQUALE-vPE 0',
303           }
304         }
305       }
306     };
307
308
309     jest.spyOn(service, 'isAllowDrop');
310
311     service.drop(store, "serviceInstanceId", nodes, {from, to});
312
313     jest.clearAllMocks();
314
315     expect(service.isAllowDrop).not.toHaveBeenCalled();
316
317   });
318
319
320 });