import { expect, test } from "@playwright/test";
import { newProjectButton } from "./product-journeys/project-context-flow.js";
import { storyArtifactDownloadLink } from "./story-artifact.js";
import { taskProperties } from "./product-journeys/task-properties.js";
import { showPropertyRow } from "./product-journeys/task-panel.js";
import type { JourneyContext, JourneyEvidence, TargetSession } from "./product-journeys/types.js";
const id = "11111111-2222-4333-8444-555555555555";
test("property reads select Properties from an open panel and exclude inactive duplicate rows", async ({ page }) => {
const row = (value: string) => `
Project${value}
`;
await page.setContent(`
`);
const property = await showPropertyRow(page, "Project");
await expect(property.locator("[data-property-value]")).toHaveText("Saved project");
});
test("property reads cannot use an inert row when the panel has no open control", async ({ page }) => {
await page.setContent('');
await expect(showPropertyRow(page, "Project")).rejects.toThrow();
});
test("assignment opens the current side panel again after reload and verifies the saved user", async ({ page }) => {
const origin = "https://assignment-controls.test", title = "Owned assignment task", userId = "owned-user";
let assigned = false;
await page.route(`${origin}/**`, async route => {
const pathname = new URL(route.request().url()).pathname;
if (pathname === "/assign") {
assigned = true;
await route.fulfill({ json: {} });
return;
}
await route.fulfill({ contentType: "text/html", body: pathname === "/QA/issues"
? `${title}`
: `
` });
});
const context = { page, company: { issuePrefix: "QA" }, user: { id: userId }, capabilities: ["company", "board-user", "task-write"],
fixtures: { backlogTask: { id, title, identifier: "QA-201" } }, api: { origin,
get: async (route: string) => route.endsWith("/runs") ? [] : { assigneeUserId: assigned ? userId : null, assigneeAgentId: null, status: "backlog" } },
} as unknown as JourneyContext;
const evidence: JourneyEvidence = { checks: [], outcome: "passed", startingState: "recipe", phases: [], resourceDisposition: "released", privacy: "private" };
await taskProperties(context, {} as TargetSession, "owned-campaign", evidence);
expect(evidence.checks).toEqual([{ id: "assignment-persisted", passed: true }, { id: "no-agent-work", passed: true }]);
await expect(page.getByRole("button", { name: "You", exact: true })).toBeVisible();
});
test("finds the attachment download link in legacy and Artifacts V1 markup only", async ({ page }) => {
const markup = {
legacy: `Download`,
// Artifacts V1: an icon-only "Open raw" link precedes the icon-only download link.
v1: `slugify.zip`
+ ``,
none: `Open`
+ `Download`,
};
for (const kind of ["legacy", "v1"] as const) {
await page.setContent(markup[kind]);
await expect(storyArtifactDownloadLink(page, id)).toHaveAttribute("href", `/api/attachments/${id}/content?download=1`);
}
await page.setContent(markup.none);
await expect(storyArtifactDownloadLink(page, id)).toHaveCount(0);
});
test("opens new-project creation with the previous or current toolbar label only", async ({ page }) => {
for (const label of ["Add Project", "Create project"]) {
await page.setContent(``);
await expect(newProjectButton(page)).toHaveText(label);
}
await page.setContent(``);
await expect(newProjectButton(page)).toHaveCount(0);
});