/** * Test helpers: create in-memory Y.Doc fixtures with frontmatter, authors, * citations for publisher pipeline tests. */ import * as Y from "yjs"; export interface DocFixtureOptions { title?: string; subtitle?: string; description?: string; published?: string; doi?: string; licence?: string; authors?: Array<{ name: string; url?: string; affiliations: number[] }>; affiliations?: Array<{ name: string; url?: string }>; citations?: Record; } /** * Create a Y.Doc with frontmatter, authors, affiliations, and citations. * Does NOT inject TipTap content - tests that need HTML should pass JSON * directly to renderArticleHTML, keeping tests decoupled from the transformer. */ export function createTestYDoc(options: DocFixtureOptions = {}): Y.Doc { const ydoc = new Y.Doc(); const frontmatter = ydoc.getMap("frontmatter"); if (options.title) frontmatter.set("title", options.title); if (options.subtitle) frontmatter.set("subtitle", options.subtitle); if (options.description) frontmatter.set("description", options.description); if (options.published) frontmatter.set("published", options.published); if (options.doi) frontmatter.set("doi", options.doi); if (options.licence) frontmatter.set("licence", options.licence); const yAuthors = ydoc.getArray("frontmatter.authors"); for (const author of options.authors ?? []) { yAuthors.push([author]); } const yAffiliations = ydoc.getArray("frontmatter.affiliations"); for (const aff of options.affiliations ?? []) { yAffiliations.push([aff]); } const citationsMap = ydoc.getMap("citations"); for (const [key, value] of Object.entries(options.citations ?? {})) { citationsMap.set(key, value); } return ydoc; } export const MINIMAL_DOC_JSON = { type: "doc", content: [ { type: "heading", attrs: { level: 2 }, content: [{ type: "text", text: "Introduction" }], }, { type: "paragraph", content: [{ type: "text", text: "Hello world." }], }, ], }; export const FULL_DOC_OPTIONS: DocFixtureOptions = { title: "Test Article Title", subtitle: "A subtitle for testing", description: "This is a test article description.", published: "2025-01-15", doi: "10.1234/test.2025", licence: "CC BY 4.0", authors: [ { name: "Alice Smith", url: "https://example.com/alice", affiliations: [1] }, { name: "Bob Jones", affiliations: [1, 2] }, ], affiliations: [ { name: "University of Testing", url: "https://utest.edu" }, { name: "Institute of Vitest" }, ], citations: { smith2024: { id: "smith2024", type: "article-journal", title: "On Testing", author: [{ family: "Smith", given: "Alice" }], issued: { "date-parts": [[2024]] }, }, }, };