import path from "path"; import AxeBuilder from "@axe-core/playwright"; import { test, expect, loginAs, seed } from "./fixtures"; // 3.7.0 (docs/WEBSITE-1.0-PLAN.md §9 and §13): with the church's Accounts connected, the public // pages use the church's fonts and corners from its profile and the shared church footer, as the // Website and Accounts' own pages do. The dashboard stays as it is. Accounts runs in memory // (e2e/support/accounts-server.mts); afterwards the link is removed, so the other specs see the // site as before. /* eslint-disable @typescript-eslint/no-require-imports -- the backend's own modules, as prepare-db.js uses them */ const backend = path.join(__dirname, "..", "backend"); require(require.resolve("dotenv", { paths: [backend] })).config({ path: path.join(backend, ".env") }); const { Client } = require(require.resolve("pg", { paths: [backend] })); const { e2eDatabaseUrl } = require("./support/db-url"); const signing = require(require.resolve("@crosscode/contracts/signing", { paths: [backend] })); const { encrypt } = require(path.join(backend, "src", "utils", "encryption")); /* eslint-enable @typescript-eslint/no-require-imports */ const ACCOUNTS_API = "http://127.0.0.1:5221"; const ACCOUNTS_ID = "7e2d1c0b-9a8f-4e6d-8c5b-4a3f2e1d0c9b"; const TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"]; async function sql(text: string, values: unknown[] = []) { const client = new Client({ connectionString: e2eDatabaseUrl() }); await client.connect(); try { return (await client.query(text, values)).rows; } finally { await client.end(); } } test.describe.serial("the church's brand style and footer", () => { test.beforeAll(async () => { const profile = await fetch(`${ACCOUNTS_API}/test/profile`, { method: "POST", body: JSON.stringify({ name: "E2E Church", branding: { style: { fontPairing: "warm", corners: "round" } }, serviceTimes: [{ day: "sunday", time: "09:00", label: "Morning service", campus: null, note: null }], contact: { email: "office@e2e.test", phone: "+27161234567", whatsapp: null, address: { line1: "1 Church Street", line2: null, suburb: null, city: "Vereeniging", postalCode: "1939" } }, }), }); expect(profile.ok, await profile.text()).toBe(true); // Linked to Accounts, as Connect would (the backend reads the profile from this address). await sql(`DELETE FROM "ProductLink" WHERE product = 'accounts'`); await sql( `INSERT INTO "ProductLink" ("installId", product, url, "publicKey", secret, "connectedAt", "createdAt", "updatedAt") VALUES ($1, 'accounts', $2, 'x', $3, now(), now(), now())`, [ACCOUNTS_ID, ACCOUNTS_API, encrypt(signing.newLinkSecret())], ); }); test.afterAll(async () => { await sql(`DELETE FROM "ProductLink" WHERE product = 'accounts'`); }); test("public pages: the church's fonts, round corners and the shared footer, all from this site", async ({ page }) => { const elsewhere: string[] = []; page.on("request", (r) => { if (r.resourceType() === "font" && !r.url().startsWith("http://localhost:3100/")) elsewhere.push(r.url()); }); // The site keeps the profile for a minute; reload until it's there. await expect(async () => { await page.goto("/events"); await expect(page.locator("html")).toHaveAttribute("data-cc-fonts", "warm", { timeout: 1000 }); }).toPass({ timeout: 90_000 }); await expect(page.locator("html")).toHaveAttribute("data-cc-corners", "round"); await expect(page.getByText("E2E Free Evening")).toBeVisible(); const fonts = await page.evaluate(async () => { await document.fonts.ready; const h1 = document.querySelector("h1"); return { body: getComputedStyle(document.body).fontFamily, heading: h1 ? getComputedStyle(h1).fontFamily : "", radius: getComputedStyle(document.documentElement).getPropertyValue("--radius").trim(), loaded: [...document.fonts].filter((f) => f.status === "loaded").map((f) => f.family.replace(/"/g, "")), }; }); expect(fonts.body).toContain("CC Nunito Sans"); expect(fonts.heading).toContain("CC Fraunces"); expect(fonts.radius).toBe("0.75rem"); expect(fonts.loaded).toContain("CC Nunito Sans"); const footer = page.locator("footer"); await expect(footer.getByRole("heading", { name: "Service times" })).toBeVisible(); await expect(footer).toContainText("Sundays 09:00"); await expect(footer).toContainText("1 Church Street"); await expect(footer.getByRole("link", { name: "+27161234567" })).toHaveAttribute("href", "tel:+27161234567"); await expect(footer.getByRole("link", { name: "Your account" })).toHaveAttribute("href", /127\.0\.0\.1/); await expect(footer.getByRole("link", { name: "Privacy notice" })).toHaveAttribute("href", "/legal/privacy"); await expect(footer.getByRole("link", { name: "Terms of Use" })).toBeVisible(); await expect(footer.getByRole("button", { name: /cookie/i })).toBeVisible(); await page.goto(`/events/${seed().events.course}`); await expect(page.getByRole("heading", { name: "E2E Alpha Course" })).toBeVisible(); await expect(page.locator("footer").getByRole("heading", { name: "Service times" })).toBeVisible(); await page.waitForLoadState("networkidle"); const results = await new AxeBuilder({ page }).withTags(TAGS).analyze(); expect(results.violations.map((v) => `${v.id}: ${v.nodes.map((n) => n.target.join(" ")).join(", ")}`)).toEqual([]); expect(elsewhere).toEqual([]); }); test("the dashboard keeps its own fonts, corners and footer", async ({ page }) => { await loginAs(page, "admin"); await page.goto("/dashboard"); await expect(page.locator("[data-cc-staff]").first()).toBeVisible(); await expect(page.locator("main")).toBeVisible(); const look = await page.evaluate(() => ({ body: getComputedStyle(document.body).fontFamily, radius: getComputedStyle(document.documentElement).getPropertyValue("--radius").trim(), })); expect(look.body).not.toContain("CC "); expect(look.radius).toBe("0.5rem"); await expect(page.locator("footer")).toContainText("All rights reserved"); }); });