feat: add kanban board
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { Task } from "@/model/task";
|
||||
import { buildKanbanBoard } from "./buildKanbanBoard";
|
||||
|
||||
function task(partial: Partial<Task> & Pick<Task, "id" | "title">): Task {
|
||||
return {
|
||||
description: "",
|
||||
status: "todo",
|
||||
priority: "medium",
|
||||
tags: [],
|
||||
assignee: "",
|
||||
created: "2026-01-01T00:00:00.000Z",
|
||||
updated: "2026-01-01T00:00:00.000Z",
|
||||
...partial,
|
||||
};
|
||||
}
|
||||
|
||||
describe("buildKanbanBoard", () => {
|
||||
const tasks: Task[] = [
|
||||
task({
|
||||
id: "a",
|
||||
title: "Done one",
|
||||
status: "done",
|
||||
updated: "2026-01-01T00:00:02.000Z",
|
||||
}),
|
||||
task({
|
||||
id: "b",
|
||||
title: "Todo older",
|
||||
status: "todo",
|
||||
updated: "2026-01-01T00:00:01.000Z",
|
||||
}),
|
||||
task({
|
||||
id: "c",
|
||||
title: "Todo newer",
|
||||
status: "todo",
|
||||
updated: "2026-01-01T00:00:03.000Z",
|
||||
}),
|
||||
task({
|
||||
id: "d",
|
||||
title: "In progress",
|
||||
status: "in-progress",
|
||||
updated: "2026-01-01T00:00:04.000Z",
|
||||
}),
|
||||
];
|
||||
|
||||
it("returns all status columns in fixed order, including empty", () => {
|
||||
const board = buildKanbanBoard(tasks);
|
||||
|
||||
expect(board.columns.map((col) => col.status)).toEqual([
|
||||
"todo",
|
||||
"in-progress",
|
||||
"done",
|
||||
"cancelled",
|
||||
]);
|
||||
expect(board.columns.map((col) => col.label)).toEqual([
|
||||
"To Do",
|
||||
"In Progress",
|
||||
"Done",
|
||||
"Cancelled",
|
||||
]);
|
||||
expect(board.columns[3].tasks).toEqual([]);
|
||||
});
|
||||
|
||||
it("places each task into the column matching its status", () => {
|
||||
const board = buildKanbanBoard(tasks);
|
||||
|
||||
expect(board.columns[0].tasks.map((t) => t.id)).toEqual(["c", "b"]);
|
||||
expect(board.columns[1].tasks.map((t) => t.id)).toEqual(["d"]);
|
||||
expect(board.columns[2].tasks.map((t) => t.id)).toEqual(["a"]);
|
||||
});
|
||||
|
||||
it("sorts tasks within a column by updated desc", () => {
|
||||
const board = buildKanbanBoard(tasks);
|
||||
const todo = board.columns.find((col) => col.status === "todo");
|
||||
expect(todo?.tasks.map((t) => t.id)).toEqual(["c", "b"]);
|
||||
});
|
||||
|
||||
it("returns empty columns when there are no tasks", () => {
|
||||
const board = buildKanbanBoard([]);
|
||||
|
||||
expect(board.columns).toHaveLength(4);
|
||||
for (const col of board.columns) {
|
||||
expect(col.tasks).toEqual([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user