mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
Compare commits
26 commits
33a979c79d
...
12d4a0c4b8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12d4a0c4b8 | ||
|
|
c0a20e74ac | ||
|
|
aeb6f7d224 | ||
|
|
3ec6540271 | ||
|
|
d40090a5c0 | ||
|
|
68c4809a16 | ||
|
|
638e33af72 | ||
|
|
04f8b51eab | ||
|
|
dabdc86c69 | ||
|
|
448ba70d87 | ||
|
|
51739fd155 | ||
|
|
dd34e79e19 | ||
|
|
1e15eab573 | ||
|
|
d3b74afe5a | ||
|
|
b746087d0b | ||
|
|
f2df213965 | ||
|
|
49fd0b039c | ||
|
|
2b2b24f2e3 | ||
|
|
1f405bbcaf | ||
|
|
96a066e98f | ||
|
|
49be7ffbc6 | ||
|
|
fdc275ab9a | ||
|
|
b4d2d69abe | ||
|
|
dace388633 | ||
|
|
aa583858ba | ||
|
|
f48342f268 |
25 changed files with 702 additions and 50 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 99 KiB |
80
e2e/work-orders/due-date-schedule-floor.spec.ts
Normal file
80
e2e/work-orders/due-date-schedule-floor.spec.ts
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
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();
|
||||
});
|
||||
});
|
||||
|
|
@ -19,6 +19,10 @@ import type { WizardWOStatus } from "@/domain/work-orders/types/work-order-wizar
|
|||
import { deriveDayFields } from "@/domain/work-orders/utils/table-day-utils";
|
||||
import { toVendorTablePatch } from "@/domain/work-orders/utils/vendor-assignment-patch";
|
||||
import { DocBadge } from "./slide-over-doc-badge";
|
||||
import {
|
||||
clearDueDateBeforeSchedule,
|
||||
resolveDueDateFloor,
|
||||
} from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
type SlideOverInfoTabEditViewProps = {
|
||||
draft: WorkOrderTableRow;
|
||||
|
|
@ -52,6 +56,7 @@ function SlideOverScheduleOnField({
|
|||
schedMode={draft.schedMode}
|
||||
onSave={(scheduledOn) =>
|
||||
onDraftChange({
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, scheduledOn),
|
||||
scheduledOn,
|
||||
scheduleWeekOnly: false,
|
||||
targetWeek: scheduledOn ? "" : draft.targetWeek,
|
||||
|
|
@ -63,6 +68,7 @@ function SlideOverScheduleOnField({
|
|||
}
|
||||
onSaveWeek={(weekStart) =>
|
||||
onDraftChange({
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, weekStart),
|
||||
scheduledOn: "",
|
||||
targetWeek: weekStart,
|
||||
scheduleWeekOnly: true,
|
||||
|
|
@ -74,6 +80,7 @@ function SlideOverScheduleOnField({
|
|||
}
|
||||
onSaveRange={(start, end) =>
|
||||
onDraftChange({
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, start),
|
||||
scheduledOn: start,
|
||||
scheduleEnd: end,
|
||||
schedMode: "range",
|
||||
|
|
@ -175,6 +182,7 @@ export function SlideOverInfoTabEditView({
|
|||
<DueDateCell
|
||||
type={draft.type}
|
||||
value={draft.dueDate}
|
||||
minDate={resolveDueDateFloor(draft)}
|
||||
onSave={(dueDate) => onDraftChange({ dueDate })}
|
||||
/>
|
||||
</SlideOverInfoRow>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ type DateCellProps = {
|
|||
onClear?: () => void;
|
||||
/** Screen-reader-only status appended inside the button so the accessible name keeps the visible date and adds durable state. */
|
||||
srStatusSuffix?: string;
|
||||
/** Earliest selectable day in the date calendar (SH-356). */
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
export function DateCell({
|
||||
|
|
@ -41,6 +43,7 @@ export function DateCell({
|
|||
onSaveRange,
|
||||
onClear,
|
||||
srStatusSuffix,
|
||||
minDate,
|
||||
}: DateCellProps) {
|
||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||
const open = Boolean(anchorEl);
|
||||
|
|
@ -154,6 +157,7 @@ export function DateCell({
|
|||
) : (
|
||||
<MiniCalendar
|
||||
value={value}
|
||||
minDate={minDate}
|
||||
onChange={(d) => {
|
||||
onSave(d);
|
||||
setAnchorEl(null);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ type DueDateCalendarDialogProps = {
|
|||
onOpenChange: (open: boolean) => void;
|
||||
value: string;
|
||||
onSave: (iso: string) => void;
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -19,6 +20,7 @@ export function DueDateCalendarDialog({
|
|||
onOpenChange,
|
||||
value,
|
||||
onSave,
|
||||
minDate,
|
||||
}: DueDateCalendarDialogProps) {
|
||||
return (
|
||||
<Dialog
|
||||
|
|
@ -44,6 +46,7 @@ export function DueDateCalendarDialog({
|
|||
<div className="flex justify-center">
|
||||
<MiniCalendar
|
||||
value={value}
|
||||
minDate={minDate}
|
||||
onChange={(iso) => {
|
||||
onSave(iso);
|
||||
onOpenChange(false);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ type DueDateCellProps = {
|
|||
* read by colour alone.
|
||||
*/
|
||||
pastDue?: boolean;
|
||||
/** Schedule On floor: earlier days are not selectable (SH-356). */
|
||||
minDate?: string;
|
||||
onSave: (date: string) => void;
|
||||
};
|
||||
|
||||
|
|
@ -29,6 +31,7 @@ export function DueDateCell({
|
|||
q,
|
||||
highlight,
|
||||
pastDue = false,
|
||||
minDate,
|
||||
onSave,
|
||||
}: DueDateCellProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
|
@ -40,6 +43,7 @@ export function DueDateCell({
|
|||
q={q}
|
||||
highlight={highlight}
|
||||
onSave={onSave}
|
||||
minDate={minDate}
|
||||
srStatusSuffix={pastDue ? "Past due" : undefined}
|
||||
/>
|
||||
);
|
||||
|
|
@ -87,7 +91,13 @@ export function DueDateCell({
|
|||
style={{ color: "var(--muted-foreground)" }}
|
||||
/>
|
||||
</button>
|
||||
<DueDateCalendarDialog open={open} onOpenChange={setOpen} value={value} onSave={onSave} />
|
||||
<DueDateCalendarDialog
|
||||
minDate={minDate}
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
value={value}
|
||||
onSave={onSave}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { shouldNotifyCrossWeek } from "@/domain/work-orders/utils/should-notify-
|
|||
import type { ReturnTypeOfUseWorkOrdersTableData } from "./wo-table-types";
|
||||
import { rescheduleNotify, weekMoveNotify } from "./reschedule-notify";
|
||||
import type { WoTableRowHandlers } from "./wo-table-row";
|
||||
import { clearDueDateBeforeSchedule } from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
function revealOrNotifyScheduledDay(args: {
|
||||
id: string | number;
|
||||
|
|
@ -31,6 +32,35 @@ function revealOrNotifyScheduledDay(args: {
|
|||
revealScheduledRow(id);
|
||||
}
|
||||
|
||||
type DragHandlersArgs = Pick<
|
||||
ReturnTypeOfUseWorkOrdersTableData,
|
||||
"dragState" | "setDragViz" | "reorderRows" | "endDrag"
|
||||
>;
|
||||
|
||||
function createDragHandlers({ dragState, setDragViz, reorderRows, endDrag }: DragHandlersArgs) {
|
||||
return {
|
||||
onDragStart: (id: string | number) => {
|
||||
dragState.current = { dragId: id, overId: null };
|
||||
setDragViz({ dragId: id, overId: null });
|
||||
},
|
||||
onDragOver: (id: string | number) => {
|
||||
const did = dragState.current.dragId;
|
||||
if (did && did !== id && dragState.current.overId !== id) {
|
||||
dragState.current.overId = id;
|
||||
setDragViz((v) => ({ ...v, overId: id }));
|
||||
}
|
||||
},
|
||||
onDrop: () => {
|
||||
const { dragId, overId } = dragState.current;
|
||||
if (dragId && overId) {
|
||||
reorderRows(dragId, overId);
|
||||
}
|
||||
endDrag();
|
||||
},
|
||||
onDragEnd: endDrag,
|
||||
};
|
||||
}
|
||||
|
||||
type UseWoTableRowHandlersOptions = {
|
||||
tableData: ReturnTypeOfUseWorkOrdersTableData;
|
||||
weekMonday: string;
|
||||
|
|
@ -101,8 +131,11 @@ export function useWoTableRowHandlers({
|
|||
onPatch: (id, patch, options) => {
|
||||
onPatch(id, patch, options);
|
||||
},
|
||||
onScheduleDate: (id: string | number, date: string) => {
|
||||
onPatch(id, applySchedulePatch(date, false));
|
||||
onScheduleDate: (id: string | number, date: string, dueDate?: string) => {
|
||||
onPatch(id, {
|
||||
...applySchedulePatch(date, false),
|
||||
...clearDueDateBeforeSchedule(dueDate, date),
|
||||
});
|
||||
revealOrNotifyScheduledDay({
|
||||
id,
|
||||
date,
|
||||
|
|
@ -111,8 +144,11 @@ export function useWoTableRowHandlers({
|
|||
revealScheduledRow,
|
||||
});
|
||||
},
|
||||
onScheduleRange: (id: string | number, start: string, end: string) => {
|
||||
onPatch(id, applyScheduleRangePatch(start, end));
|
||||
onScheduleRange: (id: string | number, start: string, end: string, dueDate?: string) => {
|
||||
onPatch(id, {
|
||||
...applyScheduleRangePatch(start, end),
|
||||
...clearDueDateBeforeSchedule(dueDate, start),
|
||||
});
|
||||
revealOrNotifyScheduledDay({
|
||||
id,
|
||||
date: start,
|
||||
|
|
@ -121,7 +157,7 @@ export function useWoTableRowHandlers({
|
|||
revealScheduledRow,
|
||||
});
|
||||
},
|
||||
onScheduleWeek: (id: string | number, week: string) => {
|
||||
onScheduleWeek: (id: string | number, week: string, dueDate?: string) => {
|
||||
const isClear = week === "";
|
||||
onPatch(
|
||||
id,
|
||||
|
|
@ -135,6 +171,7 @@ export function useWoTableRowHandlers({
|
|||
schedMode: "week",
|
||||
dayGroup: "",
|
||||
dayLabel: "",
|
||||
...clearDueDateBeforeSchedule(dueDate, week),
|
||||
},
|
||||
);
|
||||
weekMoveNotify(week, {
|
||||
|
|
@ -153,25 +190,12 @@ export function useWoTableRowHandlers({
|
|||
onRequestComplete,
|
||||
onPastDueAttempt: (id: string | number) => onScheduleHighlight(id),
|
||||
onReorder: reorderRows,
|
||||
onDragStart: (id: string | number) => {
|
||||
dragStateRef.current = { dragId: id, overId: null };
|
||||
setDragViz({ dragId: id, overId: null });
|
||||
},
|
||||
onDragOver: (id: string | number) => {
|
||||
const did = dragStateRef.current.dragId;
|
||||
if (did && did !== id && dragStateRef.current.overId !== id) {
|
||||
dragStateRef.current.overId = id;
|
||||
setDragViz((v) => ({ ...v, overId: id }));
|
||||
}
|
||||
},
|
||||
onDrop: () => {
|
||||
const { dragId, overId } = dragStateRef.current;
|
||||
if (dragId && overId) {
|
||||
reorderRows(dragId, overId);
|
||||
}
|
||||
endDrag();
|
||||
},
|
||||
onDragEnd: endDrag,
|
||||
...createDragHandlers({
|
||||
dragState: dragStateRef,
|
||||
setDragViz,
|
||||
reorderRows,
|
||||
endDrag,
|
||||
}),
|
||||
}),
|
||||
[
|
||||
tableData,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ import { toVendorTablePatch } from "@/domain/work-orders/utils/vendor-assignment
|
|||
import { InlineCreateField } from "./inline-create-field";
|
||||
import { toInlineDraftRow } from "./to-inline-draft-row";
|
||||
import { WoTableInlineIdentityCells } from "./wo-table-inline-identity-cells";
|
||||
import {
|
||||
clearDueDateBeforeSchedule,
|
||||
resolveDueDateFloor,
|
||||
} from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
type WoTableInlineRowCellsProps = {
|
||||
draft: WorkOrderTableDraft;
|
||||
|
|
@ -106,6 +110,7 @@ function InlineScheduleOnCell({
|
|||
onSave={(date) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, date),
|
||||
scheduledOn: date,
|
||||
scheduleWeekOnly: false,
|
||||
targetWeek: "",
|
||||
|
|
@ -118,6 +123,7 @@ function InlineScheduleOnCell({
|
|||
onSaveWeek={(week) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, week),
|
||||
scheduledOn: "",
|
||||
targetWeek: week,
|
||||
scheduleWeekOnly: true,
|
||||
|
|
@ -130,6 +136,7 @@ function InlineScheduleOnCell({
|
|||
onSaveRange={(start, end) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, start),
|
||||
scheduledOn: start,
|
||||
scheduleEnd: end,
|
||||
schedMode: "range",
|
||||
|
|
@ -212,6 +219,7 @@ export function WoTableInlineRowCells({
|
|||
<DueDateCell
|
||||
type={draft.type}
|
||||
value={draft.dueDate}
|
||||
minDate={resolveDueDateFloor(draft)}
|
||||
onSave={(date) => onPatch({ dueDate: date })}
|
||||
/>
|
||||
</InlineFieldCell>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { EditableWONumberCell } from "./cells/editable-wo-number-cell";
|
|||
import { SiteCell } from "./cells/site-cell";
|
||||
import { TypeCell } from "./cells/type-cell";
|
||||
import type { WoTableRowHandlers } from "./wo-table-row";
|
||||
import { resolveDueDateFloor } from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
type WoTableRowCellsProps = {
|
||||
row: WorkOrderTableRow;
|
||||
|
|
@ -146,9 +147,9 @@ export function WoTableRowCells({
|
|||
targetWeek={row.targetWeek}
|
||||
scheduleEnd={row.scheduleEnd}
|
||||
schedMode={row.schedMode}
|
||||
onSave={(date) => handlers.onScheduleDate(row.id, date)}
|
||||
onSaveWeek={(week) => handlers.onScheduleWeek(row.id, week)}
|
||||
onSaveRange={(start, end) => handlers.onScheduleRange(row.id, start, end)}
|
||||
onSave={(date) => handlers.onScheduleDate(row.id, date, row.dueDate)}
|
||||
onSaveWeek={(week) => handlers.onScheduleWeek(row.id, week, row.dueDate)}
|
||||
onSaveRange={(start, end) => handlers.onScheduleRange(row.id, start, end, row.dueDate)}
|
||||
onClear={hasSchedule && !viewOnly ? () => handlers.onScheduleWeek(row.id, "") : undefined}
|
||||
/>
|
||||
</td>
|
||||
|
|
@ -163,6 +164,7 @@ export function WoTableRowCells({
|
|||
q={search}
|
||||
highlight={forceDueDateHighlight || row.isPastDue}
|
||||
pastDue={row.isPastDue}
|
||||
minDate={resolveDueDateFloor(row)}
|
||||
onSave={(date) => onPatchRow({ dueDate: date })}
|
||||
/>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -36,9 +36,10 @@ export type WoTableRowHandlers = {
|
|||
patch: Partial<WorkOrderTableRow>,
|
||||
options?: WorkOrderTablePatchOptions,
|
||||
) => void;
|
||||
onScheduleDate: (id: string | number, date: string) => void;
|
||||
onScheduleWeek: (id: string | number, week: string) => void;
|
||||
onScheduleRange: (id: string | number, start: string, end: string) => void;
|
||||
/** `dueDate` is the row's current Due Date, cleared when the new schedule passes it (SH-356). */
|
||||
onScheduleDate: (id: string | number, date: string, dueDate?: string) => void;
|
||||
onScheduleWeek: (id: string | number, week: string, dueDate?: string) => void;
|
||||
onScheduleRange: (id: string | number, start: string, end: string, dueDate?: string) => void;
|
||||
onDuplicateFound?: (existing: WorkOrderTableRow) => void;
|
||||
onOpenSlideOver: (row: WorkOrderTableRow) => void;
|
||||
onRequestComplete?: (row: WorkOrderTableRow) => void;
|
||||
|
|
@ -77,17 +78,17 @@ function guardScheduleHandlers(
|
|||
if (!canApplyWorkOrderTablePatch(row.status, patch)) return;
|
||||
handlers.onPatch(id, patch, options);
|
||||
},
|
||||
onScheduleDate: (id, date) => {
|
||||
onScheduleDate: (id, date, dueDate) => {
|
||||
if (!canApplyWorkOrderTablePatch(row.status, { scheduledOn: date })) return;
|
||||
handlers.onScheduleDate(id, date);
|
||||
handlers.onScheduleDate(id, date, dueDate);
|
||||
},
|
||||
onScheduleWeek: (id, week) => {
|
||||
onScheduleWeek: (id, week, dueDate) => {
|
||||
if (!canApplyWorkOrderTablePatch(row.status, { targetWeek: week })) return;
|
||||
handlers.onScheduleWeek(id, week);
|
||||
handlers.onScheduleWeek(id, week, dueDate);
|
||||
},
|
||||
onScheduleRange: (id, start, end) => {
|
||||
onScheduleRange: (id, start, end, dueDate) => {
|
||||
if (!canApplyWorkOrderTablePatch(row.status, { scheduledOn: start })) return;
|
||||
handlers.onScheduleRange(id, start, end);
|
||||
handlers.onScheduleRange(id, start, end, dueDate);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,31 +5,49 @@ import { ToolbarButton } from "@/components/ui/toolbar-button";
|
|||
|
||||
type WorkOrdersListHeaderProps = {
|
||||
search: string;
|
||||
/** Compact label of the active board week (e.g. "5/4–5/8"). */
|
||||
weekLabel: string;
|
||||
onSearchChange: (value: string) => void;
|
||||
/** Omit until Advanced Search slice mounts the sheet. */
|
||||
onOpenAdvancedFilters?: () => void;
|
||||
/** Omit until wizard shell slice mounts New WO. */
|
||||
onNewWorkOrder?: () => void;
|
||||
activeFilterCount: number;
|
||||
/** True while Advanced Filters are applied; results are global and the keyword box is inert. */
|
||||
advancedFiltersActive?: boolean;
|
||||
isFetching?: boolean;
|
||||
};
|
||||
|
||||
export function WorkOrdersListHeader({
|
||||
search,
|
||||
weekLabel,
|
||||
onSearchChange,
|
||||
onOpenAdvancedFilters,
|
||||
onNewWorkOrder,
|
||||
activeFilterCount,
|
||||
advancedFiltersActive = false,
|
||||
isFetching = false,
|
||||
}: WorkOrdersListHeaderProps) {
|
||||
return (
|
||||
<>
|
||||
<SearchInput
|
||||
value={search}
|
||||
onChange={onSearchChange}
|
||||
placeholder="Search this week…"
|
||||
aria-label="Search work orders"
|
||||
/>
|
||||
<div className="relative">
|
||||
<SearchInput
|
||||
value={search}
|
||||
onChange={onSearchChange}
|
||||
placeholder="Search this week…"
|
||||
aria-label="Search work orders"
|
||||
/>
|
||||
{/* Keyword search is scoped to the active week; make that scope visible. */}
|
||||
{!advancedFiltersActive && search.trim() !== "" && Boolean(weekLabel) && (
|
||||
<span
|
||||
role="status"
|
||||
className="absolute left-0 whitespace-nowrap text-(length:--text-xs) text-muted-foreground"
|
||||
style={{ top: "calc(100% + 4px)" }}
|
||||
>
|
||||
Searching within {weekLabel}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{Boolean(onOpenAdvancedFilters) && (
|
||||
<ToolbarButton
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ type MiniCalendarProps = {
|
|||
range?: boolean;
|
||||
rangeStart?: string;
|
||||
rangeEnd?: string;
|
||||
/** Days before this ISO date are disabled (SH-356 Due Date floor). */
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
export function MiniCalendar({
|
||||
|
|
@ -20,9 +22,11 @@ export function MiniCalendar({
|
|||
range,
|
||||
rangeStart = "",
|
||||
rangeEnd = "",
|
||||
minDate = "",
|
||||
}: MiniCalendarProps) {
|
||||
const initRaw = range ? rangeStart || value : value;
|
||||
const init = /^\d{4}-\d{2}-\d{2}$/.test(initRaw) ? initRaw : todayIso();
|
||||
const fallback = minDate > todayIso() ? minDate : todayIso();
|
||||
const init = /^\d{4}-\d{2}-\d{2}$/.test(initRaw) ? initRaw : fallback;
|
||||
const [iy, im] = init.split("-").map(Number);
|
||||
const [viewY, setViewY] = useState(iy);
|
||||
const [viewM, setViewM] = useState(im);
|
||||
|
|
@ -94,6 +98,7 @@ export function MiniCalendar({
|
|||
}
|
||||
const iso = `${viewY}-${pad2(viewM)}-${pad2(day)}`;
|
||||
const isToday = iso === today;
|
||||
const beforeMin = Boolean(minDate) && iso < minDate;
|
||||
const { bg, fg, radius, filled } = getMiniCalendarCellStyle({
|
||||
iso,
|
||||
value,
|
||||
|
|
@ -107,8 +112,9 @@ export function MiniCalendar({
|
|||
<button
|
||||
key={i}
|
||||
type="button"
|
||||
disabled={beforeMin}
|
||||
onClick={() => onChange(iso)}
|
||||
className="text-center text-[12px] transition-colors hover:bg-[var(--color-primary-tint)]"
|
||||
className="text-center text-[12px] transition-colors hover:bg-[var(--color-primary-tint)] disabled:cursor-not-allowed disabled:bg-transparent disabled:opacity-40"
|
||||
style={{
|
||||
height: 26,
|
||||
borderRadius: radius,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ type WizardDateFieldProps = {
|
|||
scheduleEnd?: string;
|
||||
schedMode?: WizardSchedMode;
|
||||
onChangeRange?: (start: string, end: string) => void;
|
||||
/** Earliest selectable day in the date calendar (SH-356). */
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
function fieldLabel(args: {
|
||||
|
|
@ -49,6 +51,7 @@ export function WizardDateField({
|
|||
scheduleEnd = "",
|
||||
schedMode,
|
||||
onChangeRange,
|
||||
minDate,
|
||||
}: WizardDateFieldProps) {
|
||||
const { anchorEl, open, setAnchor, close } = useMenuAnchor();
|
||||
const allowRange = Boolean(allowWeekMode && onChangeRange);
|
||||
|
|
@ -127,6 +130,7 @@ export function WizardDateField({
|
|||
) : (
|
||||
<MiniCalendar
|
||||
value={value}
|
||||
minDate={minDate}
|
||||
onChange={(iso) => {
|
||||
onChange(iso);
|
||||
close();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ type WizardDueDateFieldProps = {
|
|||
value: string;
|
||||
placeholder: string;
|
||||
onChange: (iso: string) => void;
|
||||
/** Schedule On floor: earlier days are not selectable (SH-356). */
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -21,11 +23,19 @@ export function WizardDueDateField({
|
|||
value,
|
||||
placeholder,
|
||||
onChange,
|
||||
minDate,
|
||||
}: WizardDueDateFieldProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
if (type !== "Emergency") {
|
||||
return <WizardDateField value={value} placeholder={placeholder} onChange={onChange} />;
|
||||
return (
|
||||
<WizardDateField
|
||||
value={value}
|
||||
placeholder={placeholder}
|
||||
onChange={onChange}
|
||||
minDate={minDate}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -63,7 +73,13 @@ export function WizardDueDateField({
|
|||
</span>
|
||||
<ChevronDown size={13} className="shrink-0" style={{ color: "var(--muted-foreground)" }} />
|
||||
</button>
|
||||
<DueDateCalendarDialog open={open} onOpenChange={setOpen} value={value} onSave={onChange} />
|
||||
<DueDateCalendarDialog
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
value={value}
|
||||
onSave={onChange}
|
||||
minDate={minDate}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ import {
|
|||
import { WizardSeverityPicker } from "@/app/(protected)/workorders/_components/wizard/wizard-severity-picker";
|
||||
import { CheckCircle2, Clock, Flame, Users, Wrench, Zap } from "lucide-react";
|
||||
import type { ElementType } from "react";
|
||||
import {
|
||||
clearDueDateBeforeSchedule,
|
||||
resolveDueDateFloor,
|
||||
} from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
const WO_TYPE_ICONS: Record<WOType, ElementType> = {
|
||||
PM: Wrench,
|
||||
|
|
@ -165,6 +169,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
|||
onChange={(iso) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, iso),
|
||||
scheduledOn: iso,
|
||||
scheduleWeekOnly: false,
|
||||
scheduleEnd: "",
|
||||
|
|
@ -177,6 +182,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
|||
onChangeWeek={(w) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, w),
|
||||
scheduledOn: w,
|
||||
scheduleWeekOnly: Boolean(w),
|
||||
scheduleEnd: "",
|
||||
|
|
@ -189,6 +195,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
|||
onChangeRange={(s, e) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, s),
|
||||
scheduledOn: s,
|
||||
scheduleEnd: e,
|
||||
schedMode: "range",
|
||||
|
|
@ -211,6 +218,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
|||
<WizardDueDateField
|
||||
type={draft.type}
|
||||
value={draft.dueDate}
|
||||
minDate={resolveDueDateFloor(draft)}
|
||||
placeholder="No due date"
|
||||
onChange={(iso) => onUpdate("dueDate", iso)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ export function useWorkOrdersBoardSource(filters: FiltersReturn): WorkOrdersBoar
|
|||
() =>
|
||||
buildResolvedBoardSearchParams({
|
||||
advApplied: filters.advApplied,
|
||||
search: filters.search,
|
||||
// Advanced Filters are global by design; the week-scoped keyword box has no effect.
|
||||
search: "",
|
||||
page: filters.page,
|
||||
pageSize: filters.pageSize,
|
||||
sortBy: filters.sortBy,
|
||||
|
|
@ -43,7 +44,6 @@ export function useWorkOrdersBoardSource(filters: FiltersReturn): WorkOrdersBoar
|
|||
}),
|
||||
[
|
||||
filters.advApplied,
|
||||
filters.search,
|
||||
filters.page,
|
||||
filters.pageSize,
|
||||
filters.sortBy,
|
||||
|
|
|
|||
|
|
@ -43,10 +43,12 @@ export default function WorkOrdersListPage() {
|
|||
actions={
|
||||
<WorkOrdersListHeader
|
||||
search={filters.search}
|
||||
weekLabel={filters.weekLabel}
|
||||
onSearchChange={filters.handleSearchChange}
|
||||
onOpenAdvancedFilters={() => filters.setAdvOpen(true)}
|
||||
onNewWorkOrder={() => page.setWizardOpen(true)}
|
||||
activeFilterCount={filters.activeFilterCount}
|
||||
advancedFiltersActive={filters.advApplied != null}
|
||||
isFetching={tableData.isFetching && !tableData.isLoading}
|
||||
/>
|
||||
}
|
||||
|
|
|
|||
27
src/domain/work-orders/utils/due-date-floor.ts
Normal file
27
src/domain/work-orders/utils/due-date-floor.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* SH-356: a Due Date can never be earlier than Schedule On.
|
||||
*
|
||||
* The floor is the concrete Schedule On day, the start of a date range, or — for a
|
||||
* week-only schedule (SH-110) — the first day of the target week.
|
||||
*/
|
||||
export function resolveDueDateFloor(schedule: {
|
||||
scheduledOn?: string | null;
|
||||
targetWeek?: string | null;
|
||||
}): string {
|
||||
return schedule.scheduledOn?.trim() || schedule.targetWeek?.trim() || "";
|
||||
}
|
||||
|
||||
export function isDueDateBeforeFloor(dueDate: string | null | undefined, floor: string): boolean {
|
||||
return Boolean(dueDate && floor && dueDate < floor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch fragment for a Schedule On change: clears an existing Due Date that the new
|
||||
* schedule would leave in the past. Never bumps it to a guessed value.
|
||||
*/
|
||||
export function clearDueDateBeforeSchedule(
|
||||
dueDate: string | null | undefined,
|
||||
nextFloor: string,
|
||||
): { dueDate?: string } {
|
||||
return isDueDateBeforeFloor(dueDate, nextFloor) ? { dueDate: "" } : {};
|
||||
}
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
import { fireEvent, render, renderHook, screen, within } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { SlideOverInfoTabEditView } from "@/app/(protected)/workorders/_components/detail/tabs/slide-over-info-tab-edit-view";
|
||||
import { WoTableInlineRow } from "@/app/(protected)/workorders/_components/list/table/wo-table-inline-row";
|
||||
import { useWoTableRowHandlers } from "@/app/(protected)/workorders/_components/list/table/use-wo-table-row-handlers";
|
||||
import { MiniCalendar } from "@/app/(protected)/workorders/_components/wizard/mini-calendar";
|
||||
import { WizardStepTypeSchedule } from "@/app/(protected)/workorders/_components/wizard/wizard-step-type-schedule";
|
||||
import { EMPTY_TABLE_DRAFT } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import { EMPTY_WIZARD_DRAFT } from "@/domain/work-orders/types/work-order-wizard";
|
||||
import { pad2, todayIso } from "@/domain/work-orders/utils/wizard-date-utils";
|
||||
import { renderWithProviders } from "@/test/test-utils";
|
||||
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/site-cell", () => ({
|
||||
SiteCell: () => null,
|
||||
}));
|
||||
vi.mock(
|
||||
"@/app/(protected)/workorders/_components/list/table/cells/editable-wo-number-cell",
|
||||
() => ({ EditableWONumberCell: () => null }),
|
||||
);
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/type-cell", () => ({
|
||||
TypeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/assigned-to-cell", () => ({
|
||||
AssignedToCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/appt-time-cell", () => ({
|
||||
ApptTimeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/pm-type-cell", () => ({
|
||||
PMTypeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/vendor-cell", () => ({
|
||||
VendorCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/status-cell", () => ({
|
||||
StatusCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/reschedule-notify", () => ({
|
||||
rescheduleNotify: vi.fn(),
|
||||
weekMoveNotify: vi.fn(),
|
||||
}));
|
||||
|
||||
function day(n: number): string {
|
||||
const [y, m] = todayIso().split("-").map(Number);
|
||||
return `${y}-${pad2(m)}-${pad2(n)}`;
|
||||
}
|
||||
|
||||
function rowByLabel(label: string) {
|
||||
return screen.getByText(label, { selector: "span,label,div" }).closest("div")!;
|
||||
}
|
||||
|
||||
describe("Due Date cannot be before Schedule On (SH-356)", () => {
|
||||
it("disables calendar days before the floor", () => {
|
||||
render(<MiniCalendar value={day(12)} minDate={day(10)} onChange={vi.fn()} />);
|
||||
|
||||
expect(screen.getByRole("button", { name: "9" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "10" })).toBeEnabled();
|
||||
expect(screen.getByRole("button", { name: "11" })).toBeEnabled();
|
||||
});
|
||||
|
||||
describe("slide-over edit", () => {
|
||||
const draft = { scheduledOn: day(10), dueDate: day(12) } as Partial<WorkOrderTableRow>;
|
||||
|
||||
function renderSlideOver(onDraftChange = vi.fn()) {
|
||||
renderWithProviders(
|
||||
<SlideOverInfoTabEditView
|
||||
draft={{ ...EMPTY_TABLE_DRAFT, id: 42, targetWeek: "", ...draft } as WorkOrderTableRow}
|
||||
users={[]}
|
||||
sites={[]}
|
||||
vendors={[]}
|
||||
pmTypes={[]}
|
||||
allOrders={[]}
|
||||
onDraftChange={onDraftChange}
|
||||
/>,
|
||||
);
|
||||
return onDraftChange;
|
||||
}
|
||||
|
||||
it("disables Due Date days before Schedule On", async () => {
|
||||
renderSlideOver();
|
||||
fireEvent.click(within(rowByLabel("Due Date")).getByRole("button"));
|
||||
|
||||
expect(await screen.findByRole("button", { name: "9" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "10" })).toBeEnabled();
|
||||
});
|
||||
|
||||
it("clears the Due Date when Schedule On moves past it", async () => {
|
||||
const onDraftChange = renderSlideOver();
|
||||
fireEvent.click(within(rowByLabel("Schedule On")).getAllByRole("button")[0]);
|
||||
fireEvent.click(await screen.findByRole("button", { name: "15" }));
|
||||
|
||||
expect(onDraftChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ scheduledOn: day(15), dueDate: "" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("wizard: clears Due Date on a later Schedule On and floors the Due Date picker", async () => {
|
||||
const onPatch = vi.fn();
|
||||
render(
|
||||
<WizardStepTypeSchedule
|
||||
draft={{ ...EMPTY_WIZARD_DRAFT, scheduledOn: day(10), schedMode: "date", dueDate: day(12) }}
|
||||
users={[]}
|
||||
onUpdate={vi.fn()}
|
||||
onPatch={onPatch}
|
||||
/>,
|
||||
);
|
||||
|
||||
const dueDateButtons = within(rowByLabel("Due Date").parentElement!).getAllByRole("button");
|
||||
fireEvent.click(dueDateButtons[dueDateButtons.length - 1]);
|
||||
expect(await screen.findByRole("button", { name: "9" })).toBeDisabled();
|
||||
fireEvent.keyDown(document.activeElement ?? document.body, { key: "Escape" });
|
||||
|
||||
const scheduleBlock = rowByLabel("Schedule On").parentElement!;
|
||||
const scheduleButtons = within(scheduleBlock).getAllByRole("button");
|
||||
fireEvent.click(scheduleButtons[scheduleButtons.length - 1]);
|
||||
const calendars = await screen.findAllByRole("button", { name: "15" });
|
||||
fireEvent.click(calendars[calendars.length - 1]);
|
||||
|
||||
expect(onPatch).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ scheduledOn: day(15), dueDate: "" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("inline creation row: clears Due Date on a later Schedule On", async () => {
|
||||
const onChange = vi.fn();
|
||||
renderWithProviders(
|
||||
<table>
|
||||
<tbody>
|
||||
<WoTableInlineRow
|
||||
draft={{ ...EMPTY_TABLE_DRAFT, scheduledOn: day(10), dueDate: day(12) }}
|
||||
draftDayKey={day(10)}
|
||||
users={[]}
|
||||
sites={[]}
|
||||
vendors={[]}
|
||||
pmTypes={[]}
|
||||
allRows={[]}
|
||||
onChange={onChange}
|
||||
onSave={vi.fn()}
|
||||
onCancel={vi.fn()}
|
||||
/>
|
||||
</tbody>
|
||||
</table>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
const cells = screen.getAllByRole("cell");
|
||||
const dateButtons = cells.flatMap((cell) => within(cell).queryAllByRole("button"));
|
||||
const scheduleButton = dateButtons.find(
|
||||
(b) => b.textContent?.includes(day(10).slice(5).replace("-", "/")) ?? false,
|
||||
);
|
||||
fireEvent.click(scheduleButton ?? dateButtons[0]);
|
||||
fireEvent.click(await screen.findByRole("button", { name: "15" }));
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ scheduledOn: day(15), dueDate: "" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("board row: sends the Due Date clear in the same schedule patch", () => {
|
||||
const onPatch = vi.fn();
|
||||
const { result } = renderHook(() =>
|
||||
useWoTableRowHandlers({
|
||||
tableData: {
|
||||
dragState: { current: { dragId: null, overId: null } },
|
||||
setDragViz: vi.fn(),
|
||||
reorderRows: vi.fn(),
|
||||
endDrag: vi.fn(),
|
||||
revealScheduledRow: vi.fn(),
|
||||
setSelectedId: vi.fn(),
|
||||
} as never,
|
||||
weekMonday: "2026-05-18",
|
||||
onNavigateToDay: vi.fn(),
|
||||
onOpenSlideOver: vi.fn(),
|
||||
onOpenMedia: vi.fn(),
|
||||
onPatch,
|
||||
onScheduleHighlight: vi.fn(),
|
||||
}),
|
||||
);
|
||||
|
||||
result.current.onScheduleDate("wo-1", "2026-05-21", "2026-05-20");
|
||||
expect(onPatch).toHaveBeenLastCalledWith("wo-1", expect.objectContaining({ dueDate: "" }));
|
||||
|
||||
result.current.onScheduleRange("wo-1", "2026-05-19", "2026-05-22", "2026-05-20");
|
||||
expect(onPatch.mock.lastCall?.[1]).not.toHaveProperty("dueDate");
|
||||
|
||||
result.current.onScheduleWeek("wo-1", "2026-05-25", "2026-05-20");
|
||||
expect(onPatch).toHaveBeenLastCalledWith(
|
||||
"wo-1",
|
||||
expect.objectContaining({ targetWeek: "2026-05-25", dueDate: "" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -42,6 +42,16 @@ describe("saveExistingRowType", () => {
|
|||
expect(onPatch.mock.calls[0]![2]).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not warn when moving between SEV 3–5", () => {
|
||||
const onPatch = vi.fn();
|
||||
|
||||
saveExistingRowType(onPatch, { ...row, severity: 5 }, "Reactive", 3);
|
||||
|
||||
expect(toastWarn).not.toHaveBeenCalled();
|
||||
expect(onPatch).toHaveBeenCalledWith(7, { type: "Reactive", severity: 3 });
|
||||
expect(onPatch.mock.calls[0]![2]).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not warn when clearing severity on a PM correction", () => {
|
||||
const onPatch = vi.fn();
|
||||
|
||||
|
|
|
|||
47
src/test/app/(protected)/workorders/severity-badge.test.tsx
Normal file
47
src/test/app/(protected)/workorders/severity-badge.test.tsx
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { SeverityBadge } from "@/app/(protected)/workorders/_components/list/table/cells/severity-badge";
|
||||
|
||||
describe("SeverityBadge", () => {
|
||||
it("shows description, Accept/Respond deadline, and after-hours on hover", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<SeverityBadge severity={1} />);
|
||||
|
||||
await user.hover(screen.getByText("SEV 1"));
|
||||
|
||||
const tooltip = await screen.findByRole("tooltip");
|
||||
expect(tooltip).toHaveTextContent(
|
||||
"Business Critical Function Down · Accept: 15 min · Respond: 2 hrs · After hours: Yes",
|
||||
);
|
||||
expect(tooltip).not.toHaveTextContent(/Quote|Tech Notes|Invoice|Turnaround/i);
|
||||
|
||||
await user.unhover(screen.getByText("SEV 1"));
|
||||
await waitFor(() => expect(screen.queryByRole("tooltip")).not.toBeInTheDocument());
|
||||
});
|
||||
|
||||
it("transcribes the SEV table row for the given severity", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<SeverityBadge severity={3} />);
|
||||
|
||||
await user.hover(screen.getByText("SEV 3"));
|
||||
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent(
|
||||
"Group Productivity Impaired · Accept: 2 hrs · Respond: 8 hrs (next day if after hours) · After hours: Approval required",
|
||||
);
|
||||
});
|
||||
|
||||
it("is a button only when it can reopen the severity control", async () => {
|
||||
const onClick = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
const { rerender } = render(<SeverityBadge severity={2} />);
|
||||
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
||||
|
||||
rerender(<SeverityBadge severity={2} onClick={onClick} />);
|
||||
const badge = screen.getByRole("button");
|
||||
expect(badge).toHaveTextContent("SEV 2");
|
||||
await user.click(badge);
|
||||
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
|
@ -189,7 +189,12 @@ vi.mock("@/app/(protected)/workorders/_components/list/table/wo-table", () => ({
|
|||
describe("WorkOrdersListHeader slice affordances", () => {
|
||||
it("hides New WO and Advanced Filters when callbacks are omitted", () => {
|
||||
renderWithProviders(
|
||||
<WorkOrdersListHeader search="" onSearchChange={vi.fn()} activeFilterCount={0} />,
|
||||
<WorkOrdersListHeader
|
||||
search=""
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
activeFilterCount={0}
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
|
|
@ -202,6 +207,7 @@ describe("WorkOrdersListHeader slice affordances", () => {
|
|||
renderWithProviders(
|
||||
<WorkOrdersListHeader
|
||||
search=""
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
onNewWorkOrder={vi.fn()}
|
||||
onOpenAdvancedFilters={vi.fn()}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,130 @@
|
|||
import { act, renderHook, screen, waitFor } from "@testing-library/react";
|
||||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import type { ReactNode } from "react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { EMPTY_ADVANCED_FILTERS } from "@/domain/work-orders/types/work-order-advanced-filters";
|
||||
import { createTestQueryClient, renderWithProviders } from "@/test/test-utils";
|
||||
|
||||
const { searchBoard, getBoard, emptyList } = vi.hoisted(() => ({
|
||||
searchBoard: vi.fn(),
|
||||
getBoard: vi.fn(),
|
||||
emptyList: [] as const,
|
||||
}));
|
||||
|
||||
vi.mock("@/hooks/use-debounce", () => ({
|
||||
useDebounce: <T,>(value: T) => value,
|
||||
}));
|
||||
|
||||
vi.mock("@/domain/work-orders/api/work-orders-api", () => ({
|
||||
workOrdersApi: {
|
||||
searchBoard: (...args: unknown[]) => searchBoard(...args),
|
||||
getBoard: (...args: unknown[]) => getBoard(...args),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/domain/work-orders/use-cases/use-work-order-detail", () => ({
|
||||
useWorkOrderLocations: () => ({ data: emptyList }),
|
||||
useWorkOrderVendors: () => ({ data: emptyList }),
|
||||
}));
|
||||
|
||||
import { WorkOrdersListHeader } from "@/app/(protected)/workorders/_components/list/work-orders-list-header";
|
||||
import { useWorkOrdersBoardSource } from "@/app/(protected)/workorders/_hooks/use-work-orders-board-source";
|
||||
import { useWorkOrdersListFilters } from "@/app/(protected)/workorders/_hooks/use-work-orders-list-filters";
|
||||
|
||||
const EMPTY_RESULT = { items: [], totalCount: 0, page: 0, pageSize: 25 };
|
||||
|
||||
function useBoardWithFilters() {
|
||||
const filters = useWorkOrdersListFilters();
|
||||
useWorkOrdersBoardSource(filters);
|
||||
return filters;
|
||||
}
|
||||
|
||||
function renderBoardSource() {
|
||||
const client = createTestQueryClient();
|
||||
const wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
||||
);
|
||||
return renderHook(() => useBoardWithFilters(), { wrapper });
|
||||
}
|
||||
|
||||
describe("keyword search scope indicator", () => {
|
||||
it("shows no scope badge while the search box is empty", () => {
|
||||
renderWithProviders(
|
||||
<WorkOrdersListHeader
|
||||
search=""
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
activeFilterCount={0}
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.queryByText(/searching within/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("names the active week while a keyword is typed", () => {
|
||||
renderWithProviders(
|
||||
<WorkOrdersListHeader
|
||||
search="hvac"
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
activeFilterCount={0}
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.getByText("Searching within 5/4–5/8")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("hides the scope label while Advanced Filters are active", () => {
|
||||
renderWithProviders(
|
||||
<WorkOrdersListHeader
|
||||
search="hvac"
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
activeFilterCount={1}
|
||||
advancedFiltersActive
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.queryByText(/searching within/i)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("keyword search vs Advanced Filters scope", () => {
|
||||
beforeEach(() => {
|
||||
searchBoard.mockReset().mockResolvedValue(EMPTY_RESULT);
|
||||
getBoard.mockReset().mockResolvedValue(EMPTY_RESULT);
|
||||
});
|
||||
|
||||
it("scopes keyword search to the active week", async () => {
|
||||
const { result } = renderBoardSource();
|
||||
|
||||
act(() => {
|
||||
result.current.setWeekMonday("2026-05-04");
|
||||
result.current.handleSearchChange("hvac");
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(getBoard).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ weekStart: "2026-05-04", weekEnd: "2026-05-08", search: "hvac" }),
|
||||
),
|
||||
);
|
||||
expect(searchBoard).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps Advanced Filters global and ignores the week-scoped keyword", async () => {
|
||||
const { result } = renderBoardSource();
|
||||
|
||||
act(() => {
|
||||
result.current.handleSearchChange("hvac");
|
||||
result.current.applyAdvancedFilters({ ...EMPTY_ADVANCED_FILTERS, rescheduled: true });
|
||||
});
|
||||
|
||||
await waitFor(() => expect(searchBoard).toHaveBeenCalled());
|
||||
const params = searchBoard.mock.lastCall?.[0] as Record<string, unknown>;
|
||||
expect(params.search).toBeUndefined();
|
||||
expect(params).not.toHaveProperty("weekStart");
|
||||
});
|
||||
});
|
||||
29
src/test/domain/work-orders/utils/due-date-floor.test.ts
Normal file
29
src/test/domain/work-orders/utils/due-date-floor.test.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
clearDueDateBeforeSchedule,
|
||||
isDueDateBeforeFloor,
|
||||
resolveDueDateFloor,
|
||||
} from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
describe("due date floor (SH-356)", () => {
|
||||
it("uses the concrete or range-start Schedule On, else the target week's first day", () => {
|
||||
expect(resolveDueDateFloor({ scheduledOn: "2026-09-10", targetWeek: "" })).toBe("2026-09-10");
|
||||
expect(resolveDueDateFloor({ scheduledOn: "", targetWeek: "2026-09-14" })).toBe("2026-09-14");
|
||||
expect(resolveDueDateFloor({ scheduledOn: "", targetWeek: "" })).toBe("");
|
||||
expect(resolveDueDateFloor({ scheduledOn: null, targetWeek: undefined })).toBe("");
|
||||
});
|
||||
|
||||
it("flags only a Due Date strictly before the floor", () => {
|
||||
expect(isDueDateBeforeFloor("2026-09-09", "2026-09-10")).toBe(true);
|
||||
expect(isDueDateBeforeFloor("2026-09-10", "2026-09-10")).toBe(false);
|
||||
expect(isDueDateBeforeFloor("", "2026-09-10")).toBe(false);
|
||||
expect(isDueDateBeforeFloor("2026-09-09", "")).toBe(false);
|
||||
});
|
||||
|
||||
it("clears (never bumps) a Due Date the new schedule passes", () => {
|
||||
expect(clearDueDateBeforeSchedule("2026-09-12", "2026-09-15")).toEqual({ dueDate: "" });
|
||||
expect(clearDueDateBeforeSchedule("2026-09-12", "2026-09-12")).toEqual({});
|
||||
expect(clearDueDateBeforeSchedule("2026-09-20", "2026-09-15")).toEqual({});
|
||||
expect(clearDueDateBeforeSchedule("2026-09-12", "")).toEqual({});
|
||||
});
|
||||
});
|
||||
|
|
@ -18,6 +18,21 @@ describe("shouldAnnounceSeverityEscalation", () => {
|
|||
expect(shouldAnnounceSeverityEscalation(2, 3)).toBe(false);
|
||||
});
|
||||
|
||||
it("announces when severity rises from SEV 3–5 into SEV 2", () => {
|
||||
expect(shouldAnnounceSeverityEscalation(5, 2)).toBe(true);
|
||||
expect(shouldAnnounceSeverityEscalation(4, 2)).toBe(true);
|
||||
});
|
||||
|
||||
it("does not announce moves between SEV 3–5", () => {
|
||||
expect(shouldAnnounceSeverityEscalation(5, 3)).toBe(false);
|
||||
expect(shouldAnnounceSeverityEscalation(4, 3)).toBe(false);
|
||||
expect(shouldAnnounceSeverityEscalation(3, 5)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not announce SEV 1 to SEV 2 (already critical)", () => {
|
||||
expect(shouldAnnounceSeverityEscalation(1, 2)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not announce SEV 2 to SEV 1 (already critical)", () => {
|
||||
expect(shouldAnnounceSeverityEscalation(2, 1)).toBe(false);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue