Files
SnapOtter/tests/e2e/image-to-pdf-target-size.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

125 lines
4.6 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { getTestImagePath, waitForProcessing } from "./helpers";
async function uploadViaButton(page: import("@playwright/test").Page) {
const testImagePath = getTestImagePath();
const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByRole("button", { name: /upload from computer/i }).click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(testImagePath);
await page.waitForTimeout(500);
}
test.describe("Image to PDF - Target File Size", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/image/image-to-pdf");
await page.waitForLoadState("networkidle");
});
test("target size controls are visible", async ({ page }) => {
const valueInput = page.getByTestId("image-to-pdf-target-size-value");
const unitSelect = page.getByTestId("image-to-pdf-target-size-unit");
await expect(valueInput).toBeVisible();
await expect(unitSelect).toBeVisible();
await expect(unitSelect).toHaveValue("MB");
});
test("creates PDF with target size and shows success result", async ({ page }) => {
await uploadViaButton(page);
const valueInput = page.getByTestId("image-to-pdf-target-size-value");
await valueInput.fill("2");
const unitSelect = page.getByTestId("image-to-pdf-target-size-unit");
await expect(unitSelect).toHaveValue("MB");
const submitBtn = page.getByTestId("image-to-pdf-submit");
await submitBtn.click();
await waitForProcessing(page, 60_000);
const downloadLink = page.getByTestId("image-to-pdf-download");
await expect(downloadLink).toBeVisible({ timeout: 30_000 });
const compressionResult = page.getByTestId("image-to-pdf-compression-result");
await expect(compressionResult).toBeVisible();
await expect(compressionResult).toContainText("Target met");
await expect(compressionResult).toContainText("JPEG quality");
});
test("creates PDF with KB unit and shows success result", async ({ page }) => {
await uploadViaButton(page);
const valueInput = page.getByTestId("image-to-pdf-target-size-value");
await valueInput.fill("500");
const unitSelect = page.getByTestId("image-to-pdf-target-size-unit");
await unitSelect.selectOption("KB");
const submitBtn = page.getByTestId("image-to-pdf-submit");
await submitBtn.click();
await waitForProcessing(page, 60_000);
const downloadLink = page.getByTestId("image-to-pdf-download");
await expect(downloadLink).toBeVisible({ timeout: 30_000 });
const compressionResult = page.getByTestId("image-to-pdf-compression-result");
await expect(compressionResult).toBeVisible();
await expect(compressionResult).toContainText("Target met");
});
test("shows warning when target cannot be met", async ({ page }) => {
await uploadViaButton(page);
const valueInput = page.getByTestId("image-to-pdf-target-size-value");
await valueInput.fill("51");
const unitSelect = page.getByTestId("image-to-pdf-target-size-unit");
await unitSelect.selectOption("KB");
const submitBtn = page.getByTestId("image-to-pdf-submit");
await submitBtn.click();
await waitForProcessing(page, 60_000);
const downloadLink = page.getByTestId("image-to-pdf-download");
await expect(downloadLink).toBeVisible({ timeout: 30_000 });
const compressionResult = page.getByTestId("image-to-pdf-compression-result");
await expect(compressionResult).toBeVisible();
});
test("creates PDF without target size (backwards compatible)", async ({ page }) => {
await uploadViaButton(page);
const submitBtn = page.getByTestId("image-to-pdf-submit");
await submitBtn.click();
await waitForProcessing(page, 60_000);
const downloadLink = page.getByTestId("image-to-pdf-download");
await expect(downloadLink).toBeVisible({ timeout: 30_000 });
const compressionResult = page.getByTestId("image-to-pdf-compression-result");
await expect(compressionResult).not.toBeVisible();
});
test("can switch between KB and MB units", async ({ page }) => {
const unitSelect = page.getByTestId("image-to-pdf-target-size-unit");
await expect(unitSelect).toHaveValue("MB");
await unitSelect.selectOption("KB");
await expect(unitSelect).toHaveValue("KB");
await unitSelect.selectOption("MB");
await expect(unitSelect).toHaveValue("MB");
});
test("target size input accepts decimal values", async ({ page }) => {
const valueInput = page.getByTestId("image-to-pdf-target-size-value");
await valueInput.fill("1.5");
await expect(valueInput).toHaveValue("1.5");
});
});