add new flag FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE
[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   getState() {
12     return {
13       global: {
14         flags: {
15           "FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE" : true
16         }
17       },
18       service: {
19         serviceInstance: {
20           "serviceInstanceId": {
21             vnfs: {
22               "vnfStoreKey": {
23                 isMissingData: true,
24                 vfModules: {
25                   "vfModulesName": {
26                     "vfModulesName": {
27                       isMissingData: true
28                     }
29                   }
30                 }
31               },
32
33               "vnfStoreKey1": {
34                 isMissingData: false,
35                 vfModules: {
36                   "vfModulesName": {
37                     "vfModulesName": {
38                       isMissingData: false
39                     }
40                   }
41                 }
42               }
43             }
44           }
45         }
46       }
47     }
48   }
49 }
50
51 describe('Drag and drop service', () => {
52   let injector;
53   let service: DragAndDropService;
54   let httpMock: HttpTestingController;
55   let store: NgRedux<AppState>;
56
57   beforeAll(done => (async () => {
58     TestBed.configureTestingModule({
59       imports: [HttpClientTestingModule],
60       providers: [
61         DragAndDropService,
62         {provide: NgRedux, useClass: MockAppStore}]
63     });
64     await TestBed.compileComponents();
65
66     injector = getTestBed();
67     service = injector.get(DragAndDropService);
68     httpMock = injector.get(HttpTestingController);
69     store = injector.get(NgRedux);
70   })().then(done).catch(done.fail));
71
72
73   test('drag should move element position', () => {
74     let nodes = [{
75       "modelCustomizationId": "91415b44-753d-494c-926a-456a9172bbb9",
76       "modelId": "d6557200-ecf2-4641-8094-5393ae3aae60",
77       "modelUniqueId": "91415b44-753d-494c-926a-456a9172bbb9",
78       "missingData": false,
79       "id": "tjjongy92jn",
80       "action": "Create",
81       "inMaint": false,
82       "name": "yoav2_001",
83       "modelName": "VF_vGeraldine 0",
84       "type": "VF",
85       "isEcompGeneratedNaming": true,
86       "networkStoreKey": "VF_vGeraldine 0:0001",
87       "vnfStoreKey": "VF_vGeraldine 0:0001",
88       "typeName": "VNF",
89       "menuActions": {"edit": {}, "showAuditInfo": {}, "duplicate": {}, "remove": {}, "delete": {}, "undoDelete": {}},
90       "isFailed": false,
91       "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, {
92         "key": "Orch Status:",
93         "testId": "orchStatus"
94       }],
95       "trackById": "di9khuolht",
96       "parentType": "",
97       "position": 0,
98       "children": [{
99         "modelCustomizationId": "f8c040f1-7e51-4a11-aca8-acf256cfd861",
100         "modelId": "a27f5cfc-7f12-4f99-af08-0af9c3885c87",
101         "modelUniqueId": "f8c040f1-7e51-4a11-aca8-acf256cfd861",
102         "missingData": false,
103         "id": 6654971919519,
104         "action": "Create",
105         "name": "VFModule1",
106         "modelName": "vf_vgeraldine0..VfVgeraldine..base_vflorence..module-0",
107         "type": "VFmodule",
108         "isEcompGeneratedNaming": true,
109         "dynamicInputs": [],
110         "dynamicModelName": "vf_vgeraldine0..VfVgeraldine..base_vflorence..module-0bykqx",
111         "typeName": "M",
112         "menuActions": {"edit": {}, "showAuditInfo": {}, "remove": {}, "delete": {}, "undoDelete": {}},
113         "isFailed": false,
114         "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, {
115           "key": "Orch Status:",
116           "testId": "orchStatus"
117         }],
118         "trackById": "5pfyfah820h",
119         "parentType": "VNF",
120         "position": 0,
121         "errors": {}
122       }, {
123         "modelCustomizationId": "6add59e0-7fe1-4bc4-af48-f8812422ae7c",
124         "modelId": "41708296-e443-4c71-953f-d9a010f059e1",
125         "modelUniqueId": "6add59e0-7fe1-4bc4-af48-f8812422ae7c",
126         "missingData": false,
127         "id": 987761655742,
128         "action": "Create",
129         "name": "VNFModule3",
130         "modelName": "vf_vgeraldine0..VfVgeraldine..vflorence_gpb..module-2",
131         "type": "VFmodule",
132         "isEcompGeneratedNaming": true,
133         "dynamicInputs": [],
134         "dynamicModelName": "vf_vgeraldine0..VfVgeraldine..vflorence_gpb..module-2fjrrc",
135         "typeName": "M",
136         "menuActions": {"edit": {}, "showAuditInfo": {}, "remove": {}, "delete": {}, "undoDelete": {}},
137         "isFailed": false,
138         "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, {
139           "key": "Orch Status:",
140           "testId": "orchStatus"
141         }],
142         "trackById": "i3dllio31bb",
143         "parentType": "VNF",
144         "position": 1,
145         "errors": {}
146       }, {
147         "modelCustomizationId": "55b1be94-671a-403e-a26c-667e9c47d091",
148         "modelId": "522159d5-d6e0-4c2a-aa44-5a542a12a830",
149         "modelUniqueId": "55b1be94-671a-403e-a26c-667e9c47d091",
150         "missingData": false,
151         "id": 873798901625,
152         "action": "Create",
153         "name": "VFModule2",
154         "modelName": "vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1",
155         "type": "VFmodule",
156         "isEcompGeneratedNaming": true,
157         "dynamicInputs": [],
158         "dynamicModelName": "vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1djjni",
159         "typeName": "M",
160         "menuActions": {"edit": {}, "showAuditInfo": {}, "remove": {}, "delete": {}, "undoDelete": {}},
161         "isFailed": false,
162         "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, {
163           "key": "Orch Status:",
164           "testId": "orchStatus"
165         }],
166         "trackById": "w7bvw1nh47s",
167         "parentType": "VNF",
168         "position": 2,
169         "errors": {}
170       }],
171       "errors": {}
172     }, {
173       "modelCustomizationId": "91415b44-753d-494c-926a-456a9172bbb9",
174       "modelId": "d6557200-ecf2-4641-8094-5393ae3aae60",
175       "modelUniqueId": "91415b44-753d-494c-926a-456a9172bbb9",
176       "missingData": false,
177       "id": "dywch8hkomi",
178       "action": "Create",
179       "inMaint": false,
180       "name": "yoav2",
181       "modelName": "VF_vGeraldine 0",
182       "type": "VF",
183       "isEcompGeneratedNaming": true,
184       "networkStoreKey": "VF_vGeraldine 0",
185       "vnfStoreKey": "VF_vGeraldine 0",
186       "typeName": "VNF",
187       "menuActions": {"edit": {}, "showAuditInfo": {}, "duplicate": {}, "remove": {}, "delete": {}, "undoDelete": {}},
188       "isFailed": false,
189       "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, {
190         "key": "Orch Status:",
191         "testId": "orchStatus"
192       }],
193       "trackById": "fjczf1urdqo",
194       "parentType": "",
195       "position": 1,
196       "children": [],
197       "errors": {}
198     }];
199     let from = {
200       data: {
201         type: 'VF',
202         index: 1
203       }
204     };
205
206     let to = {
207       parent: {
208         data: {
209           type: 'VF',
210           index: 0
211         }
212       }
213     };
214     jest.spyOn(service, 'array_move');
215
216     service.drag(store, "serviceInstanceId", nodes, {from, to});
217
218
219     expect(service.array_move).toHaveBeenCalled();
220
221   });
222
223
224 });