2026-05-13 14:16:18 +08:00
|
|
|
import path from "node:path";
|
|
|
|
|
import { expect, isAiSidecarRunning, test } from "./helpers";
|
|
|
|
|
|
|
|
|
|
function fixturePath(name: string): string {
|
2026-06-28 18:57:53 +08:00
|
|
|
return path.join(process.cwd(), "tests", "fixtures", "image", "valid", name);
|
2026-05-13 14:16:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
test.describe("AI Canvas Expand", () => {
|
|
|
|
|
test("standalone /ai-canvas-expand route loads", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-05-13 14:16:18 +08:00
|
|
|
|
|
|
|
|
await expect(page.getByText("Tool not found")).not.toBeVisible();
|
2026-06-28 18:57:53 +08:00
|
|
|
// Heading appears in both the breadcrumb and the page; .first() avoids a
|
|
|
|
|
// strict-mode multiple-match error.
|
|
|
|
|
await expect(page.getByText("AI Canvas Expand").first()).toBeVisible();
|
|
|
|
|
|
|
|
|
|
// Settings (aspect-ratio + per-side inputs) only mount after a file loads.
|
|
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
2026-05-13 14:16:18 +08:00
|
|
|
await expect(page.getByText("Extend to aspect ratio")).toBeVisible();
|
|
|
|
|
await expect(page.getByText("Extend by (pixels)")).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("standalone submit disabled without file", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-06-28 18:57:53 +08:00
|
|
|
// The settings panel (and its submit button) mount only after a file is
|
|
|
|
|
// uploaded; before upload the page shows just the dropzone.
|
|
|
|
|
await expect(page.getByTestId("ai-canvas-expand-submit")).toHaveCount(0);
|
2026-05-13 14:16:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("standalone submit disabled when all extensions are zero", async ({
|
|
|
|
|
loggedInPage: page,
|
|
|
|
|
}) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-05-13 14:16:18 +08:00
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
|
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
await expect(page.getByTestId("ai-canvas-expand-submit")).toBeDisabled();
|
2026-05-13 14:16:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("standalone submit enables with extension set", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-05-13 14:16:18 +08:00
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
|
|
|
|
|
|
|
|
|
await page.locator("#cac-top").fill("50");
|
|
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
await expect(page.getByTestId("ai-canvas-expand-submit")).toBeEnabled();
|
2026-05-13 14:16:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("standalone aspect ratio preset fills extension values", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-05-13 14:16:18 +08:00
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
|
|
|
|
|
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
await page.getByRole("button", { name: "16:9" }).click();
|
|
|
|
|
|
|
|
|
|
const topInput = page.locator("#cac-top");
|
|
|
|
|
const rightInput = page.locator("#cac-right");
|
|
|
|
|
|
|
|
|
|
const topVal = Number(await topInput.inputValue());
|
|
|
|
|
const rightVal = Number(await rightInput.inputValue());
|
|
|
|
|
|
|
|
|
|
expect(topVal > 0 || rightVal > 0).toBe(true);
|
2026-05-13 15:47:39 +08:00
|
|
|
await expect(page.getByTestId("ai-canvas-expand-submit")).toBeEnabled();
|
2026-05-13 14:16:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("standalone shows new size display", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-05-13 14:16:18 +08:00
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
|
|
|
|
|
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
await page.locator("#cac-top").fill("50");
|
|
|
|
|
await page.locator("#cac-bottom").fill("50");
|
|
|
|
|
|
|
|
|
|
await expect(page.getByText(/New size: \d+ x \d+/)).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
test("tier buttons render with Balanced selected by default", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-06-28 18:57:53 +08:00
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
2026-05-13 14:16:18 +08:00
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
await expect(page.getByTestId("tier-fast")).toBeVisible();
|
|
|
|
|
await expect(page.getByTestId("tier-balanced")).toBeVisible();
|
|
|
|
|
await expect(page.getByTestId("tier-high")).toBeVisible();
|
2026-05-13 14:16:18 +08:00
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
const balanced = page.getByTestId("tier-balanced");
|
|
|
|
|
await expect(balanced).toHaveClass(/bg-primary/);
|
2026-05-13 14:16:18 +08:00
|
|
|
});
|
|
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
test("clicking tier button changes selection", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-06-28 18:57:53 +08:00
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
2026-05-13 14:16:18 +08:00
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
await page.getByTestId("tier-fast").click();
|
|
|
|
|
await expect(page.getByTestId("tier-fast")).toHaveClass(/bg-primary/);
|
|
|
|
|
await expect(page.getByTestId("tier-balanced")).not.toHaveClass(/bg-primary/);
|
2026-05-13 14:16:18 +08:00
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
await expect(page.getByText("Quick preview, fewer AI passes")).toBeVisible();
|
2026-05-13 14:16:18 +08:00
|
|
|
});
|
|
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
test("tier description updates on selection", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-06-28 18:57:53 +08:00
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
2026-05-13 14:16:18 +08:00
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
await expect(page.getByText("Good quality, moderate speed")).toBeVisible();
|
2026-05-13 14:16:18 +08:00
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
await page.getByTestId("tier-high").click();
|
|
|
|
|
await expect(page.getByText("Best results, slower")).toBeVisible();
|
2026-05-13 14:16:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ── Processing (requires AI sidecar) ────────────────────────────────
|
|
|
|
|
|
|
|
|
|
test("processes image (AI sidecar required)", async ({ loggedInPage: page }) => {
|
2026-06-24 20:19:37 +08:00
|
|
|
await page.goto("/image/ai-canvas-expand");
|
2026-05-13 14:16:18 +08:00
|
|
|
|
|
|
|
|
if (!(await isAiSidecarRunning(page))) {
|
|
|
|
|
test.skip(true, "AI sidecar not running");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await uploadFile(page, fixturePath("test-200x150.png"));
|
|
|
|
|
await page.locator("#cac-top").fill("30");
|
|
|
|
|
await page.locator("#cac-bottom").fill("30");
|
|
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
await page.getByTestId("ai-canvas-expand-submit").click();
|
2026-05-13 14:16:18 +08:00
|
|
|
|
2026-05-13 15:47:39 +08:00
|
|
|
const download = page.getByTestId("ai-canvas-expand-download");
|
2026-05-13 14:16:18 +08:00
|
|
|
const error = page.getByText(/failed|not available|not installed|error/i);
|
|
|
|
|
|
|
|
|
|
await expect(download.or(error)).toBeVisible({ timeout: 300_000 });
|
|
|
|
|
});
|
|
|
|
|
});
|