fix(test): tests that got broken along the way

This commit is contained in:
Elian Doran 2025-03-15 17:51:10 +02:00
parent bc8cca664b
commit 2b966afbe1
No known key found for this signature in database
7 changed files with 30 additions and 46 deletions

View File

@ -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" ]
])
});
});

View File

@ -272,7 +272,7 @@ describe("data_dir.ts unit tests", async () => {
});
describe("#getDataDirs()", () => {
const envKeys: Omit<keyof ReturnType<typeof getDataDirs>, "TRILIUM_DATA_DIR">[] = ["DOCUMENT_PATH", "BACKUP_DIR", "LOG_DIR", "ANONYMIZED_DB_DIR", "CONFIG_INI_PATH"];
const envKeys: Omit<keyof ReturnType<typeof getDataDirs>, "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) => {

View File

@ -40,12 +40,7 @@ describe("markdown", () => {
# another one
Hello, world
`, "title");
expect(result).toBe(trimIndentation`\
<h2>Hello</h2>
<h2>world</h2>
<h2>another one</h2>
<p>Hello, world</p>
`);
expect(result).toBe(`<h2>Hello</h2><h2>world</h2><h2>another one</h2><p>Hello, world</p>`);
});
@ -54,7 +49,7 @@ describe("markdown", () => {
# What's new
Hi there
`, "What's new")
expect(result).toBe(`\n<p>Hi there</p>\n`);
expect(result).toBe(`<p>Hi there</p>`);
});
it("trims unnecessary whitespace", () => {

View File

@ -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("<h2>Hello world</h2>\n<p>Plain text goes here.</p>\n");
expect(importedNote.getContent().toString()).toBe("<h2>Hello world</h2><p>Plain text goes here.</p>");
});
it("supports excalidraw note", async () => {

View File

@ -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);

View File

@ -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);
});

View File

@ -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);