mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
fix(test): tests that got broken along the way
This commit is contained in:
parent
bc8cca664b
commit
2b966afbe1
@ -39,8 +39,8 @@ describe("Building events", () => {
|
|||||||
|
|
||||||
it("supports custom start date", async () => {
|
it("supports custom start date", async () => {
|
||||||
const noteIds = buildNotes([
|
const noteIds = buildNotes([
|
||||||
{ title: "Note 1", "#myStartDate": "2025-05-05", "#calendar:startDate": "#myStartDate" },
|
{ title: "Note 1", "#myStartDate": "2025-05-05", "#calendar:startDate": "myStartDate" },
|
||||||
{ title: "Note 2", "#startDate": "2025-05-07", "#calendar:startDate": "#myStartDate" },
|
{ title: "Note 2", "#startDate": "2025-05-07", "#calendar:startDate": "myStartDate" },
|
||||||
]);
|
]);
|
||||||
const events = await CalendarView.buildEvents(noteIds);
|
const events = await CalendarView.buildEvents(noteIds);
|
||||||
|
|
||||||
@ -59,10 +59,10 @@ describe("Building events", () => {
|
|||||||
|
|
||||||
it("supports custom start date and end date", async () => {
|
it("supports custom start date and end date", async () => {
|
||||||
const noteIds = buildNotes([
|
const noteIds = buildNotes([
|
||||||
{ title: "Note 1", "#myStartDate": "2025-05-05", "#myEndDate": "2025-05-05", "#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 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 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 4", "#startDate": "2025-05-07", "#myEndDate": "2025-05-08", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" },
|
||||||
]);
|
]);
|
||||||
const events = await CalendarView.buildEvents(noteIds);
|
const events = await CalendarView.buildEvents(noteIds);
|
||||||
|
|
||||||
@ -75,8 +75,8 @@ describe("Building events", () => {
|
|||||||
|
|
||||||
it("supports label as custom title", async () => {
|
it("supports label as custom title", async () => {
|
||||||
const noteIds = buildNotes([
|
const noteIds = buildNotes([
|
||||||
{ title: "Note 1", "#myTitle": "My Custom Title 1", "#startDate": "2025-05-05", "#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" },
|
{ title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "myTitle" },
|
||||||
]);
|
]);
|
||||||
const events = await CalendarView.buildEvents(noteIds);
|
const events = await CalendarView.buildEvents(noteIds);
|
||||||
|
|
||||||
@ -88,8 +88,8 @@ describe("Building events", () => {
|
|||||||
it("supports relation as custom title", async () => {
|
it("supports relation as custom title", async () => {
|
||||||
const noteIds = buildNotes([
|
const noteIds = buildNotes([
|
||||||
{ id: "mySharedTitle", title: "My shared title" },
|
{ id: "mySharedTitle", title: "My shared title" },
|
||||||
{ title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#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" },
|
{ title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "myTitle" },
|
||||||
]);
|
]);
|
||||||
const events = await CalendarView.buildEvents(noteIds);
|
const events = await CalendarView.buildEvents(noteIds);
|
||||||
|
|
||||||
@ -100,23 +100,9 @@ describe("Building events", () => {
|
|||||||
|
|
||||||
it("supports relation as custom title with custom label", async () => {
|
it("supports relation as custom title with custom label", async () => {
|
||||||
const noteIds = buildNotes([
|
const noteIds = buildNotes([
|
||||||
{ id: "mySharedTitle", title: "My custom title", "#myTitle": "My shared custom title", "#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 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "myTitle" },
|
||||||
{ title: "Note 2", "#startDate": "2025-05-07", "#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" },
|
|
||||||
]);
|
]);
|
||||||
const events = await CalendarView.buildEvents(noteIds);
|
const events = await CalendarView.buildEvents(noteIds);
|
||||||
|
|
||||||
@ -135,15 +121,15 @@ describe("Promoted attributes", () => {
|
|||||||
"#mood": "happy",
|
"#mood": "happy",
|
||||||
"#label:weight": "promoted,number,single,precision=1",
|
"#label:weight": "promoted,number,single,precision=1",
|
||||||
"#label:mood": "promoted,alias=Mood,single,text",
|
"#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");
|
const event = await CalendarView.buildEvent(note, "2025-04-04");
|
||||||
expect(event).toHaveLength(1);
|
expect(event).toHaveLength(1);
|
||||||
expect(event[0]?.promotedAttributes).toMatchObject({
|
expect(event[0]?.promotedAttributes).toMatchObject([
|
||||||
weight: "75",
|
[ "weight", "75" ],
|
||||||
Mood: "happy"
|
[ "mood", "happy" ]
|
||||||
})
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("supports relations", async () => {
|
it("supports relations", async () => {
|
||||||
@ -152,14 +138,14 @@ describe("Promoted attributes", () => {
|
|||||||
"~assignee": buildNote({
|
"~assignee": buildNote({
|
||||||
"title": "Target note"
|
"title": "Target note"
|
||||||
}).noteId,
|
}).noteId,
|
||||||
"#calendar:promotedAttributes": "relation:assignee",
|
"#calendar:displayedAttributes": "assignee",
|
||||||
"#relation:assignee": "promoted,alias=Assignee,single,text",
|
"#relation:assignee": "promoted,alias=Assignee,single,text",
|
||||||
});
|
});
|
||||||
|
|
||||||
const event = await CalendarView.buildEvent(note, "2025-04-04");
|
const event = await CalendarView.buildEvent(note, "2025-04-04");
|
||||||
expect(event).toHaveLength(1);
|
expect(event).toHaveLength(1);
|
||||||
expect(event[0]?.promotedAttributes).toMatchObject({
|
expect(event[0]?.promotedAttributes).toMatchObject([
|
||||||
"Assignee": "Target note"
|
[ "assignee", "Target note" ]
|
||||||
})
|
])
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -272,7 +272,7 @@ describe("data_dir.ts unit tests", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("#getDataDirs()", () => {
|
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) => {
|
const setMockedEnv = (prefix: string | null) => {
|
||||||
envKeys.forEach((key) => {
|
envKeys.forEach((key) => {
|
||||||
|
@ -40,12 +40,7 @@ describe("markdown", () => {
|
|||||||
# another one
|
# another one
|
||||||
Hello, world
|
Hello, world
|
||||||
`, "title");
|
`, "title");
|
||||||
expect(result).toBe(trimIndentation`\
|
expect(result).toBe(`<h2>Hello</h2><h2>world</h2><h2>another one</h2><p>Hello, world</p>`);
|
||||||
<h2>Hello</h2>
|
|
||||||
<h2>world</h2>
|
|
||||||
<h2>another one</h2>
|
|
||||||
<p>Hello, world</p>
|
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +49,7 @@ describe("markdown", () => {
|
|||||||
# What's new
|
# What's new
|
||||||
Hi there
|
Hi there
|
||||||
`, "What's new")
|
`, "What's new")
|
||||||
expect(result).toBe(`\n<p>Hi there</p>\n`);
|
expect(result).toBe(`<p>Hi there</p>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("trims unnecessary whitespace", () => {
|
it("trims unnecessary whitespace", () => {
|
||||||
|
@ -87,7 +87,7 @@ describe("processNoteContent", () => {
|
|||||||
it("supports markdown note with UTF-16", async () => {
|
it("supports markdown note with UTF-16", async () => {
|
||||||
const { importedNote } = await testImport("UTF-16LE Text Note.md", "text/markdown");
|
const { importedNote } = await testImport("UTF-16LE Text Note.md", "text/markdown");
|
||||||
expect(importedNote.mime).toBe("text/html");
|
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 () => {
|
it("supports excalidraw note", async () => {
|
||||||
|
@ -13,9 +13,9 @@ export function getHelpHiddenSubtreeData() {
|
|||||||
const appDir = path.join(srcRoot, "public", isDev ? "app" : "app-dist");
|
const appDir = path.join(srcRoot, "public", isDev ? "app" : "app-dist");
|
||||||
const helpDir = path.join(appDir, "doc_notes", "en", "User Guide");
|
const helpDir = path.join(appDir, "doc_notes", "en", "User Guide");
|
||||||
const metaFilePath = path.join(helpDir, "!!!meta.json");
|
const metaFilePath = path.join(helpDir, "!!!meta.json");
|
||||||
const metaFileContent = JSON.parse(fs.readFileSync(metaFilePath).toString("utf-8"));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const metaFileContent = JSON.parse(fs.readFileSync(metaFilePath).toString("utf-8"));
|
||||||
return parseNoteMetaFile(metaFileContent as NoteMetaFile);
|
return parseNoteMetaFile(metaFileContent as NoteMetaFile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
|
@ -27,6 +27,7 @@ describe("Share API test", () => {
|
|||||||
it("requests password for password-protected share", async () => {
|
it("requests password for password-protected share", async () => {
|
||||||
await supertest(app)
|
await supertest(app)
|
||||||
.get("/share/YjlPRj2E9fOV")
|
.get("/share/YjlPRj2E9fOV")
|
||||||
|
.expect(200)
|
||||||
.expect("WWW-Authenticate", 'Basic realm="User Visible Realm", charset="UTF-8"');
|
.expect("WWW-Authenticate", 'Basic realm="User Visible Realm", charset="UTF-8"');
|
||||||
expect(cannotSetHeadersCount).toBe(0);
|
expect(cannotSetHeadersCount).toBe(0);
|
||||||
});
|
});
|
||||||
|
@ -131,6 +131,7 @@ function renderImageAttachment(image: SNote, res: Response, attachmentName: stri
|
|||||||
function register(router: Router) {
|
function register(router: Router) {
|
||||||
function renderNote(note: SNote, req: Request, res: Response) {
|
function renderNote(note: SNote, req: Request, res: Response) {
|
||||||
if (!note) {
|
if (!note) {
|
||||||
|
console.log("Unable to find note ", note);
|
||||||
res.status(404).render("share/404");
|
res.status(404).render("share/404");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -215,6 +216,7 @@ function register(router: Router) {
|
|||||||
|
|
||||||
const { shareId } = req.params;
|
const { shareId } = req.params;
|
||||||
|
|
||||||
|
console.log("Got share ", shareId, shaca.notes, shaca.aliasToNote);
|
||||||
const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];
|
const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];
|
||||||
|
|
||||||
renderNote(note, req, res);
|
renderNote(note, req, res);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user