mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-20 05:31:34 +08:00
test(calendar): start date & end date
This commit is contained in:
parent
d83b2a6a38
commit
5731cb9b4d
@ -1,16 +1,55 @@
|
|||||||
import { describe, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { buildNotes } from "../../test/easy-froca.js";
|
import { buildNotes } from "../../test/easy-froca.js";
|
||||||
|
import CalendarView from "./calendar_view.js";
|
||||||
|
|
||||||
describe("Building events", () => {
|
describe("Building events", () => {
|
||||||
it("supports start date", async () => {
|
it("supports start date", async () => {
|
||||||
const noteIds = buildNotes([
|
const noteIds = buildNotes([
|
||||||
{ title: "A", "#startDate": "2025-05-05" },
|
{ title: "Note 1", "#startDate": "2025-05-05" },
|
||||||
{ title: "A", "#startDate": "2025-05-07" },
|
{ title: "Note 2", "#startDate": "2025-05-07" },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const CalendarView = (await import("./calendar_view.js")).default;
|
|
||||||
const events = await CalendarView.buildEvents(noteIds);
|
const events = await CalendarView.buildEvents(noteIds);
|
||||||
console.log(noteIds, events);
|
|
||||||
|
expect(events).toHaveLength(2);
|
||||||
|
expect(events[0]).toMatchObject({
|
||||||
|
title: "Note 1",
|
||||||
|
start: "2025-05-05",
|
||||||
|
end: "2025-05-06"
|
||||||
|
});
|
||||||
|
expect(events[1]).toMatchObject({
|
||||||
|
title: "Note 2",
|
||||||
|
start: "2025-05-07",
|
||||||
|
end: "2025-05-08"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("ignores notes with only end date", async () => {
|
||||||
|
const noteIds = buildNotes([
|
||||||
|
{ title: "Note 1", "#endDate": "2025-05-05" },
|
||||||
|
{ title: "Note 2", "#endDateDate": "2025-05-07" },
|
||||||
|
]);
|
||||||
|
const events = await CalendarView.buildEvents(noteIds);
|
||||||
|
|
||||||
|
expect(events).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports both start date and end date", async () => {
|
||||||
|
const noteIds = buildNotes([
|
||||||
|
{ title: "Note 1", "#startDate": "2025-05-05", "#endDate": "2025-05-05" },
|
||||||
|
{ title: "Note 2", "#startDate": "2025-05-07", "#endDate": "2025-05-08" },
|
||||||
|
]);
|
||||||
|
const events = await CalendarView.buildEvents(noteIds);
|
||||||
|
|
||||||
|
expect(events).toHaveLength(2);
|
||||||
|
expect(events[0]).toMatchObject({
|
||||||
|
title: "Note 1",
|
||||||
|
start: "2025-05-05",
|
||||||
|
end: "2025-05-06"
|
||||||
|
});
|
||||||
|
expect(events[1]).toMatchObject({
|
||||||
|
title: "Note 2",
|
||||||
|
start: "2025-05-07",
|
||||||
|
end: "2025-05-09"
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user