/** * Unit tests for section parser. */ import { describe, it, expect } from "vitest"; import { splitIntoSections, extractWikilinks } from "../../mapping/sectionParser"; describe("splitIntoSections", () => { it("should split note with multiple headings", () => { const markdown = `# Heading 1 Content with [[Link1]] and [[Link2]]. ## Heading 2 More content with [[Link3]]. ### Heading 3 Even more content. `; const sections = splitIntoSections(markdown); expect(sections).toHaveLength(4); expect(sections[0]?.heading).toBeNull(); expect(sections[0]?.headingLevel).toBe(0); expect(sections[1]?.heading).toBe("Heading 1"); expect(sections[1]?.headingLevel).toBe(1); expect(sections[2]?.heading).toBe("Heading 2"); expect(sections[2]?.headingLevel).toBe(2); expect(sections[3]?.heading).toBe("Heading 3"); expect(sections[3]?.headingLevel).toBe(3); }); it("should extract links per section", () => { const markdown = `# Section 1 Content with [[Link1]] and [[Link2]]. ## Section 2 More content with [[Link3]]. `; const sections = splitIntoSections(markdown); expect(sections[1]?.links).toContain("Link1"); expect(sections[1]?.links).toContain("Link2"); expect(sections[2]?.links).toContain("Link3"); expect(sections[2]?.links).not.toContain("Link1"); }); it("should handle note without headings", () => { const markdown = `Content with [[Link1]] and [[Link2]].`; const sections = splitIntoSections(markdown); expect(sections).toHaveLength(1); expect(sections[0]?.heading).toBeNull(); expect(sections[0]?.links).toContain("Link1"); expect(sections[0]?.links).toContain("Link2"); }); }); describe("extractWikilinks", () => { it("should extract and deduplicate wikilinks", () => { const markdown = `Content with [[Link1]], [[Link2]], and [[Link1]] again.`; const links = extractWikilinks(markdown); expect(links).toHaveLength(2); expect(links).toContain("Link1"); expect(links).toContain("Link2"); }); it("should handle empty content", () => { const links = extractWikilinks(""); expect(links).toHaveLength(0); }); });