Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(client): cover the corners the split and calendar work left
Elian Doran8cc40f147ec4
diff --git a/apps/client/src/components/tab_manager.spec.ts b/apps/client/src/components/tab_manager.spec.tsindex 441c7f74cf..5c499f415b 100644--- a/apps/client/src/components/tab_manager.spec.ts+++ b/apps/client/src/components/tab_manager.spec.ts@@ -1,5 +1,6 @@-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";+import appContext from "./app_context.js";import TabManager, { buildNoteContextStatesFromUrl } from "./tab_manager.js";describe("TabManager tab placement", () => {@@ -96,6 +97,47 @@ describe("moving a tab with splits into a window of its own", () => {});});+describe("handing a tab over to a window of its own", () => {+ it("moves the tab, having described it before the close takes its panes down", async () => {+ const tm = new TabManager();+ // closing a pane asks the app which manager owns it, which only booting normally answers+ appContext.tabManager = tm;+ const [main, other] = await openEmptyTabs(tm, 2);+ const split = await tm.openEmptyTab(null, "root", main.ntxId);+ main.notePath = "root/aaaaaaaaaaaa";+ split.notePath = "root/bbbbbbbbbbbb";+ const triggerCommand = vi.spyOn(tm, "triggerCommand").mockReturnValue(undefined);++ await tm.moveTabToNewWindowCommand({ ntxId: main.ntxId ?? "" });++ expect(triggerCommand).toHaveBeenCalledWith("openInWindow", expect.objectContaining({+ notePath: "root/aaaaaaaaaaaa",+ splits: [ expect.objectContaining({ notePath: "root/bbbbbbbbbbbb" }) ]+ }));+ // the tab left with its split, leaving the neighbouring tab behind+ expect(ntxOrder(tm)).toEqual([other.ntxId]);+ });++ it("copies the tab without closing it, and asks for nothing once the tab is gone", async () => {+ const tm = new TabManager();+ const [main] = await openEmptyTabs(tm, 2);+ main.notePath = "root/aaaaaaaaaaaa";+ const triggerCommand = vi.spyOn(tm, "triggerCommand").mockReturnValue(undefined);++ await tm.copyTabToNewWindowCommand({ ntxId: main.ntxId ?? "" });++ expect(triggerCommand).toHaveBeenCalledWith("openInWindow", expect.objectContaining({+ notePath: "root/aaaaaaaaaaaa"+ }));+ expect(tm.noteContexts).toContain(main);++ // the tear-off drag fires repeatedly, so a call for an already-removed tab is expected+ triggerCommand.mockClear();+ await tm.copyTabToNewWindowCommand({ ntxId: "gone" });+ expect(triggerCommand).not.toHaveBeenCalled();+ });+});+describe("buildNoteContextStatesFromUrl", () => {it("rebuilds the panes as one tab, with the focused one active", () => {const states = buildNoteContextStatesFromUrl({diff --git a/apps/client/src/services/link.spec.ts b/apps/client/src/services/link.spec.tsindex fa4dd8d364..5621188160 100644--- a/apps/client/src/services/link.spec.ts+++ b/apps/client/src/services/link.spec.ts@@ -299,6 +299,16 @@ describe("split panes in the hash", () => {});});+ it("shrugs off an active index that is not a number, and a parameter carrying no value", () => {+ // Both reach the parser straight off the address bar, where anything at all may be typed.+ expect(parseNavigationStateFromUrl(+ asExtraWindowUrl(`#${A}?splits=${encodeURIComponent(B)}&activeSplit=whichever`)+ )).toMatchObject({ activeSplit: 0, splits: [{ notePath: B }] });++ // `popup` is a flag, so it is written bare — there is no `=` to split on.+ expect(parseNavigationStateFromUrl(`#${A}?popup`)).toMatchObject({ openInPopup: true });+ });+it("ignores parameters that describe a window rather than a pane", () => {const nested = encodeURIComponent(`${B}?ntxId=n1&splits=${encodeURIComponent(C)}`);const parsed = parseNavigationStateFromUrl(asExtraWindowUrl(`#${A}?splits=${nested}`));diff --git a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts b/apps/client/src/widgets/collections/calendar/event_builder.spec.tsindex 6d8cfed4f6..da3f81fe95 100644--- a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts+++ b/apps/client/src/widgets/collections/calendar/event_builder.spec.ts@@ -168,6 +168,20 @@ describe("Promoted attributes", () => {]);});+ it("says nothing for a relation whose target has no title, rather than the word for nothing", async () => {+ const note = buildNote({+ "title": "Hello",+ "~assignee": buildNote({ "title": "" }).noteId,+ "#calendar:displayedAttributes": "assignee",+ "#relation:assignee": "promoted,alias=Assignee,single,text"+ });++ const event = await buildEvent(note, { startDate: "2025-04-04" });+ expect(event[0]?.promotedAttributes).toMatchObject([+ [ "Assignee", "" ]+ ]);+ });+it("says an attribute nobody defined by its own name, promotion being no condition of showing one", async () => {const note = buildNote({title: "Hello",@@ -340,6 +354,24 @@ describe("Recurrence", () => {expect(events[1].duration).toEqual({ days: 3, hours: 0, minutes: 0 });});+ it("gives no length to an occurrence whose event says only when it starts", async () => {+ const noteIds = buildNotes([+ {+ title: "Recurring Open-Ended",+ "#startDate": "2025-05-05",+ "#startTime": "13:00",+ "#recurrence": "FREQ=DAILY;COUNT=5"+ }+ ]);+ const events = await buildEvents(noteIds);++ expect(events).toHaveLength(1);+ // Nothing said about how long it runs, so nothing is invented: FullCalendar gives the+ // occurrence its default length rather than one worked out from an end that isn't there.+ expect(events[0].duration).toBeUndefined();+ expect(events[0].rrule).toContain("DTSTART:20250505T130000");+ });+it("writes to console on invalid recurrence rule", async () => {const noteIds = buildNotes([{diff --git a/apps/client/src/widgets/collections/calendar/index.spec.ts b/apps/client/src/widgets/collections/calendar/index.spec.tsindex 60303faa20..81ca7355f0 100644--- a/apps/client/src/widgets/collections/calendar/index.spec.ts+++ b/apps/client/src/widgets/collections/calendar/index.spec.ts@@ -1,7 +1,7 @@import { EventDisplayInfo } from "fullcalendar";import { describe, expect, it } from "vitest";-import { roomForAttributes } from "./index.js";+import { eventInnerClass, roomForAttributes } from "./index.js";/** As much of a chip as the question is asked of: which view it is drawn in, and how it sits there. */function chip({ view, allDay = false, isShort = false, isNarrow = false }: {@@ -34,3 +34,25 @@ describe("roomForAttributes", () => {expect(roomForAttributes(chip({ view: "listMonth" }))).toBe(null);});});++describe("eventInnerClass", () => {+ /** A chip as the class is asked of it: where it is drawn, and whether it has anything to say. */+ function chipWithAttributes(view: string, promotedAttributes?: [string, string][]) {+ return {+ ...chip({ view }),+ event: { allDay: false, extendedProps: { promotedAttributes } }+ } as unknown as EventDisplayInfo;+ }++ it("makes a row that wraps of a chip whose attributes must fall beneath it", () => {+ expect(eventInnerClass(chipWithAttributes("dayGridMonth", [[ "mood", "happy" ]])))+ .toBe("calendar-event-inner-wrapped");+ });++ it("leaves the inner alone where the attributes stack, or where there are none to place", () => {+ // A timed chip on a time grid is a column already, so its attributes need no line of their own.+ expect(eventInnerClass(chipWithAttributes("timeGridWeek", [[ "mood", "happy" ]]))).toBe("");+ expect(eventInnerClass(chipWithAttributes("dayGridMonth", []))).toBe("");+ expect(eventInnerClass(chipWithAttributes("dayGridMonth"))).toBe("");+ });+});diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsxindex 121f4f8519..2f995d2512 100644--- a/apps/client/src/widgets/collections/calendar/index.tsx+++ b/apps/client/src/widgets/collections/calendar/index.tsx@@ -778,7 +778,7 @@ export function roomForAttributes(e: EventDisplayInfo): "stacked" | "wrapped" |* index.css). Said as a class on the inner rather than drawn in eventContent because wrapping is* the container's to declare and the container is the theme's, not ours.*/-function eventInnerClass(e: EventDisplayInfo) {+export function eventInnerClass(e: EventDisplayInfo) {const { promotedAttributes } = e.event.extendedProps;return clsx(!!promotedAttributes?.length && roomForAttributes(e) === "wrapped"&& "calendar-event-inner-wrapped");