mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 20:13:15 +00:00
Give keyboard and screen-reader users color-independent labels when setting, changing, or clearing a work-order flag.
136 lines
3.8 KiB
TypeScript
136 lines
3.8 KiB
TypeScript
import { fireEvent, screen } from "@testing-library/react";
|
||
import { describe, expect, it, vi } from "vitest";
|
||
import { WoTableRow } from "@/app/(protected)/workorders/_components/list/table/wo-table-row";
|
||
import type { WoTableRowHandlers } from "@/app/(protected)/workorders/_components/list/table/wo-table-row";
|
||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||
import { renderWithProviders } from "@/test/test-utils";
|
||
|
||
function makeRow(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow {
|
||
return {
|
||
id: 9,
|
||
woNumber: "24818000001",
|
||
site: "BK5",
|
||
type: "PM",
|
||
severity: null,
|
||
dispatcherId: "u1",
|
||
dispatcherName: "Alex",
|
||
scheduledOn: "2026-07-15",
|
||
completedDate: "2026-07-20",
|
||
targetWeek: "2026-07-15",
|
||
dayGroup: "07/15",
|
||
dayLabel: "Tue",
|
||
location: "Lobby",
|
||
locationId: "loc-1",
|
||
pm: "HVAC",
|
||
serviceNotes: "",
|
||
extraServices: [],
|
||
vendorId: "7",
|
||
company: "Acme",
|
||
tech: "Sam",
|
||
techPhone: "",
|
||
apptStart: "",
|
||
apptEnd: "",
|
||
apptTime: "09:00 – 10:00",
|
||
status: "Completed",
|
||
docStatus: "Yes",
|
||
pocName: "",
|
||
pocPhone: "",
|
||
pocNotes: "",
|
||
dueDate: "2026-07-22",
|
||
rescheduleCount: 0,
|
||
carriedOver: 0,
|
||
originalWeek: "",
|
||
originalDate: "",
|
||
isPastDue: false,
|
||
scheduleWeekOnly: false,
|
||
isAddOn: false,
|
||
mediaCount: 1,
|
||
title: "",
|
||
priority: "",
|
||
primaryDispatchId: null,
|
||
rowVersion: "",
|
||
dispatchRowVersion: "",
|
||
flagColor: null,
|
||
additionalContacts: [],
|
||
upliftSummary: { hasUplift: false, pendingCount: 0 },
|
||
...overrides,
|
||
};
|
||
}
|
||
|
||
const handlers: WoTableRowHandlers = {
|
||
onRowClick: vi.fn(),
|
||
onView: vi.fn(),
|
||
onEdit: vi.fn(),
|
||
onOpenMedia: vi.fn(),
|
||
onPatch: vi.fn(),
|
||
onScheduleDate: vi.fn(),
|
||
onScheduleWeek: vi.fn(),
|
||
onOpenSlideOver: vi.fn(),
|
||
onOpenCompDoc: vi.fn(),
|
||
onOpenUplifts: vi.fn(),
|
||
onReorder: vi.fn(),
|
||
onDragStart: vi.fn(),
|
||
onDragOver: vi.fn(),
|
||
onDrop: vi.fn(),
|
||
onDragEnd: vi.fn(),
|
||
};
|
||
|
||
describe("WoTableRow completed selective lock", () => {
|
||
it("keeps Flag enabled and hides Edit on a Completed row", () => {
|
||
const row = makeRow();
|
||
renderWithProviders(
|
||
<table>
|
||
<tbody>
|
||
<WoTableRow
|
||
row={row}
|
||
allRows={[row]}
|
||
users={[]}
|
||
sites={[]}
|
||
vendors={[]}
|
||
pmTypes={["HVAC"]}
|
||
isSelected={false}
|
||
isFlashing={false}
|
||
dragViz={{ dragId: null, overId: null }}
|
||
handlers={handlers}
|
||
/>
|
||
</tbody>
|
||
</table>,
|
||
{ withAuth: false },
|
||
);
|
||
|
||
expect(screen.getByRole("button", { name: "Add flag" })).toBeEnabled();
|
||
fireEvent.click(screen.getByRole("button", { name: "Add flag" }));
|
||
expect(screen.getByText("Clear flag")).toBeInTheDocument();
|
||
expect(screen.queryByTitle("Edit")).not.toBeInTheDocument();
|
||
expect(screen.getByTitle("View details")).toBeInTheDocument();
|
||
});
|
||
|
||
it("does not open the status menu on a Completed row", () => {
|
||
const row = makeRow();
|
||
renderWithProviders(
|
||
<table>
|
||
<tbody>
|
||
<WoTableRow
|
||
row={row}
|
||
allRows={[row]}
|
||
users={[]}
|
||
sites={[]}
|
||
vendors={[]}
|
||
pmTypes={["HVAC"]}
|
||
isSelected={false}
|
||
isFlashing={false}
|
||
dragViz={{ dragId: null, overId: null }}
|
||
handlers={handlers}
|
||
/>
|
||
</tbody>
|
||
</table>,
|
||
{ withAuth: false },
|
||
);
|
||
|
||
fireEvent.click(screen.getByLabelText("Status is locked because this work order is completed"));
|
||
|
||
expect(screen.queryByRole("button", { name: /scheduled/i })).not.toBeInTheDocument();
|
||
expect(screen.queryByRole("button", { name: /in progress/i })).not.toBeInTheDocument();
|
||
expect(handlers.onPatch).not.toHaveBeenCalled();
|
||
});
|
||
});
|