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(
,
);
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(
,
);
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);
});