test: find pending creation in unscheduled results

This commit is contained in:
Alexandre Brandizzi 2026-09-29 12:43:38 -03:00
parent 52b682283c
commit a61ab1919a

View file

@ -23,7 +23,12 @@ async function fulfillJson(route: Route, body: unknown) {
await route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(body) });
}
async function mockApi(page: Page, role: Role, createPayloads: unknown[] = []) {
async function mockApi(
page: Page,
role: Role,
createPayloads: unknown[] = [],
searchUrls: string[] = [],
) {
await page.clock.install({ time: new Date(FROZEN_NOW) });
await page.clock.resume();
await page.addInitScript(
@ -53,7 +58,13 @@ async function mockApi(page: Page, role: Role, createPayloads: unknown[] = []) {
const { pathname } = new URL(request.url());
if (pathname.includes("/workorders/board/search")) {
await fulfillJson(route, { items: [], totalCount: 0, page: 0, pageSize: 50 });
searchUrls.push(request.url());
await fulfillJson(route, {
items: createdRow ? [createdRow] : [],
totalCount: createdRow ? 1 : 0,
page: 0,
pageSize: 50,
});
return;
}
if (pathname === "/api/workorders/board" && request.method() === "GET") {
@ -148,7 +159,8 @@ test.describe("existing work order status menu", () => {
page,
}) => {
const createPayloads: unknown[] = [];
await mockApi(page, "Admin", createPayloads);
const searchUrls: string[] = [];
await mockApi(page, "Admin", createPayloads, searchUrls);
await page.goto("/workorders");
await expect(page.getByRole("heading", { name: "Work Orders" })).toBeVisible({
timeout: 20_000,
@ -178,6 +190,17 @@ test.describe("existing work order status menu", () => {
await expect
.poll(() => createPayloads)
.toEqual([expect.objectContaining({ lifecycleStatus: 2 })]);
const filtersSheet = page.getByRole("dialog", { name: "Advanced Filters" });
await page.getByRole("button", { name: "Advanced Filters" }).click();
await expect(filtersSheet).toBeVisible();
await filtersSheet.getByRole("button", { name: "Date range" }).click();
await filtersSheet.getByRole("button", { name: "Unscheduled", exact: true }).click();
await filtersSheet.getByRole("button", { name: "Apply filters" }).click();
await expect
.poll(() => searchUrls.some((url) => url.includes("unscheduledOnly=true")))
.toBe(true);
const createdRow = page.locator("#wo-row-900");
await expect(createdRow.getByText("WO-900")).toBeVisible();
await expect(createdRow.getByRole("button", { name: "Pending" })).toBeVisible();