Files
SnapOtter/tests/e2e/upscale.spec.ts
T
ashim-hq f67a03bb36 fix: resolve all audit findings — e2e coverage, feature system hardening, visual baselines
- Add 8 new E2E specs for AI tools (upscale, enhance-faces, colorize,
  restore-photo, erase-object, smart-crop, passport-photo, red-eye-removal)
  closing all HIGH/MEDIUM coverage gaps from the test matrix audit
- Fix ensureAiDirs() crash on non-Docker environments by gating on
  isDockerEnvironment() — prevents ENOENT when /data doesn't exist
- Bump torch 2.6.0→2.7.0 and torchvision 0.21.0→0.22.0 in feature
  manifest for broader Python version compatibility
- Add Python 3.14 version guard warning in install_feature.py
- Remove duplicate torchvision shims from upscale.py and enhance_faces.py
  (dispatcher.py already handles this at startup)
- Remove orphaned tools.batch i18n key and dead pipeline-builder filter
- Regenerate 4 visual regression baselines for current UI state
- Add data-testid to passport-photo generate button for E2E testability
2026-04-20 18:47:59 +08:00

154 lines
5.5 KiB
TypeScript

import path from "node:path";
import { expect, 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 upscaleAndWait(page: import("@playwright/test").Page) {
await page.getByTestId("upscale-submit").click();
await expect(page.getByTestId("upscale-download")).toBeVisible({ timeout: 300_000 });
}
test.describe("Upscale tool", () => {
async function skipIfFeatureNotInstalled(page: import("@playwright/test").Page) {
await page.goto("/upscale");
try {
await page.getByTestId("upscale-submit").waitFor({ state: "visible", timeout: 15_000 });
} catch {
test.skip(true, "upscale-enhance feature bundle not installed");
}
}
test("page loads with correct UI controls", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
// Scale factor buttons
await expect(page.getByRole("button", { name: "2x" })).toBeVisible();
await expect(page.getByRole("button", { name: "4x" })).toBeVisible();
await expect(page.getByRole("button", { name: "8x" })).toBeVisible();
// Quality tier buttons
await expect(page.getByRole("button", { name: "Fast" })).toBeVisible();
await expect(page.getByRole("button", { name: "Balanced" })).toBeVisible();
await expect(page.getByRole("button", { name: "Best" })).toBeVisible();
// Output format dropdown
await expect(page.locator("#upscale-format")).toBeVisible();
// Submit button disabled with no file
await expect(page.getByTestId("upscale-submit")).toBeDisabled();
});
test("submit button disabled without file", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await expect(page.getByTestId("upscale-submit")).toBeDisabled();
});
test("submit button enables after file upload", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadFile(page, fixturePath("test-200x150.png"));
await expect(page.getByTestId("upscale-submit")).toBeEnabled();
});
test("scale factor buttons are interactive", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
const btn4x = page.getByRole("button", { name: "4x" });
await btn4x.click();
await expect(btn4x).toHaveClass(/bg-primary/);
const btn8x = page.getByRole("button", { name: "8x" });
await btn8x.click();
await expect(btn8x).toHaveClass(/bg-primary/);
});
test("quality tier buttons are interactive", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
const fast = page.getByRole("button", { name: "Fast" });
const balanced = page.getByRole("button", { name: "Balanced" });
const best = page.getByRole("button", { name: "Best" });
await fast.click();
await expect(fast).toHaveClass(/bg-primary/);
await balanced.click();
await expect(balanced).toHaveClass(/bg-primary/);
await best.click();
await expect(best).toHaveClass(/bg-primary/);
});
test("face enhance checkbox visibility depends on quality tier", async ({
loggedInPage: page,
}) => {
await skipIfFeatureNotInstalled(page);
const faceCheckbox = page.getByText("Enhance faces");
// Balanced (default) - visible
await expect(faceCheckbox).toBeVisible();
// Fast (lanczos) - hidden
await page.getByRole("button", { name: "Fast" }).click();
await expect(faceCheckbox).not.toBeVisible();
// Best (realesrgan) - visible
await page.getByRole("button", { name: "Best" }).click();
await expect(faceCheckbox).toBeVisible();
});
test("quality slider shows only for lossy output formats", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
const formatSelect = page.locator("#upscale-format");
// PNG (default) - no quality slider
await expect(page.getByText("Quality").nth(1)).not.toBeVisible();
// JPG - quality slider visible
await formatSelect.selectOption("jpg");
await expect(page.locator("input[type='range'][min='1'][max='100']")).toBeVisible();
// WEBP - quality slider visible
await formatSelect.selectOption("webp");
await expect(page.locator("input[type='range'][min='1'][max='100']")).toBeVisible();
// PNG - quality slider hidden
await formatSelect.selectOption("png");
await expect(page.locator("input[type='range'][min='1'][max='100']")).not.toBeVisible();
});
test("JPG portrait - balanced tier upscales and shows download", async ({
loggedInPage: page,
}) => {
await skipIfFeatureNotInstalled(page);
await uploadFile(page, fixturePath("test-portrait.jpg"));
await upscaleAndWait(page);
await expect(page.locator("section[aria-label='Image area'] img").first()).toBeVisible();
await expect(page.getByText("Upscale failed")).not.toBeVisible();
});
test("HEIC input processes without error", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadFile(page, fixturePath("test-200x150.heic"));
await upscaleAndWait(page);
await expect(page.locator("section[aria-label='Image area'] img").first()).toBeVisible();
await expect(page.getByText("Upscale failed")).not.toBeVisible();
});
});