Files
SnapOtter/tests/e2e/html-to-image.spec.ts
SnapOtterandGitHub 0f98f60c33 test(e2e): modernize stale routes for 2.0 section URLs (#347)
The e2e specs predate the 2.0 section-route migration and navigated to
single-segment tool URLs (/resize) that now 404 (App.tsx only mounts
/:section/:toolId). This broke the whole e2e suite (Cross-Browser, Device
Matrix, E2E Full, Visual) - part of the known stale-spec backlog.

- Sweep 929 goto("/<tool>") -> goto("/<section>/<tool>") across 45 spec
  files, using the authoritative TOOLS + toolSection() mapping. Two-segment
  routes, top-level routes (/automate, /editor, ...), and intentional 404
  tests (/nonexistent-*) are untouched.
- Implement the legacy redirects the specs already assert: the 1.x color
  tools (brightness-contrast, saturation, color-channels, color-effects)
  redirect to /image/adjust-colors (App.tsx). Good for old bookmarks too.
- Remove the analytics-consent page tests (gui-navigation + gui-visual);
  #336 deleted that page.

Mechanical + biome-clean + web typecheck passes. Browser-specific behavior
can only be confirmed by the nightly e2e jobs.
2026-06-24 20:19:37 +08:00

56 lines
2.1 KiB
TypeScript

import { expect, test } from "@playwright/test";
test.describe("HTML to Image", () => {
test("navigates to the tool page", async ({ page }) => {
await page.goto("/image/html-to-image");
await expect(page.locator("input[type='url']")).toBeVisible();
});
test("shows capture button disabled when URL is empty", async ({ page }) => {
await page.goto("/image/html-to-image");
const button = page.locator("button[type='submit']");
await expect(button).toBeDisabled();
});
test("enables capture button when URL is entered", async ({ page }) => {
await page.goto("/image/html-to-image");
await page.locator("input[type='url']").fill("https://snapotter.com");
const button = page.locator("button[type='submit']");
await expect(button).toBeEnabled();
});
test("captures a webpage and shows the result", async ({ page }) => {
await page.goto("/image/html-to-image");
await page.locator("input[type='url']").fill("https://snapotter.com");
await page.locator("button[type='submit']").click();
const resultImg = page.locator("img[alt='Captured screenshot']");
await expect(resultImg).toBeVisible({ timeout: 45_000 });
});
test("shows download button after capture", async ({ page }) => {
await page.goto("/image/html-to-image");
await page.locator("input[type='url']").fill("https://snapotter.com");
await page.locator("button[type='submit']").click();
const downloadBtn = page.getByRole("button", { name: /download/i });
await expect(downloadBtn).toBeVisible({ timeout: 45_000 });
});
test("device preset selector works", async ({ page }) => {
await page.goto("/image/html-to-image");
const preset = page.locator("select").nth(1);
await preset.selectOption("mobile");
await expect(preset).toHaveValue("mobile");
});
test("shows viewport fields when custom preset selected", async ({ page }) => {
await page.goto("/image/html-to-image");
const preset = page.locator("select").nth(1);
await preset.selectOption("custom");
const widthInput = page.locator("input[type='number']").first();
await expect(widthInput).toBeVisible();
});
});