shoc-frontend-new/src/test/app/(protected)/workorders/wizard-service-clears-vendor.test.tsx
Codex Review Integration cd5d4ad1d8 fix(work-orders): keep wizard vendor notes bound to the selected company
Late roster data no longer overwrites notes typed for the current selection.
The notes baseline is keyed by vendor, so a save never patches a previous
company. Changing the primary service clears leftover notes, and a save
with a missing baseline reads the current roster first. Also drops ticket
keys from shipped comments.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 15:18:06 -03:00

92 lines
2.5 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",
vendorNotes: "Old company notes",
};
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: "",
vendorNotes: "",
}),
);
});
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",
vendorNotes: "Old company notes",
};
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",
extraServices: [],
vendorId: "",
vendorName: "",
techPhone: "",
vendorNotes: "",
});
});
});