38 lines
No EOL
1.4 KiB
TypeScript
38 lines
No EOL
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { colorForOrder, ORDER_COLOR_PALETTE } from "./order-color";
|
|
|
|
describe("colorForOrder", () => {
|
|
it("returns the first palette entry for empty/null/undefined", () => {
|
|
expect(colorForOrder("")).toBe(ORDER_COLOR_PALETTE[0]);
|
|
expect(colorForOrder(null)).toBe(ORDER_COLOR_PALETTE[0]);
|
|
expect(colorForOrder(undefined)).toBe(ORDER_COLOR_PALETTE[0]);
|
|
});
|
|
|
|
it("is deterministic for the same id", () => {
|
|
const a = colorForOrder("PO-2026-07-009");
|
|
const b = colorForOrder("PO-2026-07-009");
|
|
expect(a).toBe(b);
|
|
});
|
|
|
|
it("returns an entry from the palette", () => {
|
|
const result = colorForOrder("PO-2026-07-009");
|
|
expect(ORDER_COLOR_PALETTE).toContain(result);
|
|
});
|
|
|
|
it("distributes 60 distinct ids across at least 4 of the 6 palette entries", () => {
|
|
const seen = new Set<string>();
|
|
for (let i = 0; i < 60; i++) {
|
|
seen.add(colorForOrder(`PO-2026-${i.toString().padStart(2, "0")}-001`).borderClass);
|
|
}
|
|
expect(seen.size).toBeGreaterThanOrEqual(4);
|
|
});
|
|
|
|
it("returns a stable, known entry for a known id", () => {
|
|
// Locks in the hash function. If the implementation ever changes
|
|
// (e.g. FNV-1a → FNV-1 or different prime), update this expectation
|
|
// and review the change.
|
|
expect(colorForOrder("PO-2026-07-009").borderClass).toMatch(
|
|
/^border-(emerald|sky|amber|rose|violet|teal)-500\/40$/,
|
|
);
|
|
});
|
|
}); |