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";
7 class MockAppStore<T> {
16 "FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE": true,
17 "FLAG_2008_DISABLE_DRAG_FOR_BASE_MODULE":true
33 "serviceInstanceId": {
64 describe('Drag and drop service', () => {
66 let service: DragAndDropService;
67 let httpMock: HttpTestingController;
68 let store: NgRedux<AppState>;
71 beforeAll(done => (async () => {
72 TestBed.configureTestingModule({
73 imports: [HttpClientTestingModule],
76 {provide: NgRedux, useClass: MockAppStore}]
78 await TestBed.compileComponents();
80 injector = getTestBed();
81 service = injector.get(DragAndDropService);
82 httpMock = injector.get(HttpTestingController);
83 store = injector.get(NgRedux);
86 })().then(done).catch(done.fail));
91 "trackById": "ckfqe3sb3y8",
92 "componentInfoType": "VNF",
96 "instanceName": "2017-488_PASQUALE-vPE",
100 "id": "1150884479608",
102 "instanceName": "puwesovabe",
103 "name": "puwesovabe",
105 "trackById": "d5if1906rqa",
108 "componentInfoType": "VFModule",
110 "updatePoistionFunction": () => {
114 "id": "4637423092446",
116 "instanceName": "bnmgtrx",
119 "trackById": "9ei9adlh27e",
122 "componentInfoType": "VFModule",
123 "updatePoistionFunction": () => {
131 test('drag should execute array_move when the nodes parent are same', () => {
137 instanceName: 'puwesovabe',
138 modelName: 'vocggrapitesting0..VocgGrapiTesting..ocgmgr..module-1'
144 trackById: 'ckfqe3sb3y8',
145 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
155 instanceName: 'bnmgtrx',
160 trackById: 'ckfqe3sb3y8',
161 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
167 jest.spyOn(service, 'array_move');
169 service.drop(store, "serviceInstanceId", nodes, {from, to});
171 expect(service.array_move).toHaveBeenCalled();
176 test('drag shouldnt execute array_move when the nodes parent are different', () => {
182 instanceName: '2017-488_PASQUALE-vPE',
183 modelName: 'vocggrapitesting0..VocgGrapiTesting..ocgmgr..module-1'
193 instanceName: 'bnmgtrx',
199 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
206 jest.spyOn(service, 'array_move');
208 service.drop(store, "serviceInstanceId", nodes, {from, to});
210 jest.clearAllMocks();
212 expect(service.array_move).not.toHaveBeenCalled();
216 test('drop should change nodes index and position', () => {
218 let arr: Array<any> = service.array_move(nodes[0].children, 0, 1, "serviceInstanceId", '')
220 expect(arr[0]).toMatchObject({instanceName: "bnmgtrx", position: 1});
221 expect(arr[1]).toMatchObject({instanceName: "puwesovabe", position: 2});
225 test('drag shouldnt execute isAllowDrop when the to index is 0 & the drop node is a base module', () => {
231 instanceName: 'puwesovabe',
232 modelName: 'vocggrapitesting0..VocgGrapiTesting..ocgmgr..module-1'
238 trackById: 'ckfqe3sb3y8',
239 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
249 instanceName: 'bnmgtrx',
254 trackById: 'ckfqe3sb3y8',
255 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
262 jest.spyOn(service, 'isAllowDrop');
264 service.drop(store, "serviceInstanceId", nodes, {from, to});
266 jest.clearAllMocks();
268 expect(service.isAllowDrop).not.toHaveBeenCalled();
272 test('drag shouldnt execute isAllowDrop when the from node is base module', () => {
278 instanceName: 'puwesovabe',
279 modelName: 'vocggrapitesting0..VocgGrapiTesting..ocgmgr..module-1'
285 trackById: 'ckfqe3sb3y8',
286 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
296 instanceName: 'bnmgtrx',
301 trackById: 'ckfqe3sb3y8',
302 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
309 jest.spyOn(service, 'isAllowDrop');
311 service.drop(store, "serviceInstanceId", nodes, {from, to});
313 jest.clearAllMocks();
315 expect(service.isAllowDrop).not.toHaveBeenCalled();