import { describe, expect, it } from "vitest"; import { parseImportFile } from "./parsers"; describe("parseNetscapeBookmarkFile", () => { it("parses a simple bookmark file with single bookmark", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0]).toMatchObject({ title: "Example Site", content: { type: "link", url: "https://example.com", }, tags: [], addDate: 1234567890, paths: [[]], }); }); it("parses bookmarks with tags", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0].tags).toEqual(["tag1", "tag2", "tag3"]); }); it("parses bookmarks in nested folders", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0]).toMatchObject({ title: "Nested Bookmark", content: { type: "link", url: "https://example.com", }, paths: [["Folder1", "Folder2"]], }); }); it("handles empty folder names by replacing with 'Unnamed'", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0].paths).toEqual([["Named Folder", "Unnamed"]]); }); it("parses multiple bookmarks in different folders", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(3); expect(result[0]).toMatchObject({ title: "GitHub", content: { type: "link", url: "https://github.com" }, paths: [["Tech"]], }); expect(result[1]).toMatchObject({ title: "Stack Overflow", content: { type: "link", url: "https://stackoverflow.com" }, paths: [["Tech"]], }); expect(result[2]).toMatchObject({ title: "Hacker News", content: { type: "link", url: "https://news.ycombinator.com" }, paths: [["News"]], }); }); it("parses bookmarks at root level (no folders)", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(2); expect(result[0].paths).toEqual([[]]); expect(result[1].paths).toEqual([[]]); }); it("handles deeply nested folder structures", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0].paths).toEqual([["Level1", "Level2", "Level3", "Level4"]]); }); it("deduplicates bookmarks with the same URL", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0]).toMatchObject({ content: { type: "link", url: "https://example.com" }, tags: ["tag1", "tag2"], addDate: 1234567890, // Should keep the earlier date }); expect(result[0].paths).toHaveLength(2); expect(result[0].paths).toContainEqual(["Folder1"]); expect(result[0].paths).toContainEqual(["Folder2"]); }); it("merges notes from duplicate bookmarks", () => { const html = `
`; // Note: The current parser doesn't extract DD notes, but this test // documents the expected behavior if/when DD parsing is added const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0].content).toMatchObject({ type: "link", url: "https://example.com", }); }); it("handles bookmarks without ADD_DATE attribute", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0].addDate).toBeUndefined(); }); it("handles bookmarks without HREF attribute", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(1); expect(result[0].content).toBeUndefined(); }); it("handles mixed structure with folders and root-level bookmarks", () => { const html = `
`; const result = parseImportFile("html", html); expect(result).toHaveLength(3); expect(result[0]).toMatchObject({ title: "Root Bookmark 1", paths: [[]], }); expect(result[1]).toMatchObject({ title: "Folder Bookmark", paths: [["Folder"]], }); expect(result[2]).toMatchObject({ title: "Root Bookmark 2", paths: [[]], }); }); it("throws error for non-Netscape bookmark files", () => { const html = `