Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

test(web): verify task ranges against real selection stores

Tin9641247c0bd6
diff --git a/apps/web/src/components/kanban-board/filtered-drag.test.tsx b/apps/web/src/components/kanban-board/filtered-drag.test.tsx
index 6932e5454..86d9ca2b5 100644
--- a/apps/web/src/components/kanban-board/filtered-drag.test.tsx
+++ b/apps/web/src/components/kanban-board/filtered-drag.test.tsx
@@ -35,9 +35,6 @@ vi.mock("@/store/project", () => ({
vi.mock("@/store/background", () => ({
useBackgroundStore: () => ({ setBackground: vi.fn() }),
}));
-vi.mock("@/store/bulk-selection", () => ({
- default: () => ({ setAvailableTasks: vi.fn(), clearFocus: vi.fn() }),
-}));
vi.mock("@/hooks/use-keyboard-shortcuts", () => ({
useRegisterShortcuts: vi.fn(),
}));
diff --git a/apps/web/src/components/list-view/task-row.test.tsx b/apps/web/src/components/list-view/task-row.test.tsx
index 0cc781958..323b9f3cb 100644
--- a/apps/web/src/components/list-view/task-row.test.tsx
+++ b/apps/web/src/components/list-view/task-row.test.tsx
@@ -1,6 +1,14 @@
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
-import { afterEach, describe, expect, it, vi } from "vite-plus/test";
+import {
+ afterEach,
+ beforeEach,
+ describe,
+ expect,
+ it,
+ vi,
+} from "vite-plus/test";
import type Task from "@/types/task";
+import useBulkSelectionStore from "@/store/bulk-selection";
import BacklogTaskRow from "../backlog-list-view/backlog-task-row";
import TaskCard from "../kanban-board/task-card";
import { PublicTaskCard } from "../public-project/task-card";
@@ -9,11 +17,14 @@ import TaskRow from "./task-row";
const useExternalLinks = vi.fn((_taskId: string) => ({ data: [] }));
const useGetLabelsByTask = vi.fn((_taskId: string) => ({ data: [] }));
-const { selectRange, navigate } = vi.hoisted(() => ({
- selectRange: vi.fn(),
+const { navigate } = vi.hoisted(() => ({
navigate: vi.fn(),
}));
+beforeEach(() => {
+ useBulkSelectionStore.setState(useBulkSelectionStore.getInitialState());
+});
+
afterEach(() => {
cleanup();
vi.clearAllMocks();
@@ -57,25 +68,6 @@ vi.mock(
}),
);
-vi.mock("@/store/bulk-selection", () => ({
- default: (
- selector: (state: {
- toggleSelection: (taskId: string) => void;
- selectRange: (taskId: string) => void;
- setSelectionAnchor: (taskId: string) => void;
- selectedTaskIds: Set<string>;
- focusedTaskId: string | null;
- }) => unknown,
- ) =>
- selector({
- toggleSelection: vi.fn(),
- selectRange,
- setSelectionAnchor: vi.fn(),
- selectedTaskIds: new Set<string>(),
- focusedTaskId: null,
- }),
-}));
-
vi.mock("@/store/project", () => ({
default: (
selector?: (state: {
@@ -136,6 +128,8 @@ describe("TaskRow", () => {
it.each(["board", "list"])(
"selects a range with Shift+Enter in the %s view",
(view) => {
+ useBulkSelectionStore.getState().setAvailableTasks(["anchor", task.id]);
+ useBulkSelectionStore.getState().setSelectionAnchor("anchor");
render(
view === "board" ? (
<TaskCard task={task} />
@@ -149,7 +143,9 @@ describe("TaskRow", () => {
shiftKey: true,
});
- expect(selectRange).toHaveBeenCalledWith(task.id);
+ expect(useBulkSelectionStore.getState().selectedTaskIds).toEqual(
+ new Set(["anchor", task.id]),
+ );
expect(navigate).not.toHaveBeenCalled();
fireEvent.keyDown(screen.getByText("Row from payload"), { key: "Enter" });
@@ -157,6 +153,44 @@ describe("TaskRow", () => {
},
);
+ it.each(["board", "list"])(
+ "selects a visible range with Shift+click and preserves Ctrl/Cmd toggling in the %s view",
+ (view) => {
+ const otherTask = { ...task, id: "task-2", title: "Second task" };
+ useBulkSelectionStore
+ .getState()
+ .setAvailableTasks([task.id, "middle", otherTask.id]);
+ render(
+ <>
+ {view === "board" ? (
+ <TaskCard task={task} />
+ ) : (
+ <TaskRow task={task} projectSlug="kan" />
+ )}
+ {view === "board" ? (
+ <TaskCard task={otherTask} />
+ ) : (
+ <TaskRow task={otherTask} projectSlug="kan" />
+ )}
+ </>,
+ );
+ fireEvent.click(screen.getByText(task.title));
+ expect(navigate).toHaveBeenCalled();
+ navigate.mockClear();
+ fireEvent.click(screen.getByText(otherTask.title), { shiftKey: true });
+ expect(useBulkSelectionStore.getState().selectedTaskIds).toEqual(
+ new Set([task.id, "middle", otherTask.id]),
+ );
+ expect(navigate).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByText(task.title), { ctrlKey: true });
+ fireEvent.click(screen.getByText(otherTask.title), { metaKey: true });
+ expect(useBulkSelectionStore.getState().selectedTaskIds).toEqual(
+ new Set(["middle"]),
+ );
+ expect(navigate).not.toHaveBeenCalled();
+ },
+ );
+
it.each([PublicTaskCard, PublicTaskRow])(
"renders public progress without nesting interactive controls",
(Component) => {
diff --git a/apps/web/src/store/bulk-selection.test.ts b/apps/web/src/store/bulk-selection.test.ts
index 155ca52e4..485325193 100644
--- a/apps/web/src/store/bulk-selection.test.ts
+++ b/apps/web/src/store/bulk-selection.test.ts
@@ -39,6 +39,14 @@ describe.each(stores)("%s range selection", (_name, store) => {
expect(store.getState().selectionAnchorId).toBe("e");
});
+ it("follows the current visible order after filtering or reordering", () => {
+ store.getState().toggleSelection("a");
+ store.getState().setAvailableTasks(["e", "a", "d", "c"]);
+ store.getState().selectRange("c");
+ expect(store.getState().selectedTaskIds).toEqual(new Set(["a", "d", "c"]));
+ expect(store.getState().selectionAnchorId).toBe("a");
+ });
+
it("clears the anchor with the selection", () => {
store.getState().toggleSelection("b");
store.getState().clearSelection();