import { describe, expect, it } from "vitest"; import { draftFromForm, postFields } from "../src/posts.ts"; const form = (pairs: [string, string][]) => new URLSearchParams(pairs); describe("post form", () => { const d = draftFromForm( form([ ["title", " Pouring galaxy dice "], ["date", "2026-10-12"], ["topic", "Making"], ["postType", "article"], ["summary", "How the set came together."], ["cover", "[[galaxy.jpg]]"], ["links", "Resin"], ["links", "[[Galaxy dice]]"], ["links", ""], ["role", "Ignored for articles"], ["body", "Line one\r\nLine two"], ]), ); it("reads the form into a draft", () => { expect(d).toMatchObject({ title: "Pouring galaxy dice", cover: "galaxy.jpg", links: ["Resin", "Galaxy dice"], body: "Line one\nLine two" }); }); it("writes note fields, with links and the cover as wikilinks", () => { expect(postFields(d, true, false)).toEqual({ title: "Pouring galaxy dice", date: "2026-10-12", topic: "Making", postType: "article", summary: "How the set came together.", publish: true, cover: "[[galaxy.jpg]]", links: ["[[Resin]]", "[[Galaxy dice]]"], }); }); it("clears emptied fields on an update", () => { const f = postFields({ ...d, cover: "", links: [] }, false, true); expect(f).toMatchObject({ cover: null, links: null, pinned: null, role: null, publish: false }); }); });