fix(work-orders): confirm cleared vendor saves

This commit is contained in:
Codex Review Integration 2026-08-26 19:47:57 -03:00
parent 8d755bcb11
commit 2b17de2212
2 changed files with 25 additions and 9 deletions

View file

@ -76,9 +76,7 @@ export function applyVendorTableSave(
id: string | number, id: string | number,
fields: VendorAssignmentFields, fields: VendorAssignmentFields,
) { ) {
onPatch( onPatch(id, toVendorTablePatch(fields), {
id, onSuccess: isAssignedVendorId(fields.vendorId) ? notifyVendorAssigned : notifyWorkOrderSaved,
toVendorTablePatch(fields), });
isAssignedVendorId(fields.vendorId) ? { onSuccess: notifyVendorAssigned } : undefined,
);
} }

View file

@ -71,7 +71,7 @@ describe("work-order-feedback-toasts", () => {
expect(toast.warning).not.toHaveBeenCalled(); expect(toast.warning).not.toHaveBeenCalled();
}); });
it("persists an empty vendor without an assigned toast", () => { it("shows generic save success for an empty vendor after persistence", () => {
const onPatch = vi.fn(); const onPatch = vi.fn();
const fields = { const fields = {
vendorId: "", vendorId: "",
@ -81,11 +81,20 @@ describe("work-order-feedback-toasts", () => {
}; };
applyVendorTableSave(onPatch, 7, fields); applyVendorTableSave(onPatch, 7, fields);
expect(onPatch).toHaveBeenCalledWith(7, toVendorTablePatch(fields), undefined); expect(onPatch).toHaveBeenCalledWith(
7,
toVendorTablePatch(fields),
expect.objectContaining({ onSuccess: expect.any(Function) }),
);
expect(toast.success).not.toHaveBeenCalled(); expect(toast.success).not.toHaveBeenCalled();
const { onSuccess } = onPatch.mock.calls[0][2] as { onSuccess: () => void };
onSuccess();
expect(toast.success).toHaveBeenCalledWith(workOrderSavedMessage());
expect(toast.success).not.toHaveBeenCalledWith(vendorAssignedMessage());
}); });
it("persists a whitespace vendorId without an assigned toast", () => { it("shows generic save success for a whitespace vendor id after persistence", () => {
const onPatch = vi.fn(); const onPatch = vi.fn();
const fields = { const fields = {
vendorId: " ", vendorId: " ",
@ -95,8 +104,17 @@ describe("work-order-feedback-toasts", () => {
}; };
applyVendorTableSave(onPatch, 7, fields); applyVendorTableSave(onPatch, 7, fields);
expect(onPatch).toHaveBeenCalledWith(7, toVendorTablePatch(fields), undefined); expect(onPatch).toHaveBeenCalledWith(
7,
toVendorTablePatch(fields),
expect.objectContaining({ onSuccess: expect.any(Function) }),
);
expect(toast.success).not.toHaveBeenCalled(); expect(toast.success).not.toHaveBeenCalled();
const { onSuccess } = onPatch.mock.calls[0][2] as { onSuccess: () => void };
onSuccess();
expect(toast.success).toHaveBeenCalledWith(workOrderSavedMessage());
expect(toast.success).not.toHaveBeenCalledWith(vendorAssignedMessage());
}); });
it("toasts vendor assignment when a slide-over patch includes a vendor id", () => { it("toasts vendor assignment when a slide-over patch includes a vendor id", () => {