shoc-frontend-new/src/test/app/(protected)/workorders/vendor-dialog-can-submit.test.ts

95 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
computeVendorDialogCanSubmit,
type VendorDialogSubmitSnapshot,
} from "@/app/(protected)/workorders/_components/list/table/cells/vendor-dialog-can-submit";
const empty: VendorDialogSubmitSnapshot = {
company: "",
selectedKey: "",
phone: "",
notes: "",
pendingCreateCount: 0,
};
const assigned: VendorDialogSubmitSnapshot = {
company: "Gateway Plumbing",
selectedKey: "10",
phone: "(314) 555-0100",
notes: "",
pendingCreateCount: 0,
};
describe("computeVendorDialogCanSubmit", () => {
it("rejects an empty untouched assignment", () => {
expect(
computeVendorDialogCanSubmit({
current: empty,
baseline: empty,
}),
).toBe(false);
});
it("rejects an existing assignment with no field changes", () => {
expect(
computeVendorDialogCanSubmit({
current: assigned,
baseline: assigned,
}),
).toBe(false);
});
it("allows save after the technician key changes", () => {
expect(
computeVendorDialogCanSubmit({
current: { ...assigned, selectedKey: "11" },
baseline: assigned,
}),
).toBe(true);
});
it("allows save when a new technician is staged", () => {
expect(
computeVendorDialogCanSubmit({
current: { ...assigned, selectedKey: "draft-1", pendingCreateCount: 1 },
baseline: assigned,
}),
).toBe(true);
});
it("rejects notes-only changes because notes are not persisted", () => {
expect(
computeVendorDialogCanSubmit({
current: { ...assigned, notes: "Call before arrival" },
baseline: assigned,
}),
).toBe(false);
});
it("does not allow notes-only save without a company or technician", () => {
expect(
computeVendorDialogCanSubmit({
current: { ...empty, notes: "Call before arrival" },
baseline: empty,
}),
).toBe(false);
});
it("allows a company-only assignment", () => {
expect(
computeVendorDialogCanSubmit({
current: { ...empty, company: "Gateway Plumbing" },
baseline: empty,
}),
).toBe(true);
});
it("rejects a technician without a company", () => {
expect(
computeVendorDialogCanSubmit({
current: { ...empty, selectedKey: "10" },
baseline: empty,
}),
).toBe(false);
});
});