Files
SnapOtter/tests/e2e/ocr.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

110 lines
3.9 KiB
TypeScript

import { expect, test } from "./helpers";
async function uploadOcrFile(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 submitOcr(page: import("@playwright/test").Page) {
const submit = page.getByTestId("ocr-submit");
await expect(submit).toBeEnabled();
await submit.click();
await expect(page.getByText("Extracted Text")).toBeVisible({ timeout: 300_000 });
}
test.describe("OCR / Text Extraction", () => {
async function skipIfFeatureNotInstalled(page: import("@playwright/test").Page) {
await page.goto("/image/ocr");
await page.waitForLoadState("networkidle");
try {
await page.getByTestId("ocr-submit").waitFor({ state: "visible", timeout: 15_000 });
} catch {
test.skip(true, "ocr feature bundle not installed");
}
}
test("renders quality selector with three options", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
const buttons = page.locator("button").filter({ hasText: /^(Fast|Balanced|Best)$/ });
await expect(buttons).toHaveCount(3);
const balanced = page.locator("button").filter({ hasText: "Balanced" });
await expect(balanced).toHaveClass(/border-primary/);
});
test("renders enhance checkbox defaulting to unchecked", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
const checkbox = page.locator('input[type="checkbox"]');
await expect(checkbox).not.toBeChecked();
});
test("enhance defaults to unchecked when Best is selected", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await page.locator("button").filter({ hasText: "Best" }).click();
const checkbox = page.locator('input[type="checkbox"]');
await expect(checkbox).not.toBeChecked();
});
test("language section is collapsed by default showing auto-detect", async ({
loggedInPage: page,
}) => {
await skipIfFeatureNotInstalled(page);
await expect(page.getByText("auto-detect", { exact: false })).toBeVisible();
await expect(page.locator("select")).not.toBeVisible();
});
test("language section expands to show dropdown", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await page.getByText("Language").click();
await expect(page.locator("select")).toBeVisible();
const options = page.locator("select option");
await expect(options).toHaveCount(8);
});
test("extract text button is disabled without a file", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
const button = page.getByTestId("ocr-submit");
await expect(button).toBeDisabled();
});
test("uploads image and OCR processing completes", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadOcrFile(page, "tests/fixtures/image/valid/test-portrait.jpg");
await submitOcr(page);
const hasText = await page.getByTestId("ocr-result-text").isVisible();
const hasNoText = await page.getByText("No text detected").isVisible();
expect(hasText || hasNoText).toBe(true);
});
test("copy button is visible after OCR completes", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadOcrFile(page, "tests/fixtures/image/valid/test-portrait.jpg");
await submitOcr(page);
await expect(page.getByText("Copy")).toBeVisible();
});
test("shows 'no text detected' for blank image", async ({ loggedInPage: page }) => {
await skipIfFeatureNotInstalled(page);
await uploadOcrFile(page, "tests/fixtures/image/edge/test-blank.png");
await submitOcr(page);
await expect(page.getByText("No text detected")).toBeVisible();
});
});