mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 19:32:06 +00:00
Merge branch 'dev' into fix/ab/sh-320-inline-sh-prefix-wo-number
This commit is contained in:
commit
a793e1c2d9
16 changed files with 465 additions and 41 deletions
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 { deriveDayFields } from "@/domain/work-orders/utils/table-day-utils";
|
||||||
import { toVendorTablePatch } from "@/domain/work-orders/utils/vendor-assignment-patch";
|
import { toVendorTablePatch } from "@/domain/work-orders/utils/vendor-assignment-patch";
|
||||||
import { DocBadge } from "./slide-over-doc-badge";
|
import { DocBadge } from "./slide-over-doc-badge";
|
||||||
|
import {
|
||||||
|
clearDueDateBeforeSchedule,
|
||||||
|
resolveDueDateFloor,
|
||||||
|
} from "@/domain/work-orders/utils/due-date-floor";
|
||||||
|
|
||||||
type SlideOverInfoTabEditViewProps = {
|
type SlideOverInfoTabEditViewProps = {
|
||||||
draft: WorkOrderTableRow;
|
draft: WorkOrderTableRow;
|
||||||
|
|
@ -52,6 +56,7 @@ function SlideOverScheduleOnField({
|
||||||
schedMode={draft.schedMode}
|
schedMode={draft.schedMode}
|
||||||
onSave={(scheduledOn) =>
|
onSave={(scheduledOn) =>
|
||||||
onDraftChange({
|
onDraftChange({
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, scheduledOn),
|
||||||
scheduledOn,
|
scheduledOn,
|
||||||
scheduleWeekOnly: false,
|
scheduleWeekOnly: false,
|
||||||
targetWeek: scheduledOn ? "" : draft.targetWeek,
|
targetWeek: scheduledOn ? "" : draft.targetWeek,
|
||||||
|
|
@ -63,6 +68,7 @@ function SlideOverScheduleOnField({
|
||||||
}
|
}
|
||||||
onSaveWeek={(weekStart) =>
|
onSaveWeek={(weekStart) =>
|
||||||
onDraftChange({
|
onDraftChange({
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, weekStart),
|
||||||
scheduledOn: "",
|
scheduledOn: "",
|
||||||
targetWeek: weekStart,
|
targetWeek: weekStart,
|
||||||
scheduleWeekOnly: true,
|
scheduleWeekOnly: true,
|
||||||
|
|
@ -74,6 +80,7 @@ function SlideOverScheduleOnField({
|
||||||
}
|
}
|
||||||
onSaveRange={(start, end) =>
|
onSaveRange={(start, end) =>
|
||||||
onDraftChange({
|
onDraftChange({
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, start),
|
||||||
scheduledOn: start,
|
scheduledOn: start,
|
||||||
scheduleEnd: end,
|
scheduleEnd: end,
|
||||||
schedMode: "range",
|
schedMode: "range",
|
||||||
|
|
@ -175,6 +182,7 @@ export function SlideOverInfoTabEditView({
|
||||||
<DueDateCell
|
<DueDateCell
|
||||||
type={draft.type}
|
type={draft.type}
|
||||||
value={draft.dueDate}
|
value={draft.dueDate}
|
||||||
|
minDate={resolveDueDateFloor(draft)}
|
||||||
onSave={(dueDate) => onDraftChange({ dueDate })}
|
onSave={(dueDate) => onDraftChange({ dueDate })}
|
||||||
/>
|
/>
|
||||||
</SlideOverInfoRow>
|
</SlideOverInfoRow>
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ type DateCellProps = {
|
||||||
onClear?: () => void;
|
onClear?: () => void;
|
||||||
/** Screen-reader-only status appended inside the button so the accessible name keeps the visible date and adds durable state. */
|
/** Screen-reader-only status appended inside the button so the accessible name keeps the visible date and adds durable state. */
|
||||||
srStatusSuffix?: string;
|
srStatusSuffix?: string;
|
||||||
|
/** Earliest selectable day in the date calendar (SH-356). */
|
||||||
|
minDate?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function DateCell({
|
export function DateCell({
|
||||||
|
|
@ -41,6 +43,7 @@ export function DateCell({
|
||||||
onSaveRange,
|
onSaveRange,
|
||||||
onClear,
|
onClear,
|
||||||
srStatusSuffix,
|
srStatusSuffix,
|
||||||
|
minDate,
|
||||||
}: DateCellProps) {
|
}: DateCellProps) {
|
||||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||||
const open = Boolean(anchorEl);
|
const open = Boolean(anchorEl);
|
||||||
|
|
@ -154,6 +157,7 @@ export function DateCell({
|
||||||
) : (
|
) : (
|
||||||
<MiniCalendar
|
<MiniCalendar
|
||||||
value={value}
|
value={value}
|
||||||
|
minDate={minDate}
|
||||||
onChange={(d) => {
|
onChange={(d) => {
|
||||||
onSave(d);
|
onSave(d);
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ type DueDateCalendarDialogProps = {
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
value: string;
|
value: string;
|
||||||
onSave: (iso: string) => void;
|
onSave: (iso: string) => void;
|
||||||
|
minDate?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -19,6 +20,7 @@ export function DueDateCalendarDialog({
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
value,
|
value,
|
||||||
onSave,
|
onSave,
|
||||||
|
minDate,
|
||||||
}: DueDateCalendarDialogProps) {
|
}: DueDateCalendarDialogProps) {
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
|
|
@ -44,6 +46,7 @@ export function DueDateCalendarDialog({
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-center">
|
||||||
<MiniCalendar
|
<MiniCalendar
|
||||||
value={value}
|
value={value}
|
||||||
|
minDate={minDate}
|
||||||
onChange={(iso) => {
|
onChange={(iso) => {
|
||||||
onSave(iso);
|
onSave(iso);
|
||||||
onOpenChange(false);
|
onOpenChange(false);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ type DueDateCellProps = {
|
||||||
* read by colour alone.
|
* read by colour alone.
|
||||||
*/
|
*/
|
||||||
pastDue?: boolean;
|
pastDue?: boolean;
|
||||||
|
/** Schedule On floor: earlier days are not selectable (SH-356). */
|
||||||
|
minDate?: string;
|
||||||
onSave: (date: string) => void;
|
onSave: (date: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -29,6 +31,7 @@ export function DueDateCell({
|
||||||
q,
|
q,
|
||||||
highlight,
|
highlight,
|
||||||
pastDue = false,
|
pastDue = false,
|
||||||
|
minDate,
|
||||||
onSave,
|
onSave,
|
||||||
}: DueDateCellProps) {
|
}: DueDateCellProps) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
@ -40,6 +43,7 @@ export function DueDateCell({
|
||||||
q={q}
|
q={q}
|
||||||
highlight={highlight}
|
highlight={highlight}
|
||||||
onSave={onSave}
|
onSave={onSave}
|
||||||
|
minDate={minDate}
|
||||||
srStatusSuffix={pastDue ? "Past due" : undefined}
|
srStatusSuffix={pastDue ? "Past due" : undefined}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
@ -87,7 +91,13 @@ export function DueDateCell({
|
||||||
style={{ color: "var(--muted-foreground)" }}
|
style={{ color: "var(--muted-foreground)" }}
|
||||||
/>
|
/>
|
||||||
</button>
|
</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 type { ReturnTypeOfUseWorkOrdersTableData } from "./wo-table-types";
|
||||||
import { rescheduleNotify, weekMoveNotify } from "./reschedule-notify";
|
import { rescheduleNotify, weekMoveNotify } from "./reschedule-notify";
|
||||||
import type { WoTableRowHandlers } from "./wo-table-row";
|
import type { WoTableRowHandlers } from "./wo-table-row";
|
||||||
|
import { clearDueDateBeforeSchedule } from "@/domain/work-orders/utils/due-date-floor";
|
||||||
|
|
||||||
function revealOrNotifyScheduledDay(args: {
|
function revealOrNotifyScheduledDay(args: {
|
||||||
id: string | number;
|
id: string | number;
|
||||||
|
|
@ -31,6 +32,35 @@ function revealOrNotifyScheduledDay(args: {
|
||||||
revealScheduledRow(id);
|
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 = {
|
type UseWoTableRowHandlersOptions = {
|
||||||
tableData: ReturnTypeOfUseWorkOrdersTableData;
|
tableData: ReturnTypeOfUseWorkOrdersTableData;
|
||||||
weekMonday: string;
|
weekMonday: string;
|
||||||
|
|
@ -101,8 +131,11 @@ export function useWoTableRowHandlers({
|
||||||
onPatch: (id, patch, options) => {
|
onPatch: (id, patch, options) => {
|
||||||
onPatch(id, patch, options);
|
onPatch(id, patch, options);
|
||||||
},
|
},
|
||||||
onScheduleDate: (id: string | number, date: string) => {
|
onScheduleDate: (id: string | number, date: string, dueDate?: string) => {
|
||||||
onPatch(id, applySchedulePatch(date, false));
|
onPatch(id, {
|
||||||
|
...applySchedulePatch(date, false),
|
||||||
|
...clearDueDateBeforeSchedule(dueDate, date),
|
||||||
|
});
|
||||||
revealOrNotifyScheduledDay({
|
revealOrNotifyScheduledDay({
|
||||||
id,
|
id,
|
||||||
date,
|
date,
|
||||||
|
|
@ -111,8 +144,11 @@ export function useWoTableRowHandlers({
|
||||||
revealScheduledRow,
|
revealScheduledRow,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onScheduleRange: (id: string | number, start: string, end: string) => {
|
onScheduleRange: (id: string | number, start: string, end: string, dueDate?: string) => {
|
||||||
onPatch(id, applyScheduleRangePatch(start, end));
|
onPatch(id, {
|
||||||
|
...applyScheduleRangePatch(start, end),
|
||||||
|
...clearDueDateBeforeSchedule(dueDate, start),
|
||||||
|
});
|
||||||
revealOrNotifyScheduledDay({
|
revealOrNotifyScheduledDay({
|
||||||
id,
|
id,
|
||||||
date: start,
|
date: start,
|
||||||
|
|
@ -121,7 +157,7 @@ export function useWoTableRowHandlers({
|
||||||
revealScheduledRow,
|
revealScheduledRow,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onScheduleWeek: (id: string | number, week: string) => {
|
onScheduleWeek: (id: string | number, week: string, dueDate?: string) => {
|
||||||
const isClear = week === "";
|
const isClear = week === "";
|
||||||
onPatch(
|
onPatch(
|
||||||
id,
|
id,
|
||||||
|
|
@ -135,6 +171,7 @@ export function useWoTableRowHandlers({
|
||||||
schedMode: "week",
|
schedMode: "week",
|
||||||
dayGroup: "",
|
dayGroup: "",
|
||||||
dayLabel: "",
|
dayLabel: "",
|
||||||
|
...clearDueDateBeforeSchedule(dueDate, week),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
weekMoveNotify(week, {
|
weekMoveNotify(week, {
|
||||||
|
|
@ -153,25 +190,12 @@ export function useWoTableRowHandlers({
|
||||||
onRequestComplete,
|
onRequestComplete,
|
||||||
onPastDueAttempt: (id: string | number) => onScheduleHighlight(id),
|
onPastDueAttempt: (id: string | number) => onScheduleHighlight(id),
|
||||||
onReorder: reorderRows,
|
onReorder: reorderRows,
|
||||||
onDragStart: (id: string | number) => {
|
...createDragHandlers({
|
||||||
dragStateRef.current = { dragId: id, overId: null };
|
dragState: dragStateRef,
|
||||||
setDragViz({ dragId: id, overId: null });
|
setDragViz,
|
||||||
},
|
reorderRows,
|
||||||
onDragOver: (id: string | number) => {
|
endDrag,
|
||||||
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,
|
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
tableData,
|
tableData,
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@ import { toVendorTablePatch } from "@/domain/work-orders/utils/vendor-assignment
|
||||||
import { InlineCreateField } from "./inline-create-field";
|
import { InlineCreateField } from "./inline-create-field";
|
||||||
import { toInlineDraftRow } from "./to-inline-draft-row";
|
import { toInlineDraftRow } from "./to-inline-draft-row";
|
||||||
import { WoTableInlineIdentityCells } from "./wo-table-inline-identity-cells";
|
import { WoTableInlineIdentityCells } from "./wo-table-inline-identity-cells";
|
||||||
|
import {
|
||||||
|
clearDueDateBeforeSchedule,
|
||||||
|
resolveDueDateFloor,
|
||||||
|
} from "@/domain/work-orders/utils/due-date-floor";
|
||||||
|
|
||||||
type WoTableInlineRowCellsProps = {
|
type WoTableInlineRowCellsProps = {
|
||||||
draft: WorkOrderTableDraft;
|
draft: WorkOrderTableDraft;
|
||||||
|
|
@ -106,6 +110,7 @@ function InlineScheduleOnCell({
|
||||||
onSave={(date) =>
|
onSave={(date) =>
|
||||||
onPatch(
|
onPatch(
|
||||||
withAutoScheduleStatus(draft, {
|
withAutoScheduleStatus(draft, {
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, date),
|
||||||
scheduledOn: date,
|
scheduledOn: date,
|
||||||
scheduleWeekOnly: false,
|
scheduleWeekOnly: false,
|
||||||
targetWeek: "",
|
targetWeek: "",
|
||||||
|
|
@ -118,6 +123,7 @@ function InlineScheduleOnCell({
|
||||||
onSaveWeek={(week) =>
|
onSaveWeek={(week) =>
|
||||||
onPatch(
|
onPatch(
|
||||||
withAutoScheduleStatus(draft, {
|
withAutoScheduleStatus(draft, {
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, week),
|
||||||
scheduledOn: "",
|
scheduledOn: "",
|
||||||
targetWeek: week,
|
targetWeek: week,
|
||||||
scheduleWeekOnly: true,
|
scheduleWeekOnly: true,
|
||||||
|
|
@ -130,6 +136,7 @@ function InlineScheduleOnCell({
|
||||||
onSaveRange={(start, end) =>
|
onSaveRange={(start, end) =>
|
||||||
onPatch(
|
onPatch(
|
||||||
withAutoScheduleStatus(draft, {
|
withAutoScheduleStatus(draft, {
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, start),
|
||||||
scheduledOn: start,
|
scheduledOn: start,
|
||||||
scheduleEnd: end,
|
scheduleEnd: end,
|
||||||
schedMode: "range",
|
schedMode: "range",
|
||||||
|
|
@ -212,6 +219,7 @@ export function WoTableInlineRowCells({
|
||||||
<DueDateCell
|
<DueDateCell
|
||||||
type={draft.type}
|
type={draft.type}
|
||||||
value={draft.dueDate}
|
value={draft.dueDate}
|
||||||
|
minDate={resolveDueDateFloor(draft)}
|
||||||
onSave={(date) => onPatch({ dueDate: date })}
|
onSave={(date) => onPatch({ dueDate: date })}
|
||||||
/>
|
/>
|
||||||
</InlineFieldCell>
|
</InlineFieldCell>
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import { EditableWONumberCell } from "./cells/editable-wo-number-cell";
|
||||||
import { SiteCell } from "./cells/site-cell";
|
import { SiteCell } from "./cells/site-cell";
|
||||||
import { TypeCell } from "./cells/type-cell";
|
import { TypeCell } from "./cells/type-cell";
|
||||||
import type { WoTableRowHandlers } from "./wo-table-row";
|
import type { WoTableRowHandlers } from "./wo-table-row";
|
||||||
|
import { resolveDueDateFloor } from "@/domain/work-orders/utils/due-date-floor";
|
||||||
|
|
||||||
type WoTableRowCellsProps = {
|
type WoTableRowCellsProps = {
|
||||||
row: WorkOrderTableRow;
|
row: WorkOrderTableRow;
|
||||||
|
|
@ -146,9 +147,9 @@ export function WoTableRowCells({
|
||||||
targetWeek={row.targetWeek}
|
targetWeek={row.targetWeek}
|
||||||
scheduleEnd={row.scheduleEnd}
|
scheduleEnd={row.scheduleEnd}
|
||||||
schedMode={row.schedMode}
|
schedMode={row.schedMode}
|
||||||
onSave={(date) => handlers.onScheduleDate(row.id, date)}
|
onSave={(date) => handlers.onScheduleDate(row.id, date, row.dueDate)}
|
||||||
onSaveWeek={(week) => handlers.onScheduleWeek(row.id, week)}
|
onSaveWeek={(week) => handlers.onScheduleWeek(row.id, week, row.dueDate)}
|
||||||
onSaveRange={(start, end) => handlers.onScheduleRange(row.id, start, end)}
|
onSaveRange={(start, end) => handlers.onScheduleRange(row.id, start, end, row.dueDate)}
|
||||||
onClear={hasSchedule && !viewOnly ? () => handlers.onScheduleWeek(row.id, "") : undefined}
|
onClear={hasSchedule && !viewOnly ? () => handlers.onScheduleWeek(row.id, "") : undefined}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
|
|
@ -163,6 +164,7 @@ export function WoTableRowCells({
|
||||||
q={search}
|
q={search}
|
||||||
highlight={forceDueDateHighlight || row.isPastDue}
|
highlight={forceDueDateHighlight || row.isPastDue}
|
||||||
pastDue={row.isPastDue}
|
pastDue={row.isPastDue}
|
||||||
|
minDate={resolveDueDateFloor(row)}
|
||||||
onSave={(date) => onPatchRow({ dueDate: date })}
|
onSave={(date) => onPatchRow({ dueDate: date })}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,10 @@ export type WoTableRowHandlers = {
|
||||||
patch: Partial<WorkOrderTableRow>,
|
patch: Partial<WorkOrderTableRow>,
|
||||||
options?: WorkOrderTablePatchOptions,
|
options?: WorkOrderTablePatchOptions,
|
||||||
) => void;
|
) => void;
|
||||||
onScheduleDate: (id: string | number, date: string) => void;
|
/** `dueDate` is the row's current Due Date, cleared when the new schedule passes it (SH-356). */
|
||||||
onScheduleWeek: (id: string | number, week: string) => void;
|
onScheduleDate: (id: string | number, date: string, dueDate?: string) => void;
|
||||||
onScheduleRange: (id: string | number, start: string, end: 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;
|
onDuplicateFound?: (existing: WorkOrderTableRow) => void;
|
||||||
onOpenSlideOver: (row: WorkOrderTableRow) => void;
|
onOpenSlideOver: (row: WorkOrderTableRow) => void;
|
||||||
onRequestComplete?: (row: WorkOrderTableRow) => void;
|
onRequestComplete?: (row: WorkOrderTableRow) => void;
|
||||||
|
|
@ -77,17 +78,17 @@ function guardScheduleHandlers(
|
||||||
if (!canApplyWorkOrderTablePatch(row.status, patch)) return;
|
if (!canApplyWorkOrderTablePatch(row.status, patch)) return;
|
||||||
handlers.onPatch(id, patch, options);
|
handlers.onPatch(id, patch, options);
|
||||||
},
|
},
|
||||||
onScheduleDate: (id, date) => {
|
onScheduleDate: (id, date, dueDate) => {
|
||||||
if (!canApplyWorkOrderTablePatch(row.status, { scheduledOn: date })) return;
|
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;
|
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;
|
if (!canApplyWorkOrderTablePatch(row.status, { scheduledOn: start })) return;
|
||||||
handlers.onScheduleRange(id, start, end);
|
handlers.onScheduleRange(id, start, end, dueDate);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ type MiniCalendarProps = {
|
||||||
range?: boolean;
|
range?: boolean;
|
||||||
rangeStart?: string;
|
rangeStart?: string;
|
||||||
rangeEnd?: string;
|
rangeEnd?: string;
|
||||||
|
/** Days before this ISO date are disabled (SH-356 Due Date floor). */
|
||||||
|
minDate?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function MiniCalendar({
|
export function MiniCalendar({
|
||||||
|
|
@ -20,9 +22,11 @@ export function MiniCalendar({
|
||||||
range,
|
range,
|
||||||
rangeStart = "",
|
rangeStart = "",
|
||||||
rangeEnd = "",
|
rangeEnd = "",
|
||||||
|
minDate = "",
|
||||||
}: MiniCalendarProps) {
|
}: MiniCalendarProps) {
|
||||||
const initRaw = range ? rangeStart || value : value;
|
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 [iy, im] = init.split("-").map(Number);
|
||||||
const [viewY, setViewY] = useState(iy);
|
const [viewY, setViewY] = useState(iy);
|
||||||
const [viewM, setViewM] = useState(im);
|
const [viewM, setViewM] = useState(im);
|
||||||
|
|
@ -94,6 +98,7 @@ export function MiniCalendar({
|
||||||
}
|
}
|
||||||
const iso = `${viewY}-${pad2(viewM)}-${pad2(day)}`;
|
const iso = `${viewY}-${pad2(viewM)}-${pad2(day)}`;
|
||||||
const isToday = iso === today;
|
const isToday = iso === today;
|
||||||
|
const beforeMin = Boolean(minDate) && iso < minDate;
|
||||||
const { bg, fg, radius, filled } = getMiniCalendarCellStyle({
|
const { bg, fg, radius, filled } = getMiniCalendarCellStyle({
|
||||||
iso,
|
iso,
|
||||||
value,
|
value,
|
||||||
|
|
@ -107,8 +112,9 @@ export function MiniCalendar({
|
||||||
<button
|
<button
|
||||||
key={i}
|
key={i}
|
||||||
type="button"
|
type="button"
|
||||||
|
disabled={beforeMin}
|
||||||
onClick={() => onChange(iso)}
|
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={{
|
style={{
|
||||||
height: 26,
|
height: 26,
|
||||||
borderRadius: radius,
|
borderRadius: radius,
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ type WizardDateFieldProps = {
|
||||||
scheduleEnd?: string;
|
scheduleEnd?: string;
|
||||||
schedMode?: WizardSchedMode;
|
schedMode?: WizardSchedMode;
|
||||||
onChangeRange?: (start: string, end: string) => void;
|
onChangeRange?: (start: string, end: string) => void;
|
||||||
|
/** Earliest selectable day in the date calendar (SH-356). */
|
||||||
|
minDate?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function fieldLabel(args: {
|
function fieldLabel(args: {
|
||||||
|
|
@ -49,6 +51,7 @@ export function WizardDateField({
|
||||||
scheduleEnd = "",
|
scheduleEnd = "",
|
||||||
schedMode,
|
schedMode,
|
||||||
onChangeRange,
|
onChangeRange,
|
||||||
|
minDate,
|
||||||
}: WizardDateFieldProps) {
|
}: WizardDateFieldProps) {
|
||||||
const { anchorEl, open, setAnchor, close } = useMenuAnchor();
|
const { anchorEl, open, setAnchor, close } = useMenuAnchor();
|
||||||
const allowRange = Boolean(allowWeekMode && onChangeRange);
|
const allowRange = Boolean(allowWeekMode && onChangeRange);
|
||||||
|
|
@ -127,6 +130,7 @@ export function WizardDateField({
|
||||||
) : (
|
) : (
|
||||||
<MiniCalendar
|
<MiniCalendar
|
||||||
value={value}
|
value={value}
|
||||||
|
minDate={minDate}
|
||||||
onChange={(iso) => {
|
onChange={(iso) => {
|
||||||
onChange(iso);
|
onChange(iso);
|
||||||
close();
|
close();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ type WizardDueDateFieldProps = {
|
||||||
value: string;
|
value: string;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
onChange: (iso: string) => void;
|
onChange: (iso: string) => void;
|
||||||
|
/** Schedule On floor: earlier days are not selectable (SH-356). */
|
||||||
|
minDate?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,11 +23,19 @@ export function WizardDueDateField({
|
||||||
value,
|
value,
|
||||||
placeholder,
|
placeholder,
|
||||||
onChange,
|
onChange,
|
||||||
|
minDate,
|
||||||
}: WizardDueDateFieldProps) {
|
}: WizardDueDateFieldProps) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
if (type !== "Emergency") {
|
if (type !== "Emergency") {
|
||||||
return <WizardDateField value={value} placeholder={placeholder} onChange={onChange} />;
|
return (
|
||||||
|
<WizardDateField
|
||||||
|
value={value}
|
||||||
|
placeholder={placeholder}
|
||||||
|
onChange={onChange}
|
||||||
|
minDate={minDate}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -63,7 +73,13 @@ export function WizardDueDateField({
|
||||||
</span>
|
</span>
|
||||||
<ChevronDown size={13} className="shrink-0" style={{ color: "var(--muted-foreground)" }} />
|
<ChevronDown size={13} className="shrink-0" style={{ color: "var(--muted-foreground)" }} />
|
||||||
</button>
|
</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 { WizardSeverityPicker } from "@/app/(protected)/workorders/_components/wizard/wizard-severity-picker";
|
||||||
import { CheckCircle2, Clock, Flame, Users, Wrench, Zap } from "lucide-react";
|
import { CheckCircle2, Clock, Flame, Users, Wrench, Zap } from "lucide-react";
|
||||||
import type { ElementType } from "react";
|
import type { ElementType } from "react";
|
||||||
|
import {
|
||||||
|
clearDueDateBeforeSchedule,
|
||||||
|
resolveDueDateFloor,
|
||||||
|
} from "@/domain/work-orders/utils/due-date-floor";
|
||||||
|
|
||||||
const WO_TYPE_ICONS: Record<WOType, ElementType> = {
|
const WO_TYPE_ICONS: Record<WOType, ElementType> = {
|
||||||
PM: Wrench,
|
PM: Wrench,
|
||||||
|
|
@ -165,6 +169,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
||||||
onChange={(iso) =>
|
onChange={(iso) =>
|
||||||
onPatch(
|
onPatch(
|
||||||
withAutoScheduleStatus(draft, {
|
withAutoScheduleStatus(draft, {
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, iso),
|
||||||
scheduledOn: iso,
|
scheduledOn: iso,
|
||||||
scheduleWeekOnly: false,
|
scheduleWeekOnly: false,
|
||||||
scheduleEnd: "",
|
scheduleEnd: "",
|
||||||
|
|
@ -177,6 +182,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
||||||
onChangeWeek={(w) =>
|
onChangeWeek={(w) =>
|
||||||
onPatch(
|
onPatch(
|
||||||
withAutoScheduleStatus(draft, {
|
withAutoScheduleStatus(draft, {
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, w),
|
||||||
scheduledOn: w,
|
scheduledOn: w,
|
||||||
scheduleWeekOnly: Boolean(w),
|
scheduleWeekOnly: Boolean(w),
|
||||||
scheduleEnd: "",
|
scheduleEnd: "",
|
||||||
|
|
@ -189,6 +195,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
||||||
onChangeRange={(s, e) =>
|
onChangeRange={(s, e) =>
|
||||||
onPatch(
|
onPatch(
|
||||||
withAutoScheduleStatus(draft, {
|
withAutoScheduleStatus(draft, {
|
||||||
|
...clearDueDateBeforeSchedule(draft.dueDate, s),
|
||||||
scheduledOn: s,
|
scheduledOn: s,
|
||||||
scheduleEnd: e,
|
scheduleEnd: e,
|
||||||
schedMode: "range",
|
schedMode: "range",
|
||||||
|
|
@ -211,6 +218,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
||||||
<WizardDueDateField
|
<WizardDueDateField
|
||||||
type={draft.type}
|
type={draft.type}
|
||||||
value={draft.dueDate}
|
value={draft.dueDate}
|
||||||
|
minDate={resolveDueDateFloor(draft)}
|
||||||
placeholder="No due date"
|
placeholder="No due date"
|
||||||
onChange={(iso) => onUpdate("dueDate", iso)}
|
onChange={(iso) => onUpdate("dueDate", iso)}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
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: "" }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
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({});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Reference in a new issue