import { describe, expect, it } from "vitest"; import { withSynced, type Note } from "../src/lib/content.ts"; import { gamePlayers, gamePlayTime, type Game } from "../src/lib/library.ts"; import { deckArt, deckColors } from "../src/lib/world.ts"; const note = (type: string, data: Record, synced?: Record) => ({ path: `${type}/x.md`, type, name: "x", slug: "x", title: "X", body: "", acceptedAt: "", data: { type, ...data }, synced }) as unknown as T; describe("synced values", () => { it("sit under the note's own values: the note always wins", () => { const n = withSynced(note("library-item", { cover: "[[mine.jpg]]", title: "X" }, { cover: "https://x/cover.jpg", year: 2006 })); expect(n.data).toMatchObject({ cover: "[[mine.jpg]]", year: 2006 }); const bare = withSynced(note("library-item", { title: "X" }, { cover: "https://x/cover.jpg" })); expect((bare.data as { cover?: string }).cover).toBe("https://x/cover.jpg"); }); it("leave a note with nothing synced exactly as it came", () => { const n = note("board-game", { bggId: 1, blurb: "b" }, {}); expect(withSynced(n)).toBe(n); const none = note("board-game", { bggId: 1, blurb: "b" }); expect(withSynced(none)).toBe(none); expect([gamePlayers(none), gamePlayTime(none)]).toEqual([undefined, undefined]); expect(deckArt(note("deck", { game: "[[Magic]]" }))).toBeUndefined(); expect(deckColors(note("deck", { game: "[[Magic]]" }))).toEqual([]); }); it("give the Shelf players and play time, and the decks art and colors", () => { const g = withSynced(note("board-game", { bggId: 1, blurb: "b" }, { minPlayers: 1, maxPlayers: 5, playTime: 70, minPlayTime: 40, maxPlayTime: 70 })); expect([gamePlayers(g), gamePlayTime(g)]).toEqual(["1–5 players", "40–70 min"]); const solo = withSynced(note("board-game", { bggId: 1, blurb: "b" }, { minPlayers: 1, maxPlayers: 1, playTime: 30 })); expect([gamePlayers(solo), gamePlayTime(solo)]).toEqual(["1 player", "30 min"]); const d = withSynced(note>("deck", { game: "[[Magic]]" }, { commanderArt: "https://cards.scryfall.io/a.jpg", colors: ["W", "U", "G"] })); expect(deckArt(d)).toBe("https://cards.scryfall.io/a.jpg"); expect(deckColors(d)).toEqual(["White", "Blue", "Green"]); const own = withSynced(note>("deck", { game: "[[Magic]]", cover: "[[deck.jpg]]" }, { commanderArt: "https://cards.scryfall.io/a.jpg" })); expect(deckArt(own)).toBe("/media/deck.jpg"); }); });