From 2b966afbe1f0e4b1ac8ca913f7b46582549d138a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 15 Mar 2025 17:51:10 +0200 Subject: [PATCH] fix(test): tests that got broken along the way --- .../view_widgets/calendar_view.spec.ts | 58 +++++++------------ src/services/data_dir.spec.ts | 2 +- src/services/import/markdown.spec.ts | 9 +-- src/services/import/single.spec.ts | 2 +- src/services/in_app_help.ts | 2 +- src/share/routes.spec.ts | 1 + src/share/routes.ts | 2 + 7 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/public/app/widgets/view_widgets/calendar_view.spec.ts b/src/public/app/widgets/view_widgets/calendar_view.spec.ts index 9623f0172..286792325 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.spec.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.spec.ts @@ -39,8 +39,8 @@ describe("Building events", () => { it("supports custom start date", async () => { const noteIds = buildNotes([ - { title: "Note 1", "#myStartDate": "2025-05-05", "#calendar:startDate": "#myStartDate" }, - { title: "Note 2", "#startDate": "2025-05-07", "#calendar:startDate": "#myStartDate" }, + { title: "Note 1", "#myStartDate": "2025-05-05", "#calendar:startDate": "myStartDate" }, + { title: "Note 2", "#startDate": "2025-05-07", "#calendar:startDate": "myStartDate" }, ]); const events = await CalendarView.buildEvents(noteIds); @@ -59,10 +59,10 @@ describe("Building events", () => { it("supports custom start date and end date", async () => { const noteIds = buildNotes([ - { title: "Note 1", "#myStartDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" }, - { title: "Note 2", "#myStartDate": "2025-05-07", "#endDate": "2025-05-08", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" }, - { title: "Note 3", "#startDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" }, - { title: "Note 4", "#startDate": "2025-05-07", "#myEndDate": "2025-05-08", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" }, + { title: "Note 1", "#myStartDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" }, + { title: "Note 2", "#myStartDate": "2025-05-07", "#endDate": "2025-05-08", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" }, + { title: "Note 3", "#startDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" }, + { title: "Note 4", "#startDate": "2025-05-07", "#myEndDate": "2025-05-08", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" }, ]); const events = await CalendarView.buildEvents(noteIds); @@ -75,8 +75,8 @@ describe("Building events", () => { it("supports label as custom title", async () => { const noteIds = buildNotes([ - { title: "Note 1", "#myTitle": "My Custom Title 1", "#startDate": "2025-05-05", "#calendar:title": "#myTitle" }, - { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "#myTitle" }, + { title: "Note 1", "#myTitle": "My Custom Title 1", "#startDate": "2025-05-05", "#calendar:title": "myTitle" }, + { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "myTitle" }, ]); const events = await CalendarView.buildEvents(noteIds); @@ -88,8 +88,8 @@ describe("Building events", () => { it("supports relation as custom title", async () => { const noteIds = buildNotes([ { id: "mySharedTitle", title: "My shared title" }, - { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" }, - { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" }, + { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "myTitle" }, + { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "myTitle" }, ]); const events = await CalendarView.buildEvents(noteIds); @@ -100,23 +100,9 @@ describe("Building events", () => { it("supports relation as custom title with custom label", async () => { const noteIds = buildNotes([ - { id: "mySharedTitle", title: "My custom title", "#myTitle": "My shared custom title", "#calendar:title": "#myTitle" }, - { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" }, - { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" }, - ]); - const events = await CalendarView.buildEvents(noteIds); - - expect(events).toHaveLength(2); - expect(events[0]).toMatchObject({ title: "My shared custom title", start: "2025-05-05" }); - expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" }); - }); - - it("discards relation as custom title with custom relation", async () => { - const noteIds = buildNotes([ - { id: "myParentNote", title: "My parent note" }, - { id: "mySharedTitle", title: "My custom title", "~myTitle": "myParentNote", "#calendar:title": "~myTitle" }, - { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" }, - { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" }, + { id: "mySharedTitle", title: "My custom title", "#myTitle": "My shared custom title", "#calendar:title": "myTitle" }, + { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "myTitle" }, + { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "myTitle" }, ]); const events = await CalendarView.buildEvents(noteIds); @@ -135,15 +121,15 @@ describe("Promoted attributes", () => { "#mood": "happy", "#label:weight": "promoted,number,single,precision=1", "#label:mood": "promoted,alias=Mood,single,text", - "#calendar:promotedAttributes": "label:weight,label:mood" + "#calendar:displayedAttributes": "weight,mood" }); const event = await CalendarView.buildEvent(note, "2025-04-04"); expect(event).toHaveLength(1); - expect(event[0]?.promotedAttributes).toMatchObject({ - weight: "75", - Mood: "happy" - }) + expect(event[0]?.promotedAttributes).toMatchObject([ + [ "weight", "75" ], + [ "mood", "happy" ] + ]); }); it("supports relations", async () => { @@ -152,14 +138,14 @@ describe("Promoted attributes", () => { "~assignee": buildNote({ "title": "Target note" }).noteId, - "#calendar:promotedAttributes": "relation:assignee", + "#calendar:displayedAttributes": "assignee", "#relation:assignee": "promoted,alias=Assignee,single,text", }); const event = await CalendarView.buildEvent(note, "2025-04-04"); expect(event).toHaveLength(1); - expect(event[0]?.promotedAttributes).toMatchObject({ - "Assignee": "Target note" - }) + expect(event[0]?.promotedAttributes).toMatchObject([ + [ "assignee", "Target note" ] + ]) }); }); diff --git a/src/services/data_dir.spec.ts b/src/services/data_dir.spec.ts index 4c94cbe94..24315a5ff 100644 --- a/src/services/data_dir.spec.ts +++ b/src/services/data_dir.spec.ts @@ -272,7 +272,7 @@ describe("data_dir.ts unit tests", async () => { }); describe("#getDataDirs()", () => { - const envKeys: Omit, "TRILIUM_DATA_DIR">[] = ["DOCUMENT_PATH", "BACKUP_DIR", "LOG_DIR", "ANONYMIZED_DB_DIR", "CONFIG_INI_PATH"]; + const envKeys: Omit, "TRILIUM_DATA_DIR">[] = ["DOCUMENT_PATH", "BACKUP_DIR", "LOG_DIR", "ANONYMIZED_DB_DIR", "CONFIG_INI_PATH", "TMP_DIR"]; const setMockedEnv = (prefix: string | null) => { envKeys.forEach((key) => { diff --git a/src/services/import/markdown.spec.ts b/src/services/import/markdown.spec.ts index dc382b896..5d5ccd33c 100644 --- a/src/services/import/markdown.spec.ts +++ b/src/services/import/markdown.spec.ts @@ -40,12 +40,7 @@ describe("markdown", () => { # another one Hello, world `, "title"); - expect(result).toBe(trimIndentation`\ -

Hello

-

world

-

another one

-

Hello, world

- `); + expect(result).toBe(`

Hello

world

another one

Hello, world

`); }); @@ -54,7 +49,7 @@ describe("markdown", () => { # What's new Hi there `, "What's new") - expect(result).toBe(`\n

Hi there

\n`); + expect(result).toBe(`

Hi there

`); }); it("trims unnecessary whitespace", () => { diff --git a/src/services/import/single.spec.ts b/src/services/import/single.spec.ts index e04b657df..1eacd261b 100644 --- a/src/services/import/single.spec.ts +++ b/src/services/import/single.spec.ts @@ -87,7 +87,7 @@ describe("processNoteContent", () => { it("supports markdown note with UTF-16", async () => { const { importedNote } = await testImport("UTF-16LE Text Note.md", "text/markdown"); expect(importedNote.mime).toBe("text/html"); - expect(importedNote.getContent().toString()).toBe("

Hello world

\n

Plain text goes here.

\n"); + expect(importedNote.getContent().toString()).toBe("

Hello world

Plain text goes here.

"); }); it("supports excalidraw note", async () => { diff --git a/src/services/in_app_help.ts b/src/services/in_app_help.ts index b7fd30050..7841ee71b 100644 --- a/src/services/in_app_help.ts +++ b/src/services/in_app_help.ts @@ -13,9 +13,9 @@ export function getHelpHiddenSubtreeData() { const appDir = path.join(srcRoot, "public", isDev ? "app" : "app-dist"); const helpDir = path.join(appDir, "doc_notes", "en", "User Guide"); const metaFilePath = path.join(helpDir, "!!!meta.json"); - const metaFileContent = JSON.parse(fs.readFileSync(metaFilePath).toString("utf-8")); try { + const metaFileContent = JSON.parse(fs.readFileSync(metaFilePath).toString("utf-8")); return parseNoteMetaFile(metaFileContent as NoteMetaFile); } catch (e) { console.warn(e); diff --git a/src/share/routes.spec.ts b/src/share/routes.spec.ts index 86e1927bd..c78e447af 100644 --- a/src/share/routes.spec.ts +++ b/src/share/routes.spec.ts @@ -27,6 +27,7 @@ describe("Share API test", () => { it("requests password for password-protected share", async () => { await supertest(app) .get("/share/YjlPRj2E9fOV") + .expect(200) .expect("WWW-Authenticate", 'Basic realm="User Visible Realm", charset="UTF-8"'); expect(cannotSetHeadersCount).toBe(0); }); diff --git a/src/share/routes.ts b/src/share/routes.ts index 3c6db87d5..2591cce0c 100644 --- a/src/share/routes.ts +++ b/src/share/routes.ts @@ -131,6 +131,7 @@ function renderImageAttachment(image: SNote, res: Response, attachmentName: stri function register(router: Router) { function renderNote(note: SNote, req: Request, res: Response) { if (!note) { + console.log("Unable to find note ", note); res.status(404).render("share/404"); return; } @@ -215,6 +216,7 @@ function register(router: Router) { const { shareId } = req.params; + console.log("Got share ", shareId, shaca.notes, shaca.aliasToNote); const note = shaca.aliasToNote[shareId] || shaca.notes[shareId]; renderNote(note, req, res);