test: update tests, add eslint rules
This commit is contained in:
+30
-12
@@ -1,6 +1,8 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { parseTaskFile, serializeTask } from "./markdown";
|
||||
import { Task } from "@/model/task";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseTaskFile, serializeTask } from "./markdown";
|
||||
|
||||
const ISO_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
|
||||
|
||||
const fullTask: Task = {
|
||||
id: "550e8400-e29b-41d4-a716-446655440000",
|
||||
@@ -51,20 +53,17 @@ describe("markdown", () => {
|
||||
expect(task.priority).toBe("medium");
|
||||
expect(task.tags).toEqual([]);
|
||||
expect(task.assignee).toBe("");
|
||||
expect(task.created).toBeTruthy();
|
||||
expect(task.updated).toBeTruthy();
|
||||
});
|
||||
|
||||
it("serializeTask produces valid frontmatter", () => {
|
||||
const result = serializeTask(fullTask);
|
||||
expect(result).toContain("---");
|
||||
expect(result).toContain("title: Пофиксить баг логина");
|
||||
expect(result).toContain("status: in-progress");
|
||||
expect(result).toContain("Ошибка валидации токена");
|
||||
expect(task.created).toMatch(ISO_RE);
|
||||
expect(task.updated).toMatch(ISO_RE);
|
||||
});
|
||||
|
||||
it("round-trip: serialize → parse produces the same task", () => {
|
||||
const serialized = serializeTask(fullTask);
|
||||
expect(serialized).toContain("---");
|
||||
expect(serialized).toContain("title: Пофиксить баг логина");
|
||||
expect(serialized).toContain("status: in-progress");
|
||||
expect(serialized).toContain("Ошибка валидации токена");
|
||||
|
||||
const parsed = parseTaskFile(serialized);
|
||||
expect(parsed).toEqual(fullTask);
|
||||
});
|
||||
@@ -78,4 +77,23 @@ describe("markdown", () => {
|
||||
const parsed = parseTaskFile(serialized);
|
||||
expect(parsed.description).toBe(task.description);
|
||||
});
|
||||
|
||||
it("converts Date values from YAML to ISO strings", () => {
|
||||
const created = new Date("2026-07-12T10:00:00.000Z");
|
||||
const updated = new Date("2026-07-12T11:00:00.000Z");
|
||||
const content = [
|
||||
"---",
|
||||
'id: "date-task"',
|
||||
'title: "With dates"',
|
||||
`created: ${created.toISOString()}`,
|
||||
`updated: ${updated.toISOString()}`,
|
||||
"---",
|
||||
"",
|
||||
].join("\n");
|
||||
|
||||
// front-matter/js-yaml may return Date for unquoted ISO-like timestamps
|
||||
const task = parseTaskFile(content);
|
||||
expect(task.created).toBe("2026-07-12T10:00:00.000Z");
|
||||
expect(task.updated).toBe("2026-07-12T11:00:00.000Z");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user