2026-03-25 09:27:12 +08:00
|
|
|
import { expect, getTestImagePath, test } from "./helpers";
|
2026-03-22 19:28:57 +08:00
|
|
|
|
|
|
|
|
test.describe("Automate Page", () => {
|
2026-03-24 20:37:14 +08:00
|
|
|
// Retry flaky tests caused by dev server timing
|
|
|
|
|
test.describe.configure({ retries: 3 });
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Navigate to /automate and wait for the page to fully render.
|
|
|
|
|
* Uses multiple retry strategies for blank-page flakes.
|
|
|
|
|
*/
|
|
|
|
|
async function gotoAutomate(page: import("@playwright/test").Page) {
|
|
|
|
|
const heading = page.getByRole("heading", {
|
2026-04-24 23:27:08 +08:00
|
|
|
name: /pipeline builder|automate/i,
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
|
|
|
if (attempt === 0) {
|
2026-04-24 23:27:08 +08:00
|
|
|
await page.goto("/automate", { waitUntil: "load" });
|
2026-03-24 20:37:14 +08:00
|
|
|
} else {
|
|
|
|
|
// On retry, wait then reload
|
|
|
|
|
await page.waitForTimeout(500);
|
2026-04-24 23:27:08 +08:00
|
|
|
await page.goto("/automate", { waitUntil: "load" });
|
2026-03-24 20:37:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await expect(heading).toBeVisible({ timeout: 8_000 });
|
|
|
|
|
return; // Page loaded successfully
|
|
|
|
|
} catch {
|
|
|
|
|
// Continue to next attempt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
// Final attempt - let it throw if it fails
|
2026-04-24 23:27:08 +08:00
|
|
|
await page.goto("/automate", { waitUntil: "load" });
|
2026-03-24 20:37:14 +08:00
|
|
|
await expect(heading).toBeVisible({ timeout: 10_000 });
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
/** Wait for pipeline steps to render. */
|
2026-03-25 09:27:12 +08:00
|
|
|
async function waitForSteps(page: import("@playwright/test").Page, count: number) {
|
2026-03-24 20:37:14 +08:00
|
|
|
await expect(page.getByTitle("Remove")).toHaveCount(count, {
|
|
|
|
|
timeout: 5_000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
/** Open the tool picker, search for a tool by name, and click it. */
|
|
|
|
|
async function addToolStep(
|
|
|
|
|
page: import("@playwright/test").Page,
|
|
|
|
|
name: string,
|
|
|
|
|
expectedCount: number,
|
|
|
|
|
) {
|
|
|
|
|
await page.getByPlaceholder("Search tools...").fill(name);
|
|
|
|
|
await page
|
|
|
|
|
.getByRole("button", { name: new RegExp(name, "i") })
|
|
|
|
|
.first()
|
|
|
|
|
.click();
|
|
|
|
|
await waitForSteps(page, expectedCount);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 20:37:14 +08:00
|
|
|
const testImagePath = getTestImagePath();
|
|
|
|
|
|
2026-04-13 16:26:38 +08:00
|
|
|
/** Upload the test image via the Dropzone file chooser in the right panel. */
|
2026-03-24 20:37:14 +08:00
|
|
|
async function uploadTestFile(page: import("@playwright/test").Page) {
|
|
|
|
|
const fileChooserPromise = page.waitForEvent("filechooser");
|
2026-04-13 16:26:38 +08:00
|
|
|
// The Dropzone renders a button labelled "Upload from computer"
|
|
|
|
|
await page.getByRole("button", { name: /upload from computer/i }).click();
|
2026-03-24 20:37:14 +08:00
|
|
|
const fileChooser = await fileChooserPromise;
|
|
|
|
|
await fileChooser.setFiles(testImagePath);
|
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
// --- Page Rendering ---
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
test("automate page renders pipeline builder", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-04-24 23:27:08 +08:00
|
|
|
await expect(
|
|
|
|
|
page.getByText(/add tools from the palette|chain tools into a pipeline/i).first(),
|
|
|
|
|
).toBeVisible();
|
2026-03-22 19:28:57 +08:00
|
|
|
});
|
|
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
test("shows empty state message when no steps", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-06-28 18:57:53 +08:00
|
|
|
// The empty-state prompt (t.automate.addToolsPrompt) renders in both the canvas
|
|
|
|
|
// header and the pipeline-builder body when no steps exist, so scope to the first.
|
2026-04-24 23:27:08 +08:00
|
|
|
await expect(
|
2026-06-28 18:57:53 +08:00
|
|
|
page.getByText(/add tools from the palette|add steps to build your pipeline/i).first(),
|
2026-04-24 23:27:08 +08:00
|
|
|
).toBeVisible();
|
2026-03-22 19:28:57 +08:00
|
|
|
});
|
|
|
|
|
|
2026-04-13 16:26:38 +08:00
|
|
|
test("shows dropzone when no file uploaded", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-04-13 16:26:38 +08:00
|
|
|
// The Dropzone section should be visible with its upload button
|
|
|
|
|
await expect(page.locator("section[aria-label='File drop zone']")).toBeVisible();
|
|
|
|
|
await expect(page.getByRole("button", { name: /upload from computer/i })).toBeVisible();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
2026-03-22 19:28:57 +08:00
|
|
|
|
2026-04-24 23:27:08 +08:00
|
|
|
test("has tool palette search", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-04-24 23:27:08 +08:00
|
|
|
await expect(page.getByPlaceholder("Search tools...")).toBeVisible();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
test("has Process button (disabled when no steps or file)", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
|
|
|
|
const processBtn = page.getByRole("button", {
|
|
|
|
|
name: "Process",
|
|
|
|
|
exact: true,
|
|
|
|
|
});
|
|
|
|
|
await expect(processBtn).toBeVisible();
|
|
|
|
|
await expect(processBtn).toBeDisabled();
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
test("has Save Pipeline button (disabled when no steps)", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-04-13 16:26:38 +08:00
|
|
|
// Save Pipeline button is only rendered when steps > 0, so it should not exist yet
|
2026-04-25 07:23:58 +08:00
|
|
|
await expect(page.getByRole("button", { name: "Save" })).not.toBeVisible();
|
2026-04-13 16:26:38 +08:00
|
|
|
|
|
|
|
|
// Add a step so the button appears
|
|
|
|
|
await addToolStep(page, "Resize", 1);
|
2026-04-25 07:23:58 +08:00
|
|
|
await expect(page.getByRole("button", { name: "Save" })).toBeVisible();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
// --- Add Step ---
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-04-24 23:27:08 +08:00
|
|
|
test("tool palette is visible with search", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-04-24 23:27:08 +08:00
|
|
|
await expect(page.getByPlaceholder("Search tools...")).toBeVisible();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
test("selecting a tool from picker adds a step", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-03-28 18:34:05 +08:00
|
|
|
await addToolStep(page, "Resize", 1);
|
|
|
|
|
// Verify empty state is gone
|
2026-04-24 23:27:08 +08:00
|
|
|
await expect(
|
|
|
|
|
page.getByText(/add tools from the palette|add steps to build your pipeline/i),
|
|
|
|
|
).not.toBeVisible();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("can add multiple steps", async ({ loggedInPage: page }) => {
|
|
|
|
|
await gotoAutomate(page);
|
2026-03-28 18:34:05 +08:00
|
|
|
await addToolStep(page, "Resize", 1);
|
|
|
|
|
await addToolStep(page, "Convert", 2);
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
test("can add resize, remove-background, then compress without drops", async ({
|
|
|
|
|
loggedInPage: page,
|
|
|
|
|
}) => {
|
|
|
|
|
await gotoAutomate(page);
|
|
|
|
|
await addToolStep(page, "Resize", 1);
|
|
|
|
|
await addToolStep(page, "Remove Background", 2);
|
|
|
|
|
await addToolStep(page, "Compress", 3);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// --- Step Controls ---
|
2026-03-24 20:37:14 +08:00
|
|
|
|
|
|
|
|
test("can remove a step", async ({ loggedInPage: page }) => {
|
|
|
|
|
await gotoAutomate(page);
|
2026-03-28 18:34:05 +08:00
|
|
|
await addToolStep(page, "Resize", 1);
|
|
|
|
|
await addToolStep(page, "Compress", 2);
|
2026-03-24 20:37:14 +08:00
|
|
|
|
|
|
|
|
await page.getByTitle("Remove").first().click();
|
|
|
|
|
await waitForSteps(page, 1);
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
// --- File Upload ---
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-04-13 16:26:38 +08:00
|
|
|
test("can upload a file via dropzone", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
|
|
|
|
await uploadTestFile(page);
|
|
|
|
|
|
2026-04-13 16:26:38 +08:00
|
|
|
// File name should be visible in the left panel file info section
|
2026-04-20 10:56:47 +08:00
|
|
|
await expect(page.getByText("test-image.png").first()).toBeVisible();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
// --- Save Pipeline ---
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
test("Save Pipeline button enables after adding steps", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-03-28 18:34:05 +08:00
|
|
|
await addToolStep(page, "Resize", 1);
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-04-25 07:23:58 +08:00
|
|
|
await expect(page.getByRole("button", { name: "Save" })).toBeVisible();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
test("clicking Save Pipeline shows name input form", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-03-28 18:34:05 +08:00
|
|
|
await addToolStep(page, "Resize", 1);
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-04-25 07:23:58 +08:00
|
|
|
await page.getByRole("button", { name: "Save" }).click();
|
2026-03-25 09:27:12 +08:00
|
|
|
await expect(page.getByPlaceholder("Pipeline name")).toBeVisible();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-04-13 16:26:38 +08:00
|
|
|
test("can save a pipeline and see it as a chip", async ({ loggedInPage: page }) => {
|
2026-04-20 15:03:56 +08:00
|
|
|
// Clean up stale E2E pipelines from previous runs to avoid overflow hiding new ones
|
|
|
|
|
const apiUrl = process.env.API_URL || "http://localhost:13490";
|
|
|
|
|
const loginRes = await fetch(`${apiUrl}/api/auth/login`, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify({ username: "admin", password: "admin" }),
|
|
|
|
|
});
|
|
|
|
|
const { token } = await loginRes.json();
|
|
|
|
|
const listRes = await fetch(`${apiUrl}/api/v1/pipeline/list`, {
|
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
|
});
|
|
|
|
|
const { pipelines } = await listRes.json();
|
|
|
|
|
for (const p of pipelines.filter((p: { name: string }) => p.name.startsWith("E2E Pipeline"))) {
|
|
|
|
|
await fetch(`${apiUrl}/api/v1/pipeline/${p.id}`, {
|
|
|
|
|
method: "DELETE",
|
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-03-28 18:34:05 +08:00
|
|
|
await addToolStep(page, "Resize", 1);
|
|
|
|
|
await addToolStep(page, "Compress", 2);
|
2026-03-24 20:37:14 +08:00
|
|
|
|
|
|
|
|
const uniqueName = `E2E Pipeline ${Date.now()}`;
|
2026-04-25 07:23:58 +08:00
|
|
|
await page.getByRole("button", { name: "Save" }).click();
|
2026-03-24 20:37:14 +08:00
|
|
|
await page.getByPlaceholder("Pipeline name").fill(uniqueName);
|
2026-03-25 09:27:12 +08:00
|
|
|
await page.getByRole("button", { name: "Save", exact: true }).click();
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-04-20 10:56:47 +08:00
|
|
|
// The name input should disappear after save completes
|
|
|
|
|
await expect(page.getByPlaceholder("Pipeline name")).not.toBeVisible({
|
2026-03-24 20:37:14 +08:00
|
|
|
timeout: 5_000,
|
|
|
|
|
});
|
2026-04-20 12:27:07 +08:00
|
|
|
// The saved pipeline should appear by name
|
|
|
|
|
await expect(page.getByText(uniqueName).first()).toBeVisible({
|
|
|
|
|
timeout: 5_000,
|
|
|
|
|
});
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-03-28 18:34:05 +08:00
|
|
|
// --- Pipeline Execution ---
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
test("Process button enables when steps and file are set", async ({ loggedInPage: page }) => {
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-03-28 18:34:05 +08:00
|
|
|
await addToolStep(page, "Compress", 1);
|
2026-03-24 20:37:14 +08:00
|
|
|
await uploadTestFile(page);
|
|
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
await expect(page.getByRole("button", { name: "Process", exact: true })).toBeEnabled();
|
2026-03-24 20:37:14 +08:00
|
|
|
});
|
|
|
|
|
|
2026-04-13 16:26:38 +08:00
|
|
|
test("executing pipeline shows before/after result", async ({ loggedInPage: page }) => {
|
2026-06-28 18:57:53 +08:00
|
|
|
// A two-step pipeline can exceed the default 30s test budget on a busy
|
|
|
|
|
// worker pool; give it room.
|
|
|
|
|
test.setTimeout(90_000);
|
2026-03-24 20:37:14 +08:00
|
|
|
await gotoAutomate(page);
|
2026-07-15 21:55:51 +08:00
|
|
|
await addToolStep(page, "Remove Image Metadata", 1);
|
2026-03-28 18:34:05 +08:00
|
|
|
await addToolStep(page, "Compress", 2);
|
2026-06-28 18:57:53 +08:00
|
|
|
// Compress defaults to Target Size mode with an unset (0) size, which is
|
|
|
|
|
// invalid; switch the step to Quality mode so the pipeline has valid
|
|
|
|
|
// settings to run.
|
|
|
|
|
await page.getByRole("button", { name: "Quality", exact: true }).click();
|
2026-03-24 20:37:14 +08:00
|
|
|
await uploadTestFile(page);
|
|
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
await page.getByRole("button", { name: "Process", exact: true }).click();
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-06-28 18:57:53 +08:00
|
|
|
// Wait for the before/after slider to appear (indicates processing
|
|
|
|
|
// completed). A two-step pipeline runs both child jobs plus a finalize, so
|
|
|
|
|
// allow a generous window for a busy worker pool.
|
2026-04-13 16:26:38 +08:00
|
|
|
const slider = page.locator("[aria-label='Before/after comparison slider']");
|
2026-06-28 18:57:53 +08:00
|
|
|
await expect(slider).toBeVisible({ timeout: 60_000 });
|
2026-03-24 20:37:14 +08:00
|
|
|
|
2026-04-13 16:26:38 +08:00
|
|
|
// Should show Original and Processed labels inside the slider
|
|
|
|
|
await expect(page.getByText("Original").first()).toBeVisible();
|
|
|
|
|
await expect(page.getByText("Processed").first()).toBeVisible();
|
2026-03-22 19:28:57 +08:00
|
|
|
});
|
|
|
|
|
});
|