58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { TASK_FILE_EXTENSION } from "@/model/taskFile";
|
|
import { err } from "neverthrow";
|
|
import { InMemoryFileSystem } from "../../tests/helpers/InMemoryFileSystem";
|
|
import { appError, AppErrorVariant } from "@/error";
|
|
import { FsTaskRepository } from "@/storage/FsTaskRepository";
|
|
import { loadDashboard } from "./loadDashboard";
|
|
|
|
describe("loadDashboard", () => {
|
|
const folder = "/tasks";
|
|
let repo: FsTaskRepository;
|
|
|
|
beforeEach(() => {
|
|
repo = new FsTaskRepository(new InMemoryFileSystem(), TASK_FILE_EXTENSION);
|
|
});
|
|
|
|
it("loads all tasks for a folder", async () => {
|
|
const a = await repo.create(folder, {
|
|
title: "First",
|
|
description: "",
|
|
status: "todo",
|
|
priority: "medium",
|
|
tags: [],
|
|
assignee: "",
|
|
});
|
|
const b = await repo.create(folder, {
|
|
title: "Second",
|
|
description: "body",
|
|
status: "done",
|
|
priority: "high",
|
|
tags: ["x"],
|
|
assignee: "",
|
|
});
|
|
|
|
const result = await loadDashboard(repo, { folderPath: folder });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
if (result.isErr()) return;
|
|
|
|
expect(result.value.tasks).toHaveLength(2);
|
|
const ids = result.value.tasks.map((t) => t.id).sort();
|
|
expect(ids).toEqual([a.id, b.id].sort());
|
|
});
|
|
|
|
it("returns empty list when folder has no tasks", async () => {
|
|
const result = await loadDashboard(repo, { folderPath: folder });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
if (result.isErr()) return;
|
|
expect(result.value.tasks).toEqual([]);
|
|
});
|
|
|
|
it("rejects missing folder", async () => {
|
|
const result = await loadDashboard(repo, { folderPath: undefined });
|
|
expect(result).toEqual(err(appError(AppErrorVariant.NO_FOLDER)));
|
|
});
|
|
});
|