mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
102 lines
3.4 KiB
TypeScript
102 lines
3.4 KiB
TypeScript
import { createRef } from "react";
|
|
import { fireEvent, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { WoTableInlineRowCells } from "@/app/(protected)/workorders/_components/list/table/wo-table-inline-row-cells";
|
|
import { EMPTY_TABLE_DRAFT } from "@/domain/work-orders/types/work-order-table-row";
|
|
import { pad2, todayIso } from "@/domain/work-orders/utils/wizard-date-utils";
|
|
import { renderWithProviders } from "@/test/test-utils";
|
|
|
|
function currentMonthIso(day: number): string {
|
|
const [y, m] = todayIso().split("-").map(Number);
|
|
return `${y}-${pad2(m)}-${pad2(day)}`;
|
|
}
|
|
|
|
describe("WoTableInlineRowCells — Schedule On range", () => {
|
|
it("reopens a company-only inline assignment without inferring its anchor as technician", async () => {
|
|
renderWithProviders(
|
|
<table>
|
|
<tbody>
|
|
<tr>
|
|
<WoTableInlineRowCells
|
|
draft={{
|
|
...EMPTY_TABLE_DRAFT,
|
|
vendorId: "41",
|
|
company: "Vinewood LLC",
|
|
technicianAssigned: false,
|
|
}}
|
|
weekDefault={false}
|
|
users={[]}
|
|
sites={[]}
|
|
vendors={[
|
|
{
|
|
id: 41,
|
|
companyName: "Vinewood LLC",
|
|
contactName: "Adam Whyte",
|
|
tradeSpecialties: "HVAC",
|
|
address: "1 Market St",
|
|
distanceMiles: null,
|
|
},
|
|
]}
|
|
pmTypes={[]}
|
|
allRows={[]}
|
|
siteCellRef={createRef()}
|
|
woCellRef={createRef()}
|
|
siteShowError={false}
|
|
siteError=""
|
|
woShowError={false}
|
|
onPatch={vi.fn()}
|
|
/>
|
|
</tr>
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /Vinewood LLC/ }));
|
|
expect(await screen.findByRole("button", { name: "No technician" })).toBeVisible();
|
|
expect(screen.queryByRole("button", { name: "Adam Whyte" })).not.toBeInTheDocument();
|
|
}, 10_000);
|
|
|
|
it("patches schedMode range with start and end", async () => {
|
|
const onPatch = vi.fn();
|
|
renderWithProviders(
|
|
<table>
|
|
<tbody>
|
|
<tr>
|
|
<WoTableInlineRowCells
|
|
draft={EMPTY_TABLE_DRAFT}
|
|
weekDefault={false}
|
|
users={[]}
|
|
sites={[]}
|
|
vendors={[]}
|
|
pmTypes={[]}
|
|
allRows={[]}
|
|
siteCellRef={createRef()}
|
|
woCellRef={createRef()}
|
|
siteShowError={false}
|
|
siteError=""
|
|
woShowError={false}
|
|
onPatch={onPatch}
|
|
/>
|
|
</tr>
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
|
|
const scheduleButtons = screen.getAllByRole("button", { name: "—" });
|
|
fireEvent.click(scheduleButtons[0]);
|
|
fireEvent.click(await screen.findByRole("button", { name: "Range" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "5" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "20" }));
|
|
fireEvent.click(screen.getByRole("button", { name: /^done$/i }));
|
|
|
|
expect(onPatch).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
scheduledOn: currentMonthIso(5),
|
|
scheduleEnd: currentMonthIso(20),
|
|
schedMode: "range",
|
|
scheduleWeekOnly: false,
|
|
targetWeek: "",
|
|
}),
|
|
);
|
|
}, 10_000);
|
|
});
|