mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 21:42:06 +00:00
* 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>
51 lines
1.8 KiB
TypeScript
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",
|
|
}),
|
|
);
|
|
});
|
|
});
|