Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mbraak committed Dec 26, 2024
1 parent 1e11526 commit c077179
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/test/dragAndDropHandler/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,51 @@ describe(".mouseStop", () => {
}),
);
});

it("calls tree.moveNode", () => {
const tree = new Node(null, true);
const node1 = new Node({ name: "node1" });
tree.addChild(node1);
const node2 = new Node({ name: "node2" });
tree.addChild(node2);

const mockMoveNode = jest.spyOn(tree, "moveNode");

const { dragAndDropHandler } = createDragAndDropHandler({
tree,
});

// Capture
const positionInfo = {
originalEvent: new Event("click"),
pageX: 10,
pageY: 10,
target: node1.element as HTMLElement,
};

dragAndDropHandler.mouseCapture(positionInfo);
expect(dragAndDropHandler.currentItem?.node).toBe(node1);

// Start
expect(dragAndDropHandler.mouseStart(positionInfo)).toBeTrue();
expect(dragAndDropHandler.isDragging).toBeTrue();

// Drag
const dragPositionInfo = {
originalEvent: new Event("mousemove"),
pageX: 15,
pageY: 30,
target: node2.element as HTMLElement,
};

dragAndDropHandler.mouseDrag(dragPositionInfo);
expect(dragAndDropHandler.hoveredArea?.node).toEqual(node2);

// Stop
dragAndDropHandler.mouseStop(dragPositionInfo);

expect(mockMoveNode).toHaveBeenCalledWith(node1, node2, "inside");
});
});

describe(".mouseDrag", () => {
Expand Down

0 comments on commit c077179

Please sign in to comment.