import { expect, test } from "@playwright/test";
import { reopenTaskDocument } from "./product-journeys/task-document-flow.js";
import type { JourneyContext } from "./product-journeys/types.js";
for (const layout of ["collapsed", "artifacts", "launcher", "classic"] as const) {
test(`document reopen waits for the ${layout} task controls after reload`, async ({ page }) => {
const issue = { title: "Journey QA document navigation" };
let taskLoads = 0;
await page.route("https://document-navigation.test/**", async route => {
if (new URL(route.request().url()).pathname.endsWith("/issues")) {
await route.fulfill({ contentType: "text/html", body: `${issue.title}` });
return;
}
taskLoads++;
await route.fulfill({ contentType: "text/html", body: `` });
});
const context = { page, api: { origin: "https://document-navigation.test" }, company: { issuePrefix: "QA" } } as JourneyContext;
await reopenTaskDocument(context, issue);
await expect(page.locator("#document-qa-note")).toHaveText("Saved revision two");
expect(taskLoads).toBe(2);
});
}
test("document reopen fails when the task has no authoring controls", async ({ page }) => {
await page.route("https://document-navigation.test/**", async route => {
const list = new URL(route.request().url()).pathname.endsWith("/issues");
await route.fulfill({ contentType: "text/html", body: list ? 'Journey QA document navigation' : 'Task without document permissions' });
});
const context = { page, api: { origin: "https://document-navigation.test" }, company: { issuePrefix: "QA" } } as JourneyContext;
await expect(reopenTaskDocument(context, { title: "Journey QA document navigation" })).rejects.toThrow();
await expect(page.getByRole("button", { name: "New document", exact: true })).toHaveCount(0);
});