shoc-frontend-new/src/test/app/(protected)/workorders/wizard-step-vendor-time-closability.test.tsx
Arthur Bassi 3ed8600beb fix(work-orders): promote dated pre-schedule picks to Scheduled
Align create, wizard, and board status patches with AAP maybeAutoSchedule.
Include the previous status in audit copy when the API sends it.
2026-09-04 14:31:08 -03:00

101 lines
3.5 KiB
TypeScript

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(
<WizardStepVendorTime
draft={{ ...EMPTY_WIZARD_DRAFT, type: "PM", status: "Incomplete" }}
vendors={[]}
onUpdate={vi.fn()}
onPatch={vi.fn()}
/>,
);
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(
<WizardStepVendorTime
draft={{ ...EMPTY_WIZARD_DRAFT, type: "PM", status: "Incomplete" }}
vendors={[]}
onUpdate={vi.fn()}
onPatch={vi.fn()}
/>,
);
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(
<WizardStepVendorTime
draft={{ ...EMPTY_WIZARD_DRAFT, type: "PM", status: "Incomplete" }}
vendors={[]}
onUpdate={onUpdate}
onPatch={vi.fn()}
/>,
);
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(
<WizardStepVendorTime
draft={{ ...EMPTY_WIZARD_DRAFT, type: "PM", status: "Incomplete" }}
vendors={[]}
onUpdate={vi.fn()}
onPatch={onPatch}
/>,
);
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(
<WizardStepVendorTime
draft={{
...EMPTY_WIZARD_DRAFT,
type: "PM",
status: "Scheduled",
scheduledOn: "2026-06-01",
scheduleWeekOnly: false,
}}
vendors={[]}
onUpdate={vi.fn()}
onPatch={onPatch}
/>,
);
fireEvent.click(screen.getByRole("button", { name: /scheduled/i }));
fireEvent.click(screen.getByRole("button", { name: /^pending$/i }));
expect(onPatch).toHaveBeenCalledWith({ status: "Scheduled" });
});
});