mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 12:49:00 +00:00
45 lines
1.7 KiB
TypeScript
45 lines
1.7 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 closability gate", () => {
|
||
|
|
it("disables Completed when closability requirements are missing", () => {
|
||
|
|
const onUpdate = vi.fn();
|
||
|
|
render(
|
||
|
|
<WizardStepVendorTime
|
||
|
|
draft={{ ...EMPTY_WIZARD_DRAFT, type: "PM", status: "Scheduled" }}
|
||
|
|
vendors={[]}
|
||
|
|
onUpdate={onUpdate}
|
||
|
|
onPatch={vi.fn()}
|
||
|
|
/>,
|
||
|
|
);
|
||
|
|
|
||
|
|
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(
|
||
|
|
<WizardStepVendorTime
|
||
|
|
draft={{ ...EMPTY_WIZARD_DRAFT, type: "PM", status: "Incomplete" }}
|
||
|
|
vendors={[]}
|
||
|
|
onUpdate={onUpdate}
|
||
|
|
onPatch={vi.fn()}
|
||
|
|
/>,
|
||
|
|
);
|
||
|
|
|
||
|
|
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");
|
||
|
|
});
|
||
|
|
});
|