Files
SnapOtter/tests/e2e/smart-crop.spec.ts
T
ashim-hq 37277e5c09 fix: resolve ONNX CUDA fallback, Docker e2e infrastructure, and all test failures
- Add safe_onnx_session() to gpu.py with graceful CUDA EP → CPU fallback
- Replace bare ort.InferenceSession() calls across colorize, restore, inpaint, remove_bg
- Add libcublas-12-6 to production Dockerfile for ONNX Runtime CUDA EP
- Add skipIfFeatureNotInstalled guards to remove-bg, blur-faces, smart-crop, ocr, noise-removal e2e specs
- Add AI tool install prompt detection in tools-all.spec.ts
- Add smart-crop to PYTHON_SIDECAR_TOOLS so frontend shows install prompt correctly
- Create Dockerfile.test.dockerignore to include tests/ in test image builds
- Add libheif-examples and exiftool to Dockerfile.test for HEIC and metadata tests
- Regenerate visual regression baselines for Docker/Linux and skip on non-Docker platforms
2026-04-20 20:53:54 +08:00

131 lines
4.8 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);
}
test.describe("Smart Crop tool", () => {
async function skipIfFeatureNotInstalled(page: import("@playwright/test").Page) {
await page.goto("/smart-crop");
try {
await page.getByTestId("smart-crop-submit").waitFor({ state: "visible", timeout: 15_000 });
} catch {
test.skip(true, "face-detection feature bundle not installed");
}
}
test("page loads with correct UI controls", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
// Mode tabs
await expect(page.getByRole("button", { name: "Subject Focus" })).toBeVisible();
await expect(page.getByRole("button", { name: "Face Focus" })).toBeVisible();
await expect(page.getByRole("button", { name: "Auto Trim" })).toBeVisible();
// Submit button disabled with no file
await expect(page.getByTestId("smart-crop-submit")).toBeDisabled();
});
test("submit button disabled without file", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await expect(page.getByTestId("smart-crop-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("smart-crop-submit")).toBeEnabled();
});
test("subject mode shows strategy and padding controls", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
// Subject Focus is default
await expect(page.getByText("Detection Strategy")).toBeVisible();
await expect(page.getByRole("button", { name: "Attention" })).toBeVisible();
await expect(page.getByRole("button", { name: "Entropy" })).toBeVisible();
await expect(page.getByText("Padding")).toBeVisible();
await expect(page.getByText("Width (px)")).toBeVisible();
await expect(page.getByText("Height (px)")).toBeVisible();
});
test("face mode shows framing and sensitivity controls", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await page.getByRole("button", { name: "Face Focus" }).click();
await expect(page.getByText("Framing")).toBeVisible();
await expect(page.getByText("Detection Sensitivity")).toBeVisible();
await expect(page.getByText("Face Padding")).toBeVisible();
});
test("trim mode shows tolerance controls", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await page.getByRole("button", { name: "Auto Trim" }).click();
await expect(page.getByText("Tolerance")).toBeVisible();
await expect(page.getByText("Pad to square")).toBeVisible();
});
test("aspect ratio presets update dimensions", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
// Click 16:9 preset
await page.getByRole("button", { name: "16:9" }).click();
const widthInput = page.locator("#sc-width");
const heightInput = page.locator("#sc-height");
await expect(widthInput).toHaveValue("1920");
await expect(heightInput).toHaveValue("1080");
// Click 4:5 preset
await page.getByRole("button", { name: "4:5" }).click();
await expect(widthInput).toHaveValue("1080");
await expect(heightInput).toHaveValue("1350");
});
test("JPG - subject focus crops and shows result", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadFile(page, fixturePath("test-100x100.jpg"));
// Use default subject mode with attention strategy
await page.getByTestId("smart-crop-submit").click();
// Wait for the processed image preview to appear
await expect(page.locator("section[aria-label='Image area'] img").first()).toBeVisible({
timeout: 300_000,
});
// No error shown
await expect(page.getByText("Network error")).not.toBeVisible();
});
test("HEIC input processes without error", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadFile(page, fixturePath("test-200x150.heic"));
await page.getByTestId("smart-crop-submit").click();
await expect(page.locator("section[aria-label='Image area'] img").first()).toBeVisible({
timeout: 300_000,
});
await expect(page.locator("text=cannot identify image")).not.toBeVisible();
});
});