Files
SnapOtter/tests/e2e/restore-photo.spec.ts
T
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

141 lines
5.2 KiB
TypeScript

import path from "node:path";
import { expect, isAiSidecarRunning, test } from "./helpers";
function fixturePath(name: string): string {
return path.join(process.cwd(), "tests", "fixtures", name);
}
async function uploadFile(page: import("@playwright/test").Page, filePath: string) {
const fileChooserPromise = page.waitForEvent("filechooser");
const dropzone = page.locator("[class*='border-dashed']").first();
await dropzone.click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(filePath);
await page.waitForTimeout(500);
}
async function restoreAndWait(page: import("@playwright/test").Page) {
await page.getByTestId("restore-photo-submit").click();
await expect(page.getByTestId("restore-photo-download")).toBeVisible({ timeout: 300_000 });
}
test.describe("Restore Photo tool", () => {
async function skipIfFeatureNotInstalled(page: import("@playwright/test").Page) {
await page.goto("/image/restore-photo");
try {
await page.getByTestId("restore-photo-submit").waitFor({ state: "visible", timeout: 15_000 });
} catch {
test.skip(true, "photo-restoration feature bundle not installed");
}
if (!(await isAiSidecarRunning(page))) {
test.skip(true, "AI sidecar not running");
}
}
test("page loads with correct UI controls", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
// Mode buttons should NOT be present
await expect(page.getByRole("button", { name: "Light" })).not.toBeVisible();
await expect(page.getByRole("button", { name: "Auto" })).not.toBeVisible();
await expect(page.getByRole("button", { name: "Heavy" })).not.toBeVisible();
// Feature checkboxes
await expect(page.getByText("Scratch Removal")).toBeVisible();
await expect(page.getByText("Face Enhancement")).toBeVisible();
await expect(page.getByText("Noise Reduction")).toBeVisible();
await expect(page.getByText("Auto-Colorize")).toBeVisible();
// Submit button disabled with no file
await expect(page.getByTestId("restore-photo-submit")).toBeDisabled();
});
test("submit button disabled without file", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await expect(page.getByTestId("restore-photo-submit")).toBeDisabled();
});
test("submit button enables after file upload", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadFile(page, fixturePath("test-portrait.jpg"));
await expect(page.getByTestId("restore-photo-submit")).toBeEnabled();
});
test("face fidelity slider visible only when face enhancement enabled", async ({
loggedInPage: page,
}) => {
await skipIfFeatureNotInstalled(page);
const fidelityLabel = page.getByText("Face Fidelity");
// Face enhancement is ON by default - fidelity visible
await expect(fidelityLabel).toBeVisible();
// Uncheck face enhancement - fidelity hidden
await page.getByText("Face Enhancement").click();
await expect(fidelityLabel).not.toBeVisible();
// Re-enable face enhancement - fidelity visible again
await page.getByText("Face Enhancement").click();
await expect(fidelityLabel).toBeVisible();
});
test("denoise strength slider visible only when noise reduction enabled", async ({
loggedInPage: page,
}) => {
await skipIfFeatureNotInstalled(page);
const denoiseLabel = page.getByText("Denoise Strength");
// Noise reduction is ON by default - strength visible
await expect(denoiseLabel).toBeVisible();
// Uncheck noise reduction - strength hidden
await page.getByText("Noise Reduction").click();
await expect(denoiseLabel).not.toBeVisible();
// Re-enable noise reduction - strength visible again
await page.getByText("Noise Reduction").click();
await expect(denoiseLabel).toBeVisible();
});
test("colorize strength slider visible only when auto-colorize enabled", async ({
loggedInPage: page,
}) => {
await skipIfFeatureNotInstalled(page);
const strengthLabel = page.getByText("Colorize Strength");
// Auto-colorize is OFF by default - strength hidden
await expect(strengthLabel).not.toBeVisible();
// Enable auto-colorize - strength visible
await page.getByText("Auto-Colorize").click();
await expect(strengthLabel).toBeVisible();
// Disable auto-colorize - strength hidden again
await page.getByText("Auto-Colorize").click();
await expect(strengthLabel).not.toBeVisible();
});
test("JPG - restores and shows download", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadFile(page, fixturePath("test-portrait.jpg"));
await restoreAndWait(page);
await expect(page.locator("section[aria-label='Image area'] img").first()).toBeVisible();
await expect(page.getByText("Restoration failed")).not.toBeVisible();
});
test("HEIC input processes without error", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadFile(page, fixturePath("test-200x150.heic"));
await restoreAndWait(page);
await expect(page.locator("section[aria-label='Image area'] img").first()).toBeVisible();
await expect(page.getByText("Restoration failed")).not.toBeVisible();
});
});