Skip to content

Commit

Permalink
chore: Add extra unit test for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris committed Apr 19, 2024
1 parent a4a79a4 commit 78d8221
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/internal/item-container/__tests__/get-next-droppable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { expect, test } from "vitest";
import { Droppable } from "../../dnd-controller/controller";
import { Rect } from "../../interfaces";
import { getNextDroppable } from "../get-next-droppable";

function getMockElement({ left, right, top, bottom }: Rect) {
return {
getBoundingClientRect: () => ({ left, right, top, bottom }),
ownerDocument: {
defaultView: {
pageXOffset: 0,
pageYOffset: 0,
},
},
} as HTMLElement;
}

test("returns null if there are no droppables", () => {
const elementMock = getMockElement({ left: 0, right: 0, top: 0, bottom: 0 });
expect(getNextDroppable(elementMock, [], "left")).toBe(null);
});

test("returns next droppable matching the direction", () => {
const elementMock = getMockElement({ left: 6, right: 4, top: 0, bottom: 0 });
const next = getNextDroppable(
elementMock,
[
["1", { element: getMockElement({ left: 0, right: 10, top: 0, bottom: 0 }) } as Droppable],
["2", { element: getMockElement({ left: 5, right: 5, top: 0, bottom: 0 }) } as Droppable],
["3", { element: getMockElement({ left: 10, right: 0, top: 0, bottom: 0 }) } as Droppable],
],
"right"
);
expect(next).toBe("2");
});

0 comments on commit 78d8221

Please sign in to comment.