mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 22:43:23 +00:00
Wrap every inline creation cell in the bordered field box used by Site and WO #, top-aligned like the prototype inline row. Show a persistent asterisk on the empty WO # placeholder, the Site label in the create site dialog, and the POC name and phone inputs in the create site dialog and wizard.
121 lines
4.5 KiB
TypeScript
121 lines
4.5 KiB
TypeScript
import { fireEvent, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { PocContactFields } from "@/app/(protected)/workorders/_components/poc/poc-contact-fields";
|
|
import { WoTableInlineRow } from "@/app/(protected)/workorders/_components/list/table/wo-table-inline-row";
|
|
import {
|
|
EMPTY_TABLE_DRAFT,
|
|
type WorkOrderTableDraft,
|
|
} from "@/domain/work-orders/types/work-order-table-row";
|
|
import { renderWithProviders } from "@/test/test-utils";
|
|
|
|
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/date-cell", () => ({
|
|
DateCell: () => null,
|
|
}));
|
|
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/due-date-cell", () => ({
|
|
DueDateCell: () => 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/appt-time-cell", () => ({
|
|
ApptTimeCell: () => null,
|
|
}));
|
|
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/status-cell", () => ({
|
|
StatusCell: () => null,
|
|
}));
|
|
|
|
function renderInlineRow(draft: WorkOrderTableDraft, onSave = vi.fn()) {
|
|
const ui = (d: WorkOrderTableDraft) => (
|
|
<table>
|
|
<tbody>
|
|
<WoTableInlineRow
|
|
draft={d}
|
|
draftDayKey="2026-06-01"
|
|
users={[]}
|
|
sites={[]}
|
|
vendors={[]}
|
|
pmTypes={[]}
|
|
allRows={[]}
|
|
onChange={vi.fn()}
|
|
onSave={onSave}
|
|
onCancel={vi.fn()}
|
|
/>
|
|
</tbody>
|
|
</table>
|
|
);
|
|
const view = renderWithProviders(ui(draft), { withAuth: false });
|
|
return { ...view, rerenderDraft: (d: WorkOrderTableDraft) => view.rerender(ui(d)) };
|
|
}
|
|
|
|
const COMPLETE_DRAFT: WorkOrderTableDraft = {
|
|
...EMPTY_TABLE_DRAFT,
|
|
site: "BK5",
|
|
locationId: 9,
|
|
woNumber: "12345678901",
|
|
pocName: "Dana",
|
|
pocPhone: "555-0100",
|
|
};
|
|
|
|
describe("WoTableInlineRow required fields", () => {
|
|
it("marks Site and WO # as required without showing errors before a Save attempt", () => {
|
|
renderInlineRow(EMPTY_TABLE_DRAFT);
|
|
|
|
expect(screen.getByRole("button", { name: /^Site \*$/ })).toBeInTheDocument();
|
|
expect(screen.getByText("Insert WO #")).toHaveTextContent("Insert WO # *");
|
|
expect(screen.queryByText("Site is required")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Work order number is required")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("reveals field errors only after Save is attempted, then clears them once corrected", () => {
|
|
const onSave = vi.fn();
|
|
const { rerenderDraft } = renderInlineRow(EMPTY_TABLE_DRAFT, onSave);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Save work order" }));
|
|
|
|
expect(onSave).not.toHaveBeenCalled();
|
|
expect(screen.getByText("Site is required")).toBeInTheDocument();
|
|
expect(screen.getByText("Work order number is required")).toBeInTheDocument();
|
|
|
|
rerenderDraft(COMPLETE_DRAFT);
|
|
|
|
expect(screen.queryByText("Site is required")).not.toBeInTheDocument();
|
|
expect(screen.queryByText("Work order number is required")).not.toBeInTheDocument();
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Save work order" }));
|
|
expect(onSave).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
|
|
describe("PocContactFields required primary contact", () => {
|
|
it("labels POC name and phone with a required asterisk when the contact is required", () => {
|
|
renderWithProviders(
|
|
<PocContactFields
|
|
pocName=""
|
|
pocPhone=""
|
|
pocNotes=""
|
|
additionalContacts={[]}
|
|
primaryRequired
|
|
onPocNameChange={vi.fn()}
|
|
onPocPhoneChange={vi.fn()}
|
|
onPocNotesChange={vi.fn()}
|
|
onAdditionalContactsChange={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
expect(screen.getByLabelText(/POC name/)).toHaveAttribute("placeholder", "POC name");
|
|
expect(screen.getByLabelText(/POC phone/)).toHaveAttribute("placeholder", "POC phone");
|
|
expect(screen.getByText("POC name").closest("label")).toHaveTextContent("POC name*");
|
|
expect(screen.getByText("POC phone").closest("label")).toHaveTextContent("POC phone*");
|
|
expect(screen.queryByText("Contact name is required")).not.toBeInTheDocument();
|
|
});
|
|
});
|