import { describe, expect, it } from "vitest"; import { formatEventLine, formatIctDayLabel, formatIctTime, renderToday, renderWeek, } from "../../../src/modules/lolschedule/format.js"; /** @typedef {import("../../../src/modules/lolschedule/api-client.js").ScheduleEvent} ScheduleEvent */ function evt(overrides = {}) { return /** @type {ScheduleEvent} */ ({ startTime: "2026-04-21T09:00:00Z", state: "unstarted", blockName: "Week 4", league: { name: "LCK", slug: "lck" }, match: { id: "m1", teams: [ { name: "T1", code: "T1" }, { name: "Gen.G", code: "GEN" }, ], strategy: { type: "bestOf", count: 3 }, }, ...overrides, }); } const completed = evt({ startTime: "2026-04-20T08:00:00Z", state: "completed", blockName: "Week 3", match: { id: "m2", teams: [ { name: "T1", code: "T1", result: { outcome: "win", gameWins: 2 } }, { name: "Gen.G", code: "GEN", result: { outcome: "loss", gameWins: 1 } }, ], strategy: { type: "bestOf", count: 3 }, }, }); const live = evt({ startTime: "2026-04-21T08:00:00Z", state: "inProgress", match: { id: "m3", teams: [ { name: "Hanwha Life", code: "HLE", result: { gameWins: 1 } }, { name: "DRX", code: "DRX", result: { gameWins: 0 } }, ], strategy: { type: "bestOf", count: 3 }, }, }); describe("formatIctTime / formatIctDayLabel", () => { it("formats UTC datetime in ICT", () => { expect(formatIctTime(new Date("2026-04-21T09:00:00Z"))).toBe("16:00"); expect(formatIctDayLabel(new Date("2026-04-21T00:00:00Z"))).toBe("Tue Apr 21"); }); }); describe("formatEventLine", () => { it("omits league name — renders under a league header", () => { expect(formatEventLine(evt())).not.toContain("LCK"); }); it("renders completed with bolded winner + score", () => { const line = formatEventLine(completed); expect(line.startsWith("✅")).toBe(true); expect(line).toContain("T1"); expect(line).toContain("2–1"); expect(line).toContain("GEN"); expect(line).toContain("Bo3"); expect(line).toContain("Week 3"); }); it("renders live with LIVE prefix + current score", () => { const line = formatEventLine(live); expect(line.startsWith("🔴 LIVE")).toBe(true); expect(line).toContain("1–0"); }); it("renders unstarted with ICT time + vs", () => { const line = formatEventLine(evt()); expect(line.startsWith("🕒 16:00")).toBe(true); expect(line).toContain("T1 vs GEN"); }); it("escapes HTML in block and team labels", () => { const line = formatEventLine( evt({ blockName: "