test(workorders): seed service registry in browser fixtures

This commit is contained in:
Alexandre Brandizzi 2026-09-30 19:43:06 -03:00
parent 7090f6fb04
commit 5ee2f6f374
2 changed files with 56 additions and 0 deletions

View file

@ -12,6 +12,19 @@ const TEST_USER = {
id: "1",
};
const SERVICE_CATALOG = [
{
id: 1,
name: "HVAC",
trade: "HVAC",
iconKey: "wrench",
requiresCompletionDocument: false,
completionDocTemplate: null,
isActive: true,
supportedWorkOrderTypes: ["PM"],
},
];
async function fulfillJson(route: Route, body: unknown, status = 200) {
await route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
}
@ -39,6 +52,9 @@ async function mockWorkOrderApis(page: Page, searchUrls: string[]) {
if (pathname.includes("/workorders/board") || pathname.includes("DropdownOptions")) {
return route.fallback();
}
if (pathname === "/api/services") {
return fulfillJson(route, { data: SERVICE_CATALOG });
}
return fulfillJson(route, { data: [] });
});
await page.route("**/api/**/DropdownOptions/ByCategory/**", (route) => {
@ -136,6 +152,7 @@ test.describe("Work Orders advanced filters", () => {
await sheet.getByRole("button", { name: /Indicators/i }).click();
await sheet.getByRole("button", { name: /^Add-On$/i }).click();
await sheet.getByRole("button", { name: /^Service/i }).click();
await expect(sheet.getByText("HVAC", { exact: true })).toBeVisible();
await sheet.getByText("HVAC").click();
await sheet.getByRole("button", { name: /Completion doc/i }).click();
await sheet.getByRole("button", { name: /^Pending$/i }).click();

View file

@ -37,6 +37,29 @@ const VENDORS = [
},
];
const SERVICES = [
{
id: 1,
name: "HVAC",
trade: "HVAC",
iconKey: "wrench",
requiresCompletionDocument: false,
completionDocTemplate: null,
isActive: true,
supportedWorkOrderTypes: ["PM"],
},
{
id: 2,
name: "Plumbing",
trade: "Plumbing",
iconKey: "wrench",
requiresCompletionDocument: false,
completionDocTemplate: null,
isActive: true,
supportedWorkOrderTypes: ["PM"],
},
];
const scheduledRow = {
id: 1,
woNumber: "WO-501",
@ -150,6 +173,11 @@ async function mockWorkOrderApi(page: Page, mode: "default" | "empty" | "error"
return;
}
if (pathname === "/api/services") {
await fulfillJson(route, { data: SERVICES });
return;
}
if (pathname.includes("/DropdownOptions/ByCategory/Problem")) {
await fulfillJson(route, {
data: [
@ -192,7 +220,18 @@ async function mockWorkOrderApi(page: Page, mode: "default" | "empty" | "error"
async function openWorkOrderPage(page: Page, mode: "default" | "empty" | "error" = "default") {
await mockWorkOrderApi(page, mode);
const registryResponses = Promise.all([
page.waitForResponse((response) => {
const url = new URL(response.url());
return url.pathname === "/api/services" && url.searchParams.get("isActive") === "true";
}),
page.waitForResponse((response) => {
const url = new URL(response.url());
return url.pathname === "/api/services" && !url.searchParams.has("isActive");
}),
]);
await page.goto("/workorders");
await registryResponses;
await page.evaluate(() => document.fonts.ready);
await page.addStyleTag({
content: `