dotwee_obsidian-raindropio-.../tests/note-parser.test.ts
Lukas Wolfsteiner 877b75ddc5 feat: add testing framework and initial test cases
- Introduce Jest as the testing framework and configure it for the project.
- Add initial test cases for block and note parsing functionalities.
- Update ESLint configuration to include test files and adjust global settings.
- Modify package.json to include test scripts and dependencies for Jest.
- Enhance GitHub workflows to run tests during linting and release processes.
2026-05-02 01:33:06 +02:00

41 lines
1.3 KiB
TypeScript

import type { CachedMetadata } from "obsidian";
import { getNoteRaindropReferences, getUrlKey } from "note-parser";
describe("getNoteRaindropReferences", () => {
it("extracts unique tags and urls from a note", () => {
const metadata: CachedMetadata = {
tags: [{ tag: "#research", position: { start: { line: 0, col: 0, offset: 0 }, end: { line: 0, col: 9, offset: 9 } } }],
frontmatter: {
tags: ["saved", "#research"],
},
};
const source = [
"[Obsidian](https://obsidian.md/)",
"https://raindrop.io/library,",
"https://obsidian.md/",
].join("\n");
expect(getNoteRaindropReferences(source, metadata)).toEqual({
tags: ["research", "saved"],
urls: ["https://obsidian.md/", "https://raindrop.io/library"],
});
});
it("handles notes without metadata", () => {
expect(getNoteRaindropReferences("No links here", null)).toEqual({
tags: [],
urls: [],
});
});
});
describe("getUrlKey", () => {
it("normalizes equivalent urls for comparison", () => {
expect(getUrlKey("https://Example.com/path/#section")).toBe("https://example.com/path");
expect(getUrlKey("https://example.com/path/")).toBe("https://example.com/path");
});
it("falls back to lower-cased text for invalid urls", () => {
expect(getUrlKey("Example/Path/")).toBe("example/path");
});
});