import { fireEvent, render, screen, within } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { WizardStepVendorTime } from "@/app/(protected)/workorders/_components/wizard/wizard-step-vendor-time"; import { EMPTY_WIZARD_DRAFT } from "@/domain/work-orders/types/work-order-wizard"; describe("WizardStepVendorTime closability gate", () => { it("disables Completed when closability requirements are missing", () => { const onUpdate = vi.fn(); render( , ); fireEvent.click(screen.getByRole("button", { name: /scheduled/i })); const completed = screen.getByRole("button", { name: /^completed$/i }); expect(completed).toBeDisabled(); expect(completed).toHaveAttribute("title", expect.stringContaining("Missing:")); fireEvent.click(completed); expect(onUpdate).not.toHaveBeenCalledWith("status", "Completed"); }); it("allows selecting a non-Completed status", () => { const onUpdate = vi.fn(); render( , ); fireEvent.click(screen.getByRole("button", { name: /incomplete/i })); const menu = screen.getByRole("button", { name: /^pending$/i }).closest("div"); expect(menu).not.toBeNull(); fireEvent.click(within(menu!.parentElement!).getByRole("button", { name: /^pending$/i })); expect(onUpdate).toHaveBeenCalledWith("status", "Pending"); }); });