import { expect, test, type Route } from "@playwright/test"; const FROZEN_NOW = "2026-08-19T15:00:00.000Z"; const TEST_USER = { token: "due-date-floor-e2e-token", expiration: "2030-01-01T00:00:00.000Z", email: "admin@seahavenind.com", userRoles: "Admin", phoneNumber: "5551234567", fullname: "Work Order E2E Admin", id: "1", }; async function fulfillJson(route: Route, body: unknown, status = 200) { await route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) }); } test.describe("Due Date floor in the Create WO wizard (SH-356)", () => { test.setTimeout(60_000); test("disables days before Schedule On and clears Due Date when Schedule On passes it", async ({ page, }) => { await page.clock.install({ time: new Date(FROZEN_NOW) }); await page.clock.resume(); await page.addInitScript((user) => { localStorage.setItem("auth", JSON.stringify(user)); const style = document.createElement("style"); style.textContent = ".tsqd-parent-container { display: none !important; }"; document.documentElement.appendChild(style); }, TEST_USER); await page.route( (url) => url.pathname.startsWith("/api/"), async (route) => { if (route.request().method() !== "GET") { await fulfillJson(route, {}, 500); return; } await fulfillJson(route, { data: [], items: [], weekStart: "2026-08-17", weekEnd: "2026-08-21", counts: { returned: 0, total: 0 }, unscheduled: [], scheduled: [], }); }, ); await page.goto("/workorders"); await page.getByRole("button", { name: "New WO" }).click(); await expect(page.getByRole("heading", { name: "Type & schedule" })).toBeVisible({ timeout: 20_000, }); await page.getByRole("button", { name: /Pick a date/ }).click(); const dateTab = page.getByRole("button", { name: "Date", exact: true }); if (await dateTab.isVisible()) { await dateTab.click(); } await page.getByRole("button", { name: "20", exact: true }).click(); await page.getByRole("button", { name: /No due date/ }).click(); await expect(page.getByRole("button", { name: "19", exact: true })).toBeDisabled(); await expect(page.getByRole("button", { name: "20", exact: true })).toBeEnabled(); await page.getByRole("button", { name: "21", exact: true }).click(); await expect(page.getByRole("button", { name: /No due date/ })).toHaveCount(0); await page.getByRole("button", { name: /Aug 20/ }).click(); const dateTabAgain = page.getByRole("button", { name: "Date", exact: true }); if (await dateTabAgain.isVisible()) { await dateTabAgain.click(); } await page.getByRole("button", { name: "25", exact: true }).click(); await expect(page.getByRole("button", { name: /No due date/ })).toBeVisible(); }); });