diff --git a/src/integration.test.ts b/src/integration.test.ts new file mode 100644 index 0000000..65a5478 --- /dev/null +++ b/src/integration.test.ts @@ -0,0 +1,120 @@ +import { describe, it, expect } from "vitest"; +import { SELF } from "cloudflare:test"; + +const FIXED_WEEK = "2026-W45"; + +describe("VCR Calendar integration", () => { + it("GET / redirects to /week", async () => { + const res = await SELF.fetch("https://vcr.test/", { redirect: "manual" }); + expect(res.status).toBe(302); + expect(res.headers.get("Location")).toBe("/week"); + }); + + it("GET /week returns valid HTML with required shell elements", async () => { + const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}`); + expect(res.status).toBe(200); + expect(res.headers.get("Content-Type")).toContain("text/html"); + const html = await res.text(); + expect(html).toContain(""); + expect(html).toMatch(/data-theme="/); + expect(html).toContain("week-grid"); + expect(html).toContain("agenda"); + expect(html).toContain("controls-bar"); + expect(html).toContain("Bowl After Bowl"); + expect(html).toContain("📻 VCR Calendar"); + }); + + it("GET /week?mode=all shows all active shows including non-VCR", async () => { + const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&mode=all`); + const html = await res.text(); + expect(html).toContain("Bowl After Bowl"); + expect(html).toContain("Chad and Reeds"); + expect(html).toContain("Hyper SpaceOut"); + expect(html).toContain("vcr-badge"); + }); + + it("GET /week?mode=vcr shows only VCR shows (BAB yes, HSO no)", async () => { + const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&mode=vcr`); + const html = await res.text(); + expect(html).toContain("Bowl After Bowl"); + expect(html).not.toContain("Hyper SpaceOut"); + expect(html).not.toContain("Chad and Reeds"); + }); + + it("GET /week?tz=pacific shows Pacific in controls and converts times", async () => { + const easternRes = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&tz=eastern&mode=vcr`); + const easternHtml = await easternRes.text(); + const pacificRes = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&tz=pacific&mode=vcr`); + const pacificHtml = await pacificRes.text(); + expect(pacificHtml).toContain('aria-current="true"'); + expect(pacificHtml).toContain("Pacific"); + expect(pacificHtml).toContain("Times shown in Pacific"); + expect(easternHtml).toContain("10:00 PM"); + expect(pacificHtml).toMatch(/Bowl After Bowl[\s\S]{0,400}7:00 PM/); + }); + + it("GET /week?tz=pacific sets a tz cookie", async () => { + const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&tz=pacific`); + const cookies = res.headers.getAll("Set-Cookie"); + expect(cookies.some((c) => c.includes("tz=pacific"))).toBe(true); + }); + + it("GET /week?theme=dark sets data-theme to dark", async () => { + const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&theme=dark`); + const html = await res.text(); + expect(html).toContain('data-theme="dark"'); + const cookies = res.headers.getAll("Set-Cookie"); + expect(cookies.some((c) => c.includes("theme=dark"))).toBe(true); + }); + + it("GET /week?reset=1 clears preference cookies", async () => { + const res = await SELF.fetch(`https://vcr.test/week?reset=1`); + const cookies = res.headers.getAll("Set-Cookie"); + expect(cookies.some((c) => c.includes("Max-Age=0"))).toBe(true); + }); + + it("GET /show/bowl-after-bowl returns show detail with schedule and hosts", async () => { + const res = await SELF.fetch("https://vcr.test/show/bowl-after-bowl"); + expect(res.status).toBe(200); + expect(res.headers.get("Content-Type")).toContain("text/html"); + const html = await res.text(); + expect(html).toContain("Bowl After Bowl"); + expect(html).toContain("Spencer"); + expect(html).toContain("DuhLaurien"); + expect(html).toContain("bowlafterbowl.com"); + expect(html).toContain("Back to calendar"); + expect(html).toContain("show-detail"); + }); + + it("GET /show/nonexistent returns 404 with styled page", async () => { + const res = await SELF.fetch("https://vcr.test/show/nonexistent"); + expect(res.status).toBe(404); + expect(res.headers.get("Content-Type")).toContain("text/html"); + const html = await res.text(); + expect(html).toContain("404"); + expect(html).toContain("not-found"); + }); + + it("returns no script tags on week or show pages", async () => { + const weekRes = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}`); + expect(await weekRes.text()).not.toContain(" { + const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&mode=all`); + const html = await res.text(); + expect(html).toContain("bi-weekly"); + }); + + it("GET /week?tz=amsterdam shows Amsterdam timezone as active", async () => { + const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&tz=amsterdam`); + const html = await res.text(); + expect(html).toContain('aria-current="true"'); + expect(html).toContain("Amsterdam"); + expect(html).toContain("Times shown in Amsterdam"); + }); +});