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 Appt Time", () => { it("marks Appt Time as optional", () => { render( , ); expect(screen.getByText("Appt Time")).toBeInTheDocument(); expect(screen.getAllByText("optional").length).toBeGreaterThan(0); }); }); describe("WizardStepVendorTime creation statuses (AAP)", () => { it("offers only Incomplete, Pending, and Scheduled", () => { render( , ); fireEvent.click(screen.getByRole("button", { name: /incomplete/i })); expect(screen.getByRole("button", { name: /^pending$/i })).toBeInTheDocument(); expect(screen.getByRole("button", { name: /^scheduled$/i })).toBeInTheDocument(); expect(screen.queryByRole("button", { name: /^completed$/i })).not.toBeInTheDocument(); expect(screen.queryByRole("button", { name: /^en route$/i })).not.toBeInTheDocument(); }); it("disables Scheduled without a concrete date", () => { const onUpdate = vi.fn(); render( , ); fireEvent.click(screen.getByRole("button", { name: /incomplete/i })); const scheduled = screen.getByRole("button", { name: /^scheduled$/i }); expect(scheduled).toBeDisabled(); expect(scheduled).toHaveAttribute( "title", "Set a Schedule On date before marking this work order as Scheduled.", ); fireEvent.click(scheduled); expect(onUpdate).not.toHaveBeenCalledWith("status", "Scheduled"); }); it("allows selecting a non-Completed status", () => { const onPatch = 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(onPatch).toHaveBeenCalledWith({ status: "Pending" }); }); it("promotes Pending to Scheduled when picked on a dated draft", () => { const onPatch = vi.fn(); render( , ); fireEvent.click(screen.getByRole("button", { name: /scheduled/i })); fireEvent.click(screen.getByRole("button", { name: /^pending$/i })); expect(onPatch).toHaveBeenCalledWith({ status: "Scheduled" }); }); });