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