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
vitest(link): add Vitest test cases for parseNavigationStateFromUrl
SiriusXT6a80bda335e2
diff --git a/apps/client/src/services/link.spec.ts b/apps/client/src/services/link.spec.tsindex 60812ccf90..09eaf09e75 100644--- a/apps/client/src/services/link.spec.ts+++ b/apps/client/src/services/link.spec.ts@@ -16,4 +16,24 @@ describe("Link", () => {const output = parseNavigationStateFromUrl(`#root/WWaBNf3SSA1b/mQ2tIzLVFKHL`);expect(output).toMatchObject({ notePath: "root/WWaBNf3SSA1b/mQ2tIzLVFKHL", noteId: "mQ2tIzLVFKHL" });});++ it("parses notePath with spaces", () => {+ const output = parseNavigationStateFromUrl(` #root/WWaBNf3SSA1b/mQ2tIzLVFKHL`);+ expect(output).toMatchObject({ notePath: "root/WWaBNf3SSA1b/mQ2tIzLVFKHL", noteId: "mQ2tIzLVFKHL" });+ });++ it("ignores external URL with internal hash anchor", () => {+ const output = parseNavigationStateFromUrl(`https://en.wikipedia.org/wiki/Bearded_Collie#Health`);+ expect(output).toMatchObject({});+ });++ it("ignores malformed but hash-containing external URL", () => {+ const output = parseNavigationStateFromUrl("https://abc.com/#drop?searchString=firefox");+ expect(output).toStrictEqual({});+ });++ it("ignores non-hash internal path", () => {+ const output = parseNavigationStateFromUrl("/root/abc123");+ expect(output).toStrictEqual({});+ });});