import { request, type Page } from "@playwright/test"; import type { Api } from "./api"; import { uid } from "./factories"; import { siteHeader } from "./site"; export async function createCategory( api: Api, name = `E2E Category ${uid()}`, fields: Record = {} ) { return api.insert("HD Article Category", { category_name: name, ...fields }); } export async function createArticle( api: Api, category: string, fields: Record = {} ) { const title = fields.title || `E2E Article ${uid()}`; return api.insert("HD Article", { title, category, content: `

${title} body

`, status: "Published", // New articles default to Customers. visibility: "Public", ...fields, }); } /** Pick an option in the open dialog's frappe-ui Combobox. */ export async function chooseOption(page: Page, option: string) { await page.getByRole("combobox").last().fill(option); await page.getByRole("option", { name: option }).first().click(); } /** Raw request context for calls the Api client does not cover (uploads, file GETs). */ export async function loginContext(baseURL: string, user: string, password: string) { const context = await request.newContext({ baseURL, extraHTTPHeaders: siteHeader() }); await context.post("/api/method/login", { form: { usr: user, pwd: password } }); return context; } /** * Open the ticket list scoped to one ticket through a private throwaway view. * Typing into the list filters would auto-save them into the persona's shared default view. */ export async function openTicketInList(page: Page, api: Api, user: string, ticket: string) { const view = await api.insert("HD View", { label: `E2E ${uid()}`, user, dt: "HD Ticket", type: "list", route_name: "TicketsAgent", filters: JSON.stringify({ name: ticket }), order_by: "modified desc", }); await page.goto(`/helpdesk/tickets?view=${view.name}`); return view.name; }