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
21 "serviceInstanceId": {
52 describe('Drag and drop service', () => {
54 let service: DragAndDropService;
55 let httpMock: HttpTestingController;
56 let store: NgRedux<AppState>;
59 beforeAll(done => (async () => {
60 TestBed.configureTestingModule({
61 imports: [HttpClientTestingModule],
64 {provide: NgRedux, useClass: MockAppStore}]
66 await TestBed.compileComponents();
68 injector = getTestBed();
69 service = injector.get(DragAndDropService);
70 httpMock = injector.get(HttpTestingController);
71 store = injector.get(NgRedux);
74 })().then(done).catch(done.fail));
79 "trackById": "ckfqe3sb3y8",
80 "componentInfoType": "VNF",
84 "instanceName": "2017-488_PASQUALE-vPE",
88 "id": "1150884479608",
90 "instanceName": "puwesovabe",
93 "trackById": "d5if1906rqa",
96 "componentInfoType": "VFModule",
98 "updatePoistionFunction": () => {
102 "id": "4637423092446",
104 "instanceName": "bnmgtrx",
107 "trackById": "9ei9adlh27e",
110 "componentInfoType": "VFModule",
111 "updatePoistionFunction": () => {
119 test('drag should execute array_move when the nodes parent are same', () => {
125 instanceName: 'puwesovabe',
131 trackById: 'ckfqe3sb3y8',
132 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
142 instanceName: 'bnmgtrx',
147 trackById: 'ckfqe3sb3y8',
148 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
154 jest.spyOn(service, 'array_move');
156 service.drop(store, "serviceInstanceId", nodes, {from, to});
158 expect(service.array_move).toHaveBeenCalled();
163 test('drag shouldnt execute array_move when the nodes parent are different', () => {
169 instanceName: '2017-488_PASQUALE-vPE',
179 instanceName: 'bnmgtrx',
185 vnfStoreKey: '2017-488_PASQUALE-vPE 0',
192 jest.spyOn(service, 'array_move');
194 service.drop(store, "serviceInstanceId", nodes, {from, to});
196 jest.clearAllMocks();
198 expect(service.array_move).not.toHaveBeenCalled();
202 test('drop should change nodes index and position', () => {
204 let arr: Array<any> = service.array_move(nodes[0].children, 0, 1, "serviceInstanceId", '')
206 expect(arr[0]).toMatchObject({instanceName: "bnmgtrx", position: 1});
207 expect(arr[1]).toMatchObject({instanceName: "puwesovabe", position: 2});