mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 07:42:04 +00:00
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import { resolveTechnicianKey } from "@/app/(protected)/workorders/_components/list/table/cells/resolve-technician-key";
|
||
|
|
import type { VendorDropdownItem } from "@/domain/work-orders/types/work-order";
|
||
|
|
|
||
|
|
const vendors: VendorDropdownItem[] = [
|
||
|
|
{
|
||
|
|
id: 10,
|
||
|
|
companyName: "Gateway Plumbing",
|
||
|
|
contactName: "Jordan Lee",
|
||
|
|
tradeSpecialties: "Plumbing",
|
||
|
|
address: "1 Main St",
|
||
|
|
distanceMiles: 4.2,
|
||
|
|
email: "dispatch@gateway.test",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
id: 11,
|
||
|
|
companyName: "Gateway Plumbing",
|
||
|
|
contactName: "Adam Whyte",
|
||
|
|
tradeSpecialties: "Plumbing",
|
||
|
|
address: "1 Main St",
|
||
|
|
distanceMiles: 4.2,
|
||
|
|
email: "dispatch@gateway.test",
|
||
|
|
},
|
||
|
|
];
|
||
|
|
|
||
|
|
describe("resolveTechnicianKey", () => {
|
||
|
|
it("prefers a stable vendorId when it exists in the list", () => {
|
||
|
|
expect(resolveTechnicianKey(11, "Jordan Lee", "Gateway Plumbing", vendors)).toBe("11");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("falls back to name+company when vendorId is missing", () => {
|
||
|
|
expect(resolveTechnicianKey("", "Jordan Lee", "Gateway Plumbing", vendors)).toBe("10");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("keeps orphan tech string as key when no vendor matches", () => {
|
||
|
|
expect(resolveTechnicianKey("", "Unknown Tech", "Gateway Plumbing", vendors)).toBe(
|
||
|
|
"Unknown Tech",
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("keeps vendorId when the vendors list is still empty", () => {
|
||
|
|
expect(resolveTechnicianKey(42, "Jordan Lee", "Gateway Plumbing", [])).toBe("42");
|
||
|
|
});
|
||
|
|
});
|