mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 23:02:07 +00:00
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { WizardStepLocationServiceSelect } from "@/app/(protected)/workorders/_components/wizard/wizard-step-location-service-select";
|
|
import {
|
|
EMPTY_WIZARD_DRAFT,
|
|
type WorkOrderWizardDraft,
|
|
} from "@/domain/work-orders/types/work-order-wizard";
|
|
|
|
describe("WizardStepLocationServiceSelect — vendor clear on service change", () => {
|
|
it("clears vendor fields when the primary service changes", () => {
|
|
const onPatch = vi.fn();
|
|
const draft: WorkOrderWizardDraft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
pm: "HVAC",
|
|
vendorId: "9",
|
|
vendorName: "Old Vendor",
|
|
techPhone: "555-0100",
|
|
};
|
|
|
|
render(
|
|
<WizardStepLocationServiceSelect
|
|
draft={draft}
|
|
services={[
|
|
{ id: "1", value: "HVAC" },
|
|
{ id: "2", value: "Plumbing" },
|
|
]}
|
|
svcOpen={false}
|
|
onSvcOpenChange={vi.fn()}
|
|
svcSearch=""
|
|
onSvcSearchChange={vi.fn()}
|
|
onUpdate={vi.fn()}
|
|
onPatch={onPatch}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "HVAC" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "Plumbing" }));
|
|
|
|
expect(onPatch).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
pm: "Plumbing",
|
|
extraServices: [],
|
|
vendorId: "",
|
|
vendorName: "",
|
|
techPhone: "",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("replaces the selected service in Service & Notes without persisting extraServices", () => {
|
|
const onPatch = vi.fn();
|
|
const draft: WorkOrderWizardDraft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
pm: "HVAC",
|
|
extraServices: ["Plumbing"],
|
|
vendorId: "9",
|
|
vendorName: "Old Vendor",
|
|
techPhone: "555-0100",
|
|
};
|
|
|
|
render(
|
|
<WizardStepLocationServiceSelect
|
|
draft={draft}
|
|
services={[
|
|
{ id: "1", value: "HVAC" },
|
|
{ id: "2", value: "Plumbing" },
|
|
{ id: "3", value: "Electrical" },
|
|
]}
|
|
svcOpen={true}
|
|
onSvcOpenChange={vi.fn()}
|
|
svcSearch=""
|
|
onSvcSearchChange={vi.fn()}
|
|
onUpdate={vi.fn()}
|
|
onPatch={onPatch}
|
|
/>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Electrical" }));
|
|
|
|
expect(onPatch).toHaveBeenCalledWith({
|
|
pm: "Electrical",
|
|
serviceId: "3",
|
|
extraServices: [],
|
|
vendorId: "",
|
|
vendorName: "",
|
|
techPhone: "",
|
|
});
|
|
});
|
|
});
|