Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('test drag drop with dragPos', () => {
// init selected node
let treeNodes = treeInstance.treeComponent.getTreeNodes();
treeService = treeNodes[1].treeService;
const dragNode = treeElement.querySelectorAll('li')[1]; // 0-0-0
treeService!.setSelectedNode(treeInstance.treeComponent.getTreeNodeByKey('000')!); // set 0-0-0
dispatchTouchEvent(dragNode, 'dragstart');
fixture.detectChanges();
// drop 0-0-0 to 0-0 pre
let targetNode = treeNodes[0]; // 0-0
treeService!.dropAndApply(targetNode, -1);
// get treeNodes again
treeNodes = treeInstance.treeComponent.getTreeNodes();
// now ['0-0-0', '0-0', '0-1', '0-2']
expect(treeNodes[0].title).toEqual('0-0-0');
expect(treeNodes[0].level).toEqual(0);
fixture.detectChanges();
// drop 0-0-0 to 0-0-1 next
treeService!.selectedNode = treeNodes[0];
targetNode = treeNodes[1].getChildren()[0]; // 0-0-1
treeService!.dropAndApply(targetNode, 1);
it('test drag event nzBeforeDrop', () => {
const dragNode = treeElement.querySelector("[title='0-2']") as HTMLElement;
let dropNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
treeInstance.beforeDrop = (): Observable => {
return of(true);
};
fixture.detectChanges();
dispatchTouchEvent(dragNode, 'dragstart');
dispatchTouchEvent(dropNode, 'dragover');
// drop 0-2 to 0-1
dispatchTouchEvent(dropNode, 'drop');
fixture.detectChanges();
dropNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
expect(dropNode.parentElement!.querySelector("[title='0-2']")).toBeDefined();
});
});
it('test drag event nzBeforeDrop', () => {
const dragNode = treeElement.querySelector("[title='0-2']") as HTMLElement;
let dropNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
treeInstance.beforeDrop = (): Observable => {
return of(true);
};
fixture.detectChanges();
dispatchTouchEvent(dragNode, 'dragstart');
dispatchTouchEvent(dropNode, 'dragover');
// drop 0-2 to 0-1
dispatchTouchEvent(dropNode, 'drop');
fixture.detectChanges();
dropNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
expect(dropNode.parentElement!.querySelector("[title='0-2']")).toBeDefined();
});
});
it('test drag event nzBeforeDrop', () => {
const dragNode = treeElement.querySelector("[title='0-2']") as HTMLElement;
let dropNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
treeInstance.beforeDrop = (): Observable => {
return of(true);
};
fixture.detectChanges();
dispatchTouchEvent(dragNode, 'dragstart');
dispatchTouchEvent(dropNode, 'dragover');
// drop 0-2 to 0-1
dispatchTouchEvent(dropNode, 'drop');
fixture.detectChanges();
dropNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
expect(dropNode.parentElement!.querySelector("[title='0-2']")).toBeDefined();
});
});
function touchMoveTrigger(el: HTMLElement, from: { x: number; y: number }, to: { x: number; y: number }): void {
dispatchTouchEvent(el, 'touchstart', from.x, from.y);
dispatchTouchEvent(window.document, 'touchmove', to.x, to.y);
dispatchTouchEvent(window.document, 'touchend');
}
function touchMoveTrigger(el: HTMLElement, from: { x: number; y: number }, to: { x: number; y: number }): void {
dispatchTouchEvent(el, 'touchstart', from.x, from.y);
dispatchTouchEvent(window.document, 'touchmove', to.x, to.y);
dispatchTouchEvent(window.document, 'touchend');
}
function touchMoveTrigger(el: HTMLElement, from: { x: number; y: number }, to: { x: number; y: number }): void {
dispatchTouchEvent(el, 'touchstart', from.x, from.y);
dispatchTouchEvent(window.document, 'touchmove', to.x, to.y);
dispatchTouchEvent(window.document, 'touchend');
}