shoc-frontend-new/src/test/app/(protected)/workorders/wo-table-inline-schedule-range.test.tsx
Arthur Bassi 418eb3749d fix(work-orders): restore Range tab on Schedule On for inline and slide-over
Share Week/Date/Range on inline, board, and slide-over DateCell.
A selected range lands on the start day, matching the wizard.
2026-09-04 15:59:53 -03:00

58 lines
2 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("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);
});