Spaces:
Running

WorkPilot-AI / web /e2e /workflows.spec.ts
Aynkhn's picture
Deploy WorkPilot demo (part 2)
0776bd5 verified
Raw History Blame Contribute Delete
4.54 kB
import { expect, test, type Page } from "@playwright/test";
import { login, seed } from "./helpers";
async function dryRunApproveActivate(page: Page, n: number) {
const panel = page.locator(`[data-testid="version-panel"][data-version="${n}"]`);
await expect(panel).toBeVisible();
await panel.getByTestId("dry-run-btn").click();
await expect(page.getByTestId(`version-${n}`)).toHaveAttribute("data-status", "dry_run_ok");
await expect(panel.getByTestId("dry-run-verdict")).toHaveAttribute("data-ok", "true");
await expect(
panel.locator('[data-testid="dry-run-line"][data-tone="execute"]').filter({ hasText: "demo.add_note" }),
).toHaveCount(1);
await panel.getByTestId("approve-btn").click();
await expect(page.getByTestId(`version-${n}`)).toHaveAttribute("data-status", "approved");
await panel.getByTestId("activate-btn").click();
await expect(page.getByTestId(`version-${n}`)).toHaveAttribute("data-status", "active");
await expect(page.getByTestId("active-version")).toContainText(`v${n}`);
}
async function editJson(page: Page, change: (text: string) => string) {
await page.getByRole("tab", { name: "JSON" }).click();
const editor = page.getByTestId("json-editor");
const text = await editor.inputValue();
const updated = change(text);
expect(updated).not.toBe(text);
await editor.fill(updated);
await expect(page.getByTestId("json-error")).toHaveCount(0);
}
test("workflows: natural language -> dry run -> approve -> activate, edit v2, roll back", async ({
page,
request,
}) => {
const s = await seed(request);
await login(page, s, "/workflows");
// Template gallery from the demo pack.
await expect(page.getByTestId("template-card").first()).toContainText("Morning order check");
// Create from natural language (the scripted compiler returns the demo template).
await page.getByLabel("New workflow").fill("Every morning at 8, add a note to ORD-1021 with its status");
await page.getByRole("button", { name: "Create draft" }).click();
await page.waitForURL(/\/workflows\/[0-9a-f-]{36}$/);
await expect(page.getByRole("heading", { name: "Morning order check" })).toBeVisible();
await expect(page.getByTestId("version-1")).toHaveAttribute("data-status", "draft");
// Plain language view of the definition.
await expect(page.getByTestId("plain-plan")).toContainText("On schedule '0 8 * * *' (Asia/Karachi):");
await expect(page.getByTestId("plain-plan")).toContainText("[note] call demo.add_note(");
// Canvas: trigger plus one node per step.
await page.getByRole("tab", { name: "Canvas" }).click();
await expect(page.getByTestId("canvas-trigger")).toBeVisible();
await expect(page.getByTestId("canvas-step-lookup")).toContainText("demo.lookup_order");
await expect(page.getByTestId("canvas-step-note")).toContainText("demo.add_note");
// v1: dry run (reads run live, so the note previews the real status), approve, activate.
const base = 1;
await dryRunApproveActivate(page, base);
const next = base + 1;
// Next version: edit the JSON, which updates the same definition the other views show.
await editJson(page, (t) => t.replace("Morning check", "Daily check"));
await expect(page.getByTestId("unsaved")).toBeVisible();
await page.getByRole("tab", { name: "Plain language" }).click();
await expect(page.getByTestId("plain-plan")).toContainText("note=Daily check");
await page.getByTestId("save-version").click();
await expect(page.getByTestId(`version-${next}`)).toHaveAttribute("data-status", "draft");
await expect(page.locator(`[data-testid="version-panel"][data-version="${next}"]`)).toBeVisible();
await dryRunApproveActivate(page, next);
await expect(page.getByTestId(`version-${base}`)).toHaveAttribute("data-status", "superseded");
// Roll back: the previous version is active again, the newer one is marked rolled back.
await page.getByTestId("rollback-btn").click();
await expect(page.getByTestId("active-version")).toContainText(`v${base}`);
await expect(page.getByTestId(`version-${next}`)).toHaveAttribute("data-status", "rolled_back");
await expect(page.getByTestId(`version-${base}`)).toHaveAttribute("data-status", "active");
// The list shows the active version.
await page.getByRole("link", { name: "Workflows" }).click();
const row = page.getByTestId("workflow-row").filter({ hasText: "Morning order check" });
await expect(row.getByRole("cell").nth(2)).toHaveText(`v${base}`);
});