shoc-frontend-new/src/test/app/(protected)/workorders/vendor-dialog-add-technician.test.tsx
Arthur Bassi a30ac73d29
Some checks are pending
CI / ci (push) Waiting to run
CI / governance (push) Waiting to run
CI / vendor-visual-regression (push) Waiting to run
Deploy / deploy (push) Waiting to run
feat(work-orders): draft technician until vendor dialog save (SH-193) (#89)
* docs(work-orders): add pending BE contract checklist for design parity gaps

* feat(work-orders): add technician affordance in wo vendor dialog

* fix(work-orders): defer technician create until vendor dialog save

* docs(work-orders): align pr description with jira and qa residuals

* fix(vendors): harden draft technician optional field typing

* refactor(workorders): extract vendor dialog body footer and save hook

* fix(work-orders): coerce null company vendor for add-technician prop

* fix(work-orders): preserve draft technician staging on save [SH-193]

* fix(work-orders): select technicians by stable id [SH-193]

Keep selectedKey as explicit dialog state (SiteDialog pattern) so same-name drafts do not collide with existing vendors, and cover the regression with interaction tests.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Alexandre Brandizzi <alex_brandizzi@hotmail.com>
2026-08-11 14:01:31 -03:00

51 lines
1.8 KiB
TypeScript

import { fireEvent, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { VendorDialogAddTechnician } from "@/app/(protected)/workorders/_components/list/table/cells/vendor-dialog-add-technician";
import type { VendorDropdownItem } from "@/domain/work-orders/types/work-order";
import { isDraftVendorId } from "@/domain/vendors/utils/draft-vendor";
import { renderWithProviders } from "@/test/test-utils";
const companyVendor: VendorDropdownItem = {
id: 10,
companyName: "Gateway Plumbing",
contactName: "Adam Whyte",
tradeSpecialties: "Plumbing",
address: "1 Main St",
distanceMiles: 4.2,
email: "dispatch@gateway.test",
};
describe("VendorDialogAddTechnician", () => {
it("stages a draft technician locally without calling the create API", () => {
const onCreated = vi.fn();
renderWithProviders(
<VendorDialogAddTechnician
companyName="Gateway Plumbing"
companyVendor={companyVendor}
onCreated={onCreated}
/>,
);
fireEvent.click(screen.getByRole("button", { name: /\+ add technician/i }));
fireEvent.change(screen.getByPlaceholderText("Full name"), {
target: { value: "Jordan Lee" },
});
fireEvent.change(screen.getByPlaceholderText("(000) 000-0000"), {
target: { value: "3145550199" },
});
fireEvent.click(screen.getByRole("button", { name: /^add$/i }));
expect(onCreated).toHaveBeenCalledTimes(1);
const [draftVendor, phone, payload] = onCreated.mock.calls[0] ?? [];
expect(isDraftVendorId(draftVendor.id)).toBe(true);
expect(draftVendor.contactName).toBe("Jordan Lee");
expect(phone).toBeTruthy();
expect(payload).toEqual(
expect.objectContaining({
companyName: "Gateway Plumbing",
contactName: "Jordan Lee",
}),
);
});
});