mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
* fix(api): correct format/filename/container handling across tool routes Found during a comprehensive QA sweep exercising every tool against its full accepted-format matrix: - watermark-image, compose: preserve the requested output format and a matching download filename/extension instead of always emitting the source format - compose: crop oversized overlays to the visible base area instead of crashing Sharp's composite, and reject only overlays fully outside the base image instead of any oversized one - compare, vectorize: switch to the shared image input handler so filenames and formats like .svgz/.tga/RAW survive validation instead of being rejected pre-processing - tool-factory, images-to-video: normalize frames through Sharp before handing them to FFmpeg, fixing GIF/AVIF/RAW image-to-video jobs that previously failed or hung - media-tool, replace-audio, embed-subtitles: fix legacy container MIME/codec handling for MPEG sources and subtitle remux cases - files: expand download MIME mapping for text/data/document/video/audio outputs that were falling back to a generic content type - convert-document/presentation/spreadsheet: same-format conversions now return the original validated file instead of erroring or producing corrupt tiny output Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(web): dropzone a11y, stale localStorage getter, dead code - dropzone: stop making the whole drop-zone section clickable/focusable. A section acting as an interactive element around a real upload button is a nested-interactive-element anti-pattern that confuses screen readers; drag-and-drop doesn't need focus semantics, only the button fallback does. Keeps that button semantic and keyboard-reachable. Updates the two e2e call sites that clicked the section directly. - api, use-auth: read through window.localStorage via the existing API storage helper instead of the bare global, which resolves to Node's experimental localStorage getter under Vitest and threw - find-duplicates-settings, info-settings, login-page: remove dead code (unused zip-download handler, a stale mount-only effect dependency that left cached info stuck at reused indices, an unused response variable) Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(i18n): pt-BR, zh-CN, zh-TW were silently falling back to English The locale loader looked up dynamic-import exports by the raw locale code (mod["pt-BR"], mod["zh-CN"], mod["zh-TW"]), but those three modules export camelCased bindings (ptBR, zhCN, zhTW) since identifiers can't contain hyphens. The lookup returned undefined and every consumer silently fell back to English for these three locales. Replaces the generic lookup with explicit per-locale loaders so the mapping can't drift out of sync again. Also updates the dropzone helper copy across all 21 locales to match the drag-only dropzone wording from the previous commit. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(docs): clear build warnings in the VitePress site - config.mts: add an onwarn handler for the @vueuse INVALID_ANNOTATION warnings emitted during the docs build - deployment.md: the caddyfile code fence language isn't a shiki grammar VitePress ships with, so it warned on every build; use txt instead Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * test(qa): update QA harness for the drag-only dropzone and regen metadata - api-sweep, qa-helpers, verify-ai: add JSON-body tools, multi-input secondary fixtures, async polling for slow valid jobs, 501 FEATURE_NOT_INSTALLED skip handling, and safer per-tool settings - input-preview, pipeline-ui specs: update upload flow for the drag-only dropzone surface - add tests/fixtures/data/valid/chart.json, a valid chart fixture the updated helpers route to - regenerate tools-meta.json against current TOOLS[] Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(security): close a login timing side-channel, harden zip-slip tests Found during a black-box security sweep of the real auth-enabled production container: a nonexistent username returned 401 in ~3-10ms, while a wrong password for a real user took ~35-42ms, because scrypt verification only ran when a user row existed. That timing gap lets an attacker enumerate valid usernames without ever guessing a password. Now runs verification against a cached dummy hash on the unknown-user path too, so both cases cost the same regardless of outcome. extract-zip already had a relative-traversal regression test (../evil.txt), but its absolute-path rejection branches (name.startsWith("/") / startsWith("\\")) had none. Added the three missing cases: deep relative traversal, absolute Unix path, and Windows-style absolute path. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * test(qa): add UI-driven AI bundle install scripts QA_PROMPT.md's Phase 2 requires installing AI models the way a user does -- through the UI, on demand from HuggingFace -- and treats the curl-based admin install endpoint as fallback-only. Nothing in the harness actually drove that flow; tests/qa/seed-ai-models.sh installs via docker exec + pip, which is further from a real user than even the API fallback. install-ai-bundles-ui.mts logs in, opens Settings > AI Features, screenshots the pre-install state, clicks Install All, and screenshots progress -- then exits, since installs continue server-side once triggered. verify-ai-install-complete.mts polls bundle status, screenshots the completed state, and runs one real tool per installed bundle to prove the freshly-downloaded model actually executes. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(qa): correct the apiToolPath import in the AI verify script Dynamic import of the package name failed under tsx's module resolution from apps/api's node_modules context; use the same relative-path import api-sweep.mts already uses successfully. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(web): correct AI bundle size estimates shown before install Measured real downloads during GPU-node QA verification: photo-restoration pulls ~4.4GB (was advertised as 800MB-1GB, off by 4-5x) and ocr pulls ~5.5GB (was advertised as 3-4GB). Both estimates only accounted for model weights, not the pip dependencies (torch/paddle) that come down with them. Updated to reflect actual total download size, since that's what a user deciding whether they have the disk/bandwidth actually needs to know. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(web): make desktop Settings reachable when auth is disabled AvatarDropdown (the only desktop entry point to Settings) was gated behind `!isMobile && authEnabled`. With AUTH_ENABLED=false the synthetic anonymous admin user should have full Settings access per how auth.ts documents this mode -- and the mobile bottom nav already worked this way, showing Settings unconditionally. Desktop just had a stray extra gate the component doesn't need: AvatarDropdown already resolves its own username internally (falling back to "admin") and reads authEnabled itself where it actually matters (hiding the Logout button). Removed the outer gate; verified end-to-end against a fresh AUTH_ENABLED=false instance -- avatar now renders, Settings opens, shows the anonymous/Admin identity correctly. Also documents (not changes) a related finding in install_feature.py: detect_arch() always resolves amd64 hosts to the GPU-bundled archive variant regardless of actual GPU presence, since no CPU-only amd64 archive is published to the bundle repo yet. Left as a code comment rather than a behavior change, since requesting an unpublished archive key would hard-fail installs entirely -- worse than the current oversized-but-working download. Full detail in the QA report. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(ai): stop logging expected dispatcher reloads as crashes After each AI bundle install the Python dispatcher reloads because the venv changed, and after every app shutdown it's SIGTERMed. Both took the close handler's `code !== 0` branch (SIGTERM makes the exit code null), so they were counted as crashes -- producing an alarming "crash" line in the logs and a pointless ~1s recovery backoff after each of 7 installs. A `stopping` flag set in shutdown() lets the close handler tell an intentional stop apart from a real crash. The request-timeout kill path deliberately does not set it, so a genuinely hung script still records a crash and the 5-in-60s permanent-disable threshold is untouched. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(api): return a clean message when content-aware resize times out Carving a very high-resolution image down to a tiny target could exceed the caire subprocess timeout, and the raw error forwarded to the user was caire's terminal output -- ANSI color codes and progress-spinner control characters -- instead of anything actionable. Now: the timeout path throws a clear "timed out; try a smaller image or larger target" message (keeping the raw stderr as `cause` for server logs); friendlyError() strips ANSI/control chars centrally so any subprocess dump surfaced through the shared sanitizer is plain text; and the content-aware-resize route (a custom route that bypassed the sanitizer) now routes its error paths through friendlyError like every other tool. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(ai): stop bundle installs from exhausting host disk Installing an AI bundle on a tight-disk host could push the root filesystem to zero bytes free after the preflight check had already passed. Two root causes: - move_tree used copytree+rmtree, so during the move the extracted payload existed in both staging and the venv at once -- a full transient doubling on disk. Rewrote it to rename entries (a cheap metadata op on the same filesystem, no copy), falling back to a copy only across filesystems. - the preflight budget used the manifest's extractedSize verbatim, which is 0 for several archives, collapsing the estimate to just the compressed size. Added a conservative fallback (3x compressed) so a missing value can't under-reserve. Also added a real-on-disk re-check immediately before the first destructive venv write (measuring the actual extracted payload and whether the move needs extra space for a cross-filesystem copy), which also now covers the offline-import path that previously skipped the disk check entirely; wrapped the moves so an out-of-space failure returns a clean actionable error instead of a traceback; and made the disk check resolve the nearest existing ancestor so it never throws on a not-yet-created venv path. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * feat(web): show the real per-arch AI bundle download size The bundle cards and install prompt showed a hardcoded, architecture-blind estimatedSize string. That's misleading: amd64 hosts always pull the CUDA-inclusive archive (there's no CPU-only amd64 variant published), so a bundle labelled "1-2 GB" can actually download several times that, while arm64 pulls a much smaller archive for the same label. The manifest already carries the real per-arch compressedSize (and extractedSize where measured), so surface those: a new optional downloadBytes/installedBytes on FeatureBundleState, populated in getFeatureStates() for this host's arch (resolver mirrors install_feature.py detect_arch), shown by the UI when present with estimatedSize kept as the fallback label. Also nudged upscale-enhance's fallback string (4-5 -> 5-6 GB) to match its real compressed size, consistent with the earlier photo-restoration/ocr fixes. Fields are optional so demo/mock and existing tests stay compiling; the manifest's extractedSize is 0 for a few archives, which now surfaces as null rather than a bogus 0. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(web): move the AI install queue to the server so it survives tab close Installing multiple bundles could silently lose all but the first. The server rejected a concurrent install with 409, so the client worked around it by queueing the rest in browser-local state and only POSTing each once it saw the previous finish. A single POSTed install is durable (the installer child is detached from the request), but a queued one had zero server footprint -- close the tab mid-queue and those installs vanished with no error, while the UI still showed them "Queued". The client "mutex" didn't even serialize: the queued bundles' local waits all resolved at once and raced into concurrent POSTs that 409'd each other. Now the queue lives on the server (a small in-memory FIFO leaf module). The install endpoint enqueues instead of 409-ing and returns 202 {jobId, queued}; a pump starts the next bundle when the current one's child exits (and after an offline import releases the lock), all behind the existing venv + file locks, which are unchanged. The client just POSTs every bundle immediately and reflects the server-reported queued/installing status; Install All fires all POSTs and lets the server serialize them, keeping the one-shot retry-on-failure. Adds "queued" to FeatureStatus (the bundle card already rendered that state) and surfaces it from getFeatureStates. In-memory is deliberate: it matches the existing contract (survives a tab close, not a server restart, which already clears the lock on boot). Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG * fix(qa): don't log env-derived credentials in the AI-install script CodeQL flagged clear-text logging of sensitive information: the login status line interpolated the QA base URL and username (both read from the process environment) into a console.log. Replaced with a static message. QA helper only, but it's a real hygiene issue and cleared the high-severity code-scanning alert on the PR. Claude-Session: https://claude.ai/code/session_019fpSXhLGLXWwfyZY2tWhLG
772 lines
30 KiB
TypeScript
772 lines
30 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import type { Page } from "@playwright/test";
|
|
import { expect, getTestImagePath, test, uploadTestImage, waitForProcessing } from "./helpers";
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// GUI E2E: Watermark & Overlay Tools
|
|
// (watermark-text, watermark-image, text-overlay, compose, border)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test.describe("GUI Watermark & Overlay Tools", () => {
|
|
// ========================================================================
|
|
// WATERMARK TEXT
|
|
// ========================================================================
|
|
test.describe("Watermark Text", () => {
|
|
test("renders tool page with dropzone", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await expect(page.getByText("Text Watermark").first()).toBeVisible();
|
|
await expect(page.getByText("Upload from computer")).toBeVisible();
|
|
});
|
|
|
|
test("shows watermark text input and settings after upload", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#watermark-text-text")).toBeVisible();
|
|
// Default text is "Sample Watermark"
|
|
await expect(page.locator("#watermark-text-text")).toHaveValue("Sample Watermark");
|
|
});
|
|
|
|
test("font size slider visible", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#watermark-text-font-size")).toBeVisible();
|
|
});
|
|
|
|
test("submit disabled without file, enabled with file", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
|
|
// The settings panel and submit button render only after a file is
|
|
// uploaded. Before upload the page shows just the dropzone.
|
|
await expect(page.getByTestId("watermark-text-submit")).toHaveCount(0);
|
|
|
|
await uploadTestImage(page);
|
|
await expect(page.getByTestId("watermark-text-submit")).toBeEnabled();
|
|
});
|
|
|
|
test("shows color picker for watermark text", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#watermark-text-color")).toBeVisible();
|
|
});
|
|
|
|
test("shows opacity slider", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#watermark-text-opacity")).toBeVisible();
|
|
});
|
|
|
|
test("shows position dropdown with all options", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
const select = page.locator("#watermark-text-position");
|
|
await expect(select).toBeVisible();
|
|
const options = select.locator("option");
|
|
await expect(options).toHaveCount(6); // center, top-left, top-right, bottom-left, bottom-right, tiled
|
|
});
|
|
|
|
test("shows rotation slider", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#watermark-text-rotation")).toBeVisible();
|
|
});
|
|
|
|
test("opacity slider is interactive", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
const slider = page.locator("#watermark-text-opacity");
|
|
await expect(slider).toBeVisible();
|
|
await expect(slider).toHaveAttribute("type", "range");
|
|
});
|
|
|
|
test("font size slider is interactive", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
const slider = page.locator("#watermark-text-font-size");
|
|
await expect(slider).toBeVisible();
|
|
await expect(slider).toHaveAttribute("type", "range");
|
|
});
|
|
|
|
test("changing text input updates value", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await page.locator("#watermark-text-text").fill("My Custom Text");
|
|
await expect(page.locator("#watermark-text-text")).toHaveValue("My Custom Text");
|
|
});
|
|
|
|
test("processes watermark and shows download", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await page.locator("#watermark-text-text").fill("Test Watermark");
|
|
await page.getByTestId("watermark-text-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("watermark-text-download")).toBeVisible({
|
|
timeout: 15_000,
|
|
});
|
|
});
|
|
});
|
|
|
|
// ========================================================================
|
|
// WATERMARK IMAGE
|
|
// ========================================================================
|
|
test.describe("Watermark Image", () => {
|
|
test("renders tool page with dropzone", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-image");
|
|
await expect(page.getByText("Image Watermark").first()).toBeVisible();
|
|
await expect(page.getByText("Upload from computer")).toBeVisible();
|
|
});
|
|
|
|
test("shows position and opacity controls after upload", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-image");
|
|
await uploadTestImage(page);
|
|
|
|
// Position selector should be visible
|
|
await expect(page.getByText(/position/i).first()).toBeVisible();
|
|
// Opacity slider
|
|
await expect(page.getByText(/opacity/i).first()).toBeVisible();
|
|
});
|
|
|
|
test("shows watermark upload area after main image upload", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-image");
|
|
await uploadTestImage(page);
|
|
|
|
// Should see a prompt to upload the watermark/logo image
|
|
await expect(page.getByText(/watermark|logo|overlay/i).first()).toBeVisible();
|
|
});
|
|
|
|
test("shows position dropdown with five options", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-image");
|
|
await uploadTestImage(page);
|
|
|
|
const select = page.locator("#watermark-image-position");
|
|
await expect(select).toBeVisible();
|
|
const options = select.locator("option");
|
|
await expect(options).toHaveCount(5); // center, top-left, top-right, bottom-left, bottom-right
|
|
});
|
|
|
|
test("shows opacity slider with percentage", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-image");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#watermark-image-opacity")).toBeVisible();
|
|
});
|
|
|
|
test("shows scale slider with percentage", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-image");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#watermark-image-scale")).toBeVisible();
|
|
});
|
|
|
|
test("submit disabled without watermark file", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-image");
|
|
await uploadTestImage(page);
|
|
|
|
const submitBtn = page.getByTestId("watermark-image-submit");
|
|
await expect(submitBtn).toBeDisabled();
|
|
});
|
|
});
|
|
|
|
// ========================================================================
|
|
// TEXT OVERLAY
|
|
// ========================================================================
|
|
test.describe("Text Overlay", () => {
|
|
test("renders tool page with dropzone", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await expect(page.getByText("Text Overlay").first()).toBeVisible();
|
|
await expect(page.getByText("Upload from computer")).toBeVisible();
|
|
});
|
|
|
|
test("shows text input and font size slider after upload", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#text-overlay-text")).toBeVisible();
|
|
await expect(page.locator("#text-overlay-text")).toHaveValue("Your Text Here");
|
|
await expect(page.locator("#text-overlay-font-size")).toBeVisible();
|
|
});
|
|
|
|
test("submit disabled without file, enabled with file", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
|
|
// The settings panel and submit button render only after a file is
|
|
// uploaded. Before upload the page shows just the dropzone.
|
|
await expect(page.getByTestId("text-overlay-submit")).toHaveCount(0);
|
|
|
|
await uploadTestImage(page);
|
|
await expect(page.getByTestId("text-overlay-submit")).toBeEnabled();
|
|
});
|
|
|
|
test("shows text color picker", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#text-overlay-color")).toBeVisible();
|
|
});
|
|
|
|
test("shows position dropdown with three options", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
const select = page.locator("#text-overlay-position");
|
|
await expect(select).toBeVisible();
|
|
const options = select.locator("option");
|
|
await expect(options).toHaveCount(3); // top, center, bottom
|
|
});
|
|
|
|
test("shows drop shadow checkbox", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.getByText("Shadow")).toBeVisible();
|
|
});
|
|
|
|
test("background box checkbox reveals box color picker", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.getByText("Background Box")).toBeVisible();
|
|
|
|
// Box color should NOT be visible by default
|
|
await expect(page.locator("#text-overlay-box-color")).not.toBeVisible();
|
|
|
|
// Check Background Box
|
|
await page
|
|
.locator("label")
|
|
.filter({ hasText: "Background Box" })
|
|
.locator("input[type='checkbox']")
|
|
.check();
|
|
|
|
// Box color picker should now appear
|
|
await expect(page.locator("#text-overlay-box-color")).toBeVisible();
|
|
});
|
|
|
|
test("font size slider is interactive", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
const slider = page.locator("#text-overlay-font-size");
|
|
await expect(slider).toBeVisible();
|
|
await expect(slider).toHaveAttribute("type", "range");
|
|
});
|
|
|
|
test("changing text input updates value", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
await page.locator("#text-overlay-text").fill("Custom Overlay");
|
|
await expect(page.locator("#text-overlay-text")).toHaveValue("Custom Overlay");
|
|
});
|
|
|
|
test("processes text overlay and shows download", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
await page.getByTestId("text-overlay-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("text-overlay-download")).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
});
|
|
|
|
// ========================================================================
|
|
// COMPOSE (Image Composition)
|
|
//
|
|
// The compose page has two dashed-border elements: the overlay upload
|
|
// button in the settings sidebar and the main dropzone. The generic
|
|
// uploadTestImage helper picks the first border-dashed element (overlay
|
|
// button), so compose tests use the dropzone's aria-label and set
|
|
// overlay files directly on the hidden input.
|
|
// ========================================================================
|
|
test.describe("Compose", () => {
|
|
async function uploadBaseImage(page: Page) {
|
|
const fileChooserPromise = page.waitForEvent("filechooser");
|
|
await page
|
|
.locator("section[aria-label='File drop zone']")
|
|
.getByRole("button", { name: /upload from computer/i })
|
|
.click();
|
|
const fileChooser = await fileChooserPromise;
|
|
await fileChooser.setFiles(getTestImagePath());
|
|
await page.waitForTimeout(500);
|
|
}
|
|
|
|
async function uploadOverlayImage(page: Page, filePath?: string) {
|
|
await page.locator("#compose-overlay-image").setInputFiles(filePath ?? getTestImagePath());
|
|
await page.waitForTimeout(500);
|
|
}
|
|
|
|
test("renders tool page with dropzone", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await expect(page.getByText("Image Composition").first()).toBeVisible();
|
|
await expect(page.locator("section[aria-label='File drop zone']")).toBeVisible();
|
|
});
|
|
|
|
test("shows overlay upload and position controls", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
// Settings render only after a base image is loaded; before that the
|
|
// page shows just the dropzone.
|
|
await uploadBaseImage(page);
|
|
|
|
await expect(page.getByText("X Position")).toBeVisible();
|
|
await expect(page.getByText("Y Position")).toBeVisible();
|
|
await expect(page.getByText("Opacity").first()).toBeVisible();
|
|
await expect(page.getByText("Blend Mode")).toBeVisible();
|
|
await expect(page.getByTestId("compose-submit")).toBeVisible();
|
|
});
|
|
|
|
test("shows overlay image upload button", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
|
|
await expect(page.getByText("Overlay Image").first()).toBeVisible();
|
|
await expect(page.getByText("Choose overlay image")).toBeVisible();
|
|
});
|
|
|
|
test("shows X and Y position number inputs", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
|
|
await expect(page.locator("#compose-x-position")).toBeVisible();
|
|
await expect(page.locator("#compose-y-position")).toBeVisible();
|
|
});
|
|
|
|
test("shows opacity slider", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
|
|
await expect(page.locator("#compose-opacity")).toBeVisible();
|
|
});
|
|
|
|
test("blend mode dropdown has all options", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
|
|
const select = page.locator("#compose-blend-mode");
|
|
await expect(select).toBeVisible();
|
|
const options = select.locator("option");
|
|
await expect(options).toHaveCount(10);
|
|
});
|
|
|
|
test("submit disabled without overlay file", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
|
|
const submitBtn = page.getByTestId("compose-submit");
|
|
await expect(submitBtn).toBeDisabled();
|
|
});
|
|
|
|
test("submit enabled after uploading both base and overlay", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
await uploadOverlayImage(page);
|
|
|
|
await expect(page.getByTestId("compose-submit")).toBeEnabled();
|
|
});
|
|
|
|
test("processes composition and shows download", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
await uploadOverlayImage(page);
|
|
|
|
await page.getByTestId("compose-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("compose-download")).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
|
|
test("processes with custom position and opacity", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
await uploadOverlayImage(page);
|
|
|
|
await page.locator("#compose-x-position").fill("10");
|
|
await page.locator("#compose-y-position").fill("20");
|
|
await page.locator("#compose-opacity").fill("50");
|
|
|
|
await page.getByTestId("compose-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("compose-download")).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
|
|
test("processes with multiply blend mode", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
await uploadOverlayImage(page);
|
|
|
|
await page.locator("#compose-blend-mode").selectOption("multiply");
|
|
|
|
await page.getByTestId("compose-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("compose-download")).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
|
|
test("overlay filename shown after selection", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
// The overlay file input lives in the settings panel, which renders only
|
|
// after a base image is loaded.
|
|
await uploadBaseImage(page);
|
|
// Use a distinct overlay fixture so its filename is unambiguous (the
|
|
// base image is test-image.png, which would otherwise also match).
|
|
await uploadOverlayImage(page, "tests/fixtures/image/valid/test-50x50.webp");
|
|
|
|
await expect(page.getByText("test-50x50.webp")).toBeVisible();
|
|
});
|
|
|
|
test("shows size info after processing", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
await uploadOverlayImage(page);
|
|
|
|
await page.getByTestId("compose-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("compose-download")).toBeVisible({ timeout: 15_000 });
|
|
await expect(page.getByText(/Original:/).first()).toBeVisible();
|
|
await expect(page.getByText(/Processed:/).first()).toBeVisible();
|
|
});
|
|
|
|
test("processes webp overlay on png base", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
|
|
const webpPath = path.join(
|
|
process.cwd(),
|
|
"tests",
|
|
"fixtures",
|
|
"image",
|
|
"valid",
|
|
"test-50x50.webp",
|
|
);
|
|
await uploadOverlayImage(page, webpPath);
|
|
|
|
await page.getByTestId("compose-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("compose-download")).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
|
|
test("shows error for corrupt overlay file", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/compose");
|
|
await uploadBaseImage(page);
|
|
|
|
const tmpDir = path.join(process.cwd(), "test-results");
|
|
const corruptPath = path.join(tmpDir, "corrupt-overlay.png");
|
|
fs.writeFileSync(corruptPath, Buffer.from("not-an-image"));
|
|
await uploadOverlayImage(page, corruptPath);
|
|
|
|
await page.getByTestId("compose-submit").click();
|
|
|
|
await expect(page.getByText(/Processing failed|Invalid image|error/i)).toBeVisible({
|
|
timeout: 15_000,
|
|
});
|
|
});
|
|
});
|
|
|
|
// ========================================================================
|
|
// BORDER
|
|
// ========================================================================
|
|
test.describe("Border", () => {
|
|
test("renders tool page with dropzone", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await expect(page.getByText("Border").first()).toBeVisible();
|
|
await expect(page.getByText("Upload from computer")).toBeVisible();
|
|
});
|
|
|
|
test("shows border preset buttons after upload", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
// Presets from border-settings.tsx
|
|
await expect(page.getByText("Clean White").first()).toBeVisible();
|
|
await expect(page.getByText("Gallery Black").first()).toBeVisible();
|
|
await expect(page.getByText("Shadow").first()).toBeVisible();
|
|
await expect(page.getByText("Rounded").first()).toBeVisible();
|
|
});
|
|
|
|
test("shows border width and color controls after upload", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.getByText(/border width|width/i).first()).toBeVisible();
|
|
});
|
|
|
|
test("submit button uses data-testid", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.getByTestId("border-submit")).toBeVisible();
|
|
});
|
|
|
|
test("shows border width slider", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#border-width")).toBeVisible();
|
|
});
|
|
|
|
test("shows border color swatches", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#border-color")).toBeVisible();
|
|
});
|
|
|
|
test("shows padding slider", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#border-padding")).toBeVisible();
|
|
});
|
|
|
|
test("shows padding color swatches", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#padding-color")).toBeVisible();
|
|
});
|
|
|
|
test("shows corner radius slider", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#border-corner-radius")).toBeVisible();
|
|
});
|
|
|
|
test("shadow toggle reveals shadow controls", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
// Shadow toggle switch
|
|
const shadowToggle = page.locator("button[role='switch'][aria-checked]").first();
|
|
await expect(shadowToggle).toBeVisible();
|
|
|
|
// Shadow blur should not be visible before toggle
|
|
await expect(page.locator("#shadow-blur")).not.toBeVisible();
|
|
|
|
// Toggle shadow on
|
|
await shadowToggle.click();
|
|
|
|
// Shadow controls should now appear
|
|
await expect(page.locator("#shadow-blur")).toBeVisible();
|
|
await expect(page.locator("#shadow-offset-x")).toBeVisible();
|
|
await expect(page.locator("#shadow-offset-y")).toBeVisible();
|
|
await expect(page.locator("#shadow-color")).toBeVisible();
|
|
await expect(page.locator("#shadow-opacity")).toBeVisible();
|
|
});
|
|
|
|
test("shows all preset buttons", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.getByText("Polaroid").first()).toBeVisible();
|
|
await expect(page.getByText("Vintage").first()).toBeVisible();
|
|
await expect(page.getByText("Minimal").first()).toBeVisible();
|
|
await expect(page.getByText("Cinematic").first()).toBeVisible();
|
|
});
|
|
|
|
test("border width slider is interactive", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
const slider = page.locator("#border-width");
|
|
await expect(slider).toBeVisible();
|
|
await expect(slider).toHaveAttribute("type", "range");
|
|
});
|
|
|
|
test("clicking a preset updates border settings", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
// Click Polaroid preset
|
|
await page.getByText("Polaroid").first().click();
|
|
// Click Gallery Black preset
|
|
await page.getByText("Gallery Black").first().click();
|
|
});
|
|
|
|
test("submit disabled without file, enabled with file", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
|
|
// Submit is not rendered until a file is uploaded.
|
|
await expect(page.getByTestId("border-submit")).toHaveCount(0);
|
|
|
|
await uploadTestImage(page);
|
|
await expect(page.getByTestId("border-submit")).toBeEnabled();
|
|
});
|
|
|
|
test("processes border and shows download", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await page.getByTestId("border-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("border-download")).toBeVisible({ timeout: 15_000 });
|
|
});
|
|
});
|
|
|
|
// ========================================================================
|
|
// UNDO / STATE RESET (Overlay tools)
|
|
// ========================================================================
|
|
test.describe("Undo and State Reset", () => {
|
|
test("watermark-text: undo after processing returns to text input", async ({
|
|
loggedInPage: page,
|
|
}) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await page.locator("#watermark-text-text").fill("Undo Test");
|
|
await page.getByTestId("watermark-text-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("watermark-text-download")).toBeVisible({ timeout: 15_000 });
|
|
|
|
await page.getByRole("button", { name: /adjust settings/i }).click();
|
|
|
|
await expect(page.getByTestId("watermark-text-submit")).toBeVisible({ timeout: 5_000 });
|
|
await expect(page.getByTestId("watermark-text-download")).not.toBeVisible();
|
|
await expect(page.locator("#watermark-text-text")).toBeVisible();
|
|
});
|
|
|
|
test("text-overlay: undo after processing returns to settings", async ({
|
|
loggedInPage: page,
|
|
}) => {
|
|
await page.goto("/image/text-overlay");
|
|
await uploadTestImage(page);
|
|
|
|
await page.getByTestId("text-overlay-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("text-overlay-download")).toBeVisible({ timeout: 15_000 });
|
|
|
|
await page.getByRole("button", { name: /adjust settings/i }).click();
|
|
|
|
await expect(page.getByTestId("text-overlay-submit")).toBeVisible({ timeout: 5_000 });
|
|
await expect(page.getByTestId("text-overlay-download")).not.toBeVisible();
|
|
await expect(page.locator("#text-overlay-text")).toBeVisible();
|
|
});
|
|
|
|
test("compose: undo after processing returns to position controls", async ({
|
|
loggedInPage: page,
|
|
}) => {
|
|
await page.goto("/image/compose");
|
|
|
|
// Use compose-specific upload helpers
|
|
const fileChooserPromise = page.waitForEvent("filechooser");
|
|
await page
|
|
.locator("section[aria-label='File drop zone']")
|
|
.getByRole("button", { name: /upload from computer/i })
|
|
.click();
|
|
const fileChooser = await fileChooserPromise;
|
|
await fileChooser.setFiles(getTestImagePath());
|
|
await page.waitForTimeout(500);
|
|
|
|
await page.locator("#compose-overlay-image").setInputFiles(getTestImagePath());
|
|
await page.waitForTimeout(500);
|
|
|
|
await page.getByTestId("compose-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("compose-download")).toBeVisible({ timeout: 15_000 });
|
|
|
|
await page.getByRole("button", { name: /adjust settings/i }).click();
|
|
|
|
await expect(page.getByTestId("compose-submit")).toBeVisible({ timeout: 5_000 });
|
|
await expect(page.locator("#compose-x-position")).toBeVisible();
|
|
await expect(page.locator("#compose-y-position")).toBeVisible();
|
|
});
|
|
|
|
test("border: undo after processing returns to preset buttons", async ({
|
|
loggedInPage: page,
|
|
}) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await page.getByTestId("border-submit").click();
|
|
await waitForProcessing(page);
|
|
|
|
await expect(page.getByTestId("border-download")).toBeVisible({ timeout: 15_000 });
|
|
|
|
await page.getByRole("button", { name: /adjust settings/i }).click();
|
|
|
|
await expect(page.getByTestId("border-submit")).toBeVisible({ timeout: 5_000 });
|
|
await expect(page.getByTestId("border-download")).not.toBeVisible();
|
|
await expect(page.getByText("Clean White").first()).toBeVisible();
|
|
});
|
|
|
|
test("watermark-text: clear all returns to dropzone", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/watermark-text");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#watermark-text-text")).toBeVisible();
|
|
|
|
await page.getByText("Clear all").click();
|
|
|
|
await expect(page.getByText("Upload from computer")).toBeVisible({ timeout: 5_000 });
|
|
});
|
|
|
|
test("border: navigate away resets state", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
await expect(page.locator("#border-width")).toBeVisible();
|
|
|
|
await page.goto("/image/watermark-text");
|
|
await page.goto("/image/border");
|
|
|
|
await expect(page.getByText("Upload from computer")).toBeVisible();
|
|
});
|
|
});
|
|
|
|
// ========================================================================
|
|
// BORDER: LIVE PREVIEW VERIFICATION
|
|
// ========================================================================
|
|
test.describe("Border Live Preview", () => {
|
|
test("selecting a preset updates the live preview styling", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
const previewImg = page.locator("img").first();
|
|
await expect(previewImg).toBeVisible();
|
|
|
|
// Click Polaroid preset
|
|
await page.getByText("Polaroid").first().click();
|
|
await page.waitForTimeout(500);
|
|
|
|
// The image wrapper should have styling applied (border, padding, etc.)
|
|
// Check that some wrapper element has a non-default style
|
|
const wrapper = previewImg.locator("..");
|
|
const _bgColor = await wrapper.evaluate((el) => window.getComputedStyle(el).backgroundColor);
|
|
// Polaroid preset uses white background -- just verify the preview didn't error
|
|
await expect(previewImg).toBeVisible();
|
|
});
|
|
|
|
test("changing border width updates preview in real-time", async ({ loggedInPage: page }) => {
|
|
await page.goto("/image/border");
|
|
await uploadTestImage(page);
|
|
|
|
const previewImg = page.locator("img").first();
|
|
await expect(previewImg).toBeVisible();
|
|
|
|
// Change border width
|
|
await page.locator("#border-width").fill("20");
|
|
await page.waitForTimeout(500);
|
|
|
|
// Preview should still be visible and updated
|
|
await expect(previewImg).toBeVisible();
|
|
});
|
|
});
|
|
});
|