Skip to content

Commit

Permalink
test: add test for narrowing selections (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredLunde authored Apr 25, 2022
1 parent 05b2353 commit 0646312
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/use-selections.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { act, renderHook } from "@testing-library/react-hooks";
import { useSelections } from ".";
import type { Dir } from "./file-tree";
import { createFileTree } from "./file-tree";
import { getNodesFromMockFs, waitForTree } from "./test/utils";

Expand Down Expand Up @@ -254,4 +255,30 @@ describe("useSelections()", () => {
fileTree.visibleNodes[2],
]);
});

it("should narrow selections", async () => {
await waitForTree(fileTree);
const { result } = renderHook(() => useSelections(fileTree));

await act(async () => {
await fileTree.expand(fileTree.getById(fileTree.visibleNodes[0]) as Dir);
});

act(() => {
// @ts-expect-error
result.current.getProps(fileTree.visibleNodes[0]).onClick({});
result.current
.getProps(fileTree.visibleNodes[2])
// @ts-expect-error
.onClick({ shiftKey: true });
});

expect([...result.current.didChange.getState()]).toEqual([
fileTree.visibleNodes[0],
fileTree.visibleNodes[1],
fileTree.visibleNodes[2],
]);

expect([...result.current.narrow()]).toEqual([fileTree.visibleNodes[0]]);
});
});

0 comments on commit 0646312

Please sign in to comment.