|
| 1 | +import AxeBuilder from "@axe-core/playwright"; |
| 2 | +import { expect, test } from "@playwright/test"; |
| 3 | + |
| 4 | +const SEVERE_IMPACTS = ["serious", "critical"]; |
| 5 | + |
| 6 | +test.describe("cron builder", () => { |
| 7 | + test("route loads with a valid default expression and description", async ({ |
| 8 | + page, |
| 9 | + }) => { |
| 10 | + await page.goto("/tools/cron-builder"); |
| 11 | + |
| 12 | + await expect(page.locator("h1")).toHaveText("Cron Builder"); |
| 13 | + await expect(page.locator("#cron-raw-input")).toHaveValue("0 9 * * 1-5"); |
| 14 | + await expect( |
| 15 | + page.getByText("At 09:00, Monday through Friday."), |
| 16 | + ).toBeVisible(); |
| 17 | + await expect(page.locator("#cron-raw-error")).toHaveCount(0); |
| 18 | + }); |
| 19 | + |
| 20 | + test("upcoming runs render for the default schedule", async ({ page }) => { |
| 21 | + await page.goto("/tools/cron-builder"); |
| 22 | + |
| 23 | + await expect( |
| 24 | + page.getByRole("heading", { name: "Next runs" }), |
| 25 | + ).toBeVisible(); |
| 26 | + // 5 upcoming runs, each formatted like "Mon, Aug 17 · 09:00". |
| 27 | + await expect(page.locator("ol li")).toHaveCount(5); |
| 28 | + await expect(page.getByText(/Previewed in/)).toBeVisible(); |
| 29 | + }); |
| 30 | + |
| 31 | + test("selecting a preset updates the expression and description", async ({ |
| 32 | + page, |
| 33 | + }) => { |
| 34 | + await page.goto("/tools/cron-builder"); |
| 35 | + |
| 36 | + await page.getByRole("button", { name: "Every 5 minutes" }).click(); |
| 37 | + |
| 38 | + await expect(page.locator("#cron-raw-input")).toHaveValue("*/5 * * * *"); |
| 39 | + await expect(page.getByText("Every 5 minutes.")).toBeVisible(); |
| 40 | + }); |
| 41 | + |
| 42 | + test("editing the raw expression updates the description", async ({ |
| 43 | + page, |
| 44 | + }) => { |
| 45 | + await page.goto("/tools/cron-builder"); |
| 46 | + |
| 47 | + await page.fill("#cron-raw-input", "0 0 1 * *"); |
| 48 | + |
| 49 | + await expect( |
| 50 | + page.getByText("At 00:00 on the first day of every month."), |
| 51 | + ).toBeVisible(); |
| 52 | + }); |
| 53 | + |
| 54 | + test("an invalid raw expression is rejected without destroying the visual editor", async ({ |
| 55 | + page, |
| 56 | + }) => { |
| 57 | + await page.goto("/tools/cron-builder"); |
| 58 | + |
| 59 | + await page.fill("#cron-raw-input", "60 * * * *"); |
| 60 | + |
| 61 | + await expect(page.locator("#cron-raw-error")).toHaveText( |
| 62 | + "Minute must be between 0 and 59.", |
| 63 | + ); |
| 64 | + // The last valid state (hour 9 selected) must still be reflected. |
| 65 | + await expect(page.getByRole("button", { name: "Hour 9" })).toHaveAttribute( |
| 66 | + "aria-pressed", |
| 67 | + "true", |
| 68 | + ); |
| 69 | + }); |
| 70 | + |
| 71 | + test("copying the expression exposes a success state", async ({ page }) => { |
| 72 | + // Headless Chromium's real clipboard permissions are unreliable in CI, |
| 73 | + // so stub the Clipboard API and assert on what was actually written. |
| 74 | + await page.addInitScript(() => { |
| 75 | + (window as unknown as { __copied: string[] }).__copied = []; |
| 76 | + Object.defineProperty(navigator, "clipboard", { |
| 77 | + configurable: true, |
| 78 | + value: { |
| 79 | + writeText: (text: string) => { |
| 80 | + (window as unknown as { __copied: string[] }).__copied.push(text); |
| 81 | + return Promise.resolve(); |
| 82 | + }, |
| 83 | + }, |
| 84 | + }); |
| 85 | + }); |
| 86 | + await page.goto("/tools/cron-builder"); |
| 87 | + |
| 88 | + await page.getByRole("button", { name: "Copy cron expression" }).click(); |
| 89 | + |
| 90 | + await expect( |
| 91 | + page.getByRole("button", { name: "Cron expression copied" }), |
| 92 | + ).toBeVisible(); |
| 93 | + const copied = await page.evaluate( |
| 94 | + () => (window as unknown as { __copied: string[] }).__copied, |
| 95 | + ); |
| 96 | + expect(copied).toEqual(["0 9 * * 1-5"]); |
| 97 | + }); |
| 98 | + |
| 99 | + test("mobile viewport has no horizontal overflow", async ({ page }) => { |
| 100 | + await page.setViewportSize({ width: 375, height: 812 }); |
| 101 | + await page.goto("/tools/cron-builder"); |
| 102 | + |
| 103 | + const hasOverflow = await page.evaluate( |
| 104 | + () => |
| 105 | + document.documentElement.scrollWidth > |
| 106 | + document.documentElement.clientWidth + 1, |
| 107 | + ); |
| 108 | + expect(hasOverflow).toBe(false); |
| 109 | + }); |
| 110 | + |
| 111 | + test("has no serious/critical axe violations", async ({ page }) => { |
| 112 | + await page.goto("/tools/cron-builder"); |
| 113 | + const results = await new AxeBuilder({ page }).analyze(); |
| 114 | + const severe = results.violations.filter((v) => |
| 115 | + SEVERE_IMPACTS.includes(v.impact ?? ""), |
| 116 | + ); |
| 117 | + |
| 118 | + expect( |
| 119 | + severe, |
| 120 | + severe |
| 121 | + .map((v) => `${v.id}: ${v.description} (${v.nodes.length} node(s))`) |
| 122 | + .join("\n"), |
| 123 | + ).toEqual([]); |
| 124 | + }); |
| 125 | +}); |
0 commit comments