- Updated the `scoreQuote` function to incorporate price scoring, allowing quotes to be evaluated based on selling and cost prices when the query is numeric. - Introduced new weights for item selling and cost prices, ensuring they contribute to the overall score only when relevant. - Enhanced the test suite to cover new price matching scenarios, ensuring accurate scoring behavior for quotes based on price inputs. - Refactored related functions to support the new price scoring logic, maintaining consistency across the scoring process.
102 lines
4.3 KiB
TypeScript
102 lines
4.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import {
|
|
ITEM_STATUS_VISUAL,
|
|
TAB_GROUP_ITEM_STATUSES,
|
|
itemStatusToTabGroup,
|
|
tabGroupFilter,
|
|
getItemStatusVisual,
|
|
} from "./item-status-ui";
|
|
|
|
describe("ITEM_STATUS_VISUAL — ready_delivery", () => {
|
|
it("is labelled 'Ready for Collection' (NOT 'Collected')", () => {
|
|
// ready_delivery means "supplier confirmed ready for pickup" —
|
|
// it sits BEFORE the collection-pool flow. Calling it
|
|
// "Collected" makes the operator think the driver already
|
|
// picked the goods up.
|
|
expect(ITEM_STATUS_VISUAL.ready_delivery.label).toBe("Ready for Collection");
|
|
});
|
|
|
|
it("is visually distinct from the actual `collected` status", () => {
|
|
// Different label and different hex so the per-item pill is
|
|
// unambiguous in the order row.
|
|
expect(ITEM_STATUS_VISUAL.ready_delivery.label).not.toBe(
|
|
ITEM_STATUS_VISUAL.collected.label,
|
|
);
|
|
expect(ITEM_STATUS_VISUAL.ready_delivery.hex).not.toBe(
|
|
ITEM_STATUS_VISUAL.collected.hex,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("TAB_GROUP_ITEM_STATUSES — ready_delivery belongs to collection_pool", () => {
|
|
it("is in the collection_pool tab group, not the collected tab group", () => {
|
|
expect(TAB_GROUP_ITEM_STATUSES.collection_pool).toContain("ready_delivery");
|
|
expect(TAB_GROUP_ITEM_STATUSES.collected).not.toContain("ready_delivery");
|
|
});
|
|
|
|
it("ready_delivery maps to the collection_pool tab group", () => {
|
|
expect(itemStatusToTabGroup("ready_delivery")).toBe("collection_pool");
|
|
});
|
|
});
|
|
|
|
describe("TAB_GROUP_ITEM_STATUSES — completed belongs to the completed tab", () => {
|
|
// Regression: previously `completed` was nested inside the
|
|
// `collected` group, which made it visible on the active
|
|
// workflow tabs long after it should have aged out. The new
|
|
// `completed` tab is the only place to find these items, with
|
|
// a 30-day time-window applied at the service layer.
|
|
it("is in the completed tab group, not the collected tab group", () => {
|
|
expect(TAB_GROUP_ITEM_STATUSES.completed).toContain("completed");
|
|
expect(TAB_GROUP_ITEM_STATUSES.collected).not.toContain("completed");
|
|
});
|
|
|
|
it("delivered maps to the completed tab group (the time-windowed slice)", () => {
|
|
// The partition deliberately lists `delivered` under BOTH
|
|
// `completed` and `delivered` — the freshness check (see
|
|
// `completedTabFilter` in orders-service.ts) is what splits
|
|
// recent delivered rows from archived ones. This test pins
|
|
// the partition side of that contract.
|
|
expect(TAB_GROUP_ITEM_STATUSES.completed).toContain("delivered");
|
|
expect(TAB_GROUP_ITEM_STATUSES.delivered).toContain("delivered");
|
|
});
|
|
|
|
it("completed maps to the completed tab group", () => {
|
|
expect(itemStatusToTabGroup("completed")).toBe("completed");
|
|
});
|
|
|
|
it("delivered maps to the completed tab (first match wins in TAB_GROUP_ORDER)", () => {
|
|
// `itemStatusToTabGroup` returns the FIRST tab in TAB_GROUP_ORDER
|
|
// whose status set contains the status. With `completed` listed
|
|
// before `delivered` in that array, a `delivered` row resolves
|
|
// to `completed`. The time-window filter at the service layer
|
|
// is what separates "recent delivered" (Completed tab) from
|
|
// "old delivered" (Delivered tab on /orders/archive).
|
|
expect(itemStatusToTabGroup("delivered")).toBe("completed");
|
|
});
|
|
});
|
|
|
|
describe("tabGroupFilter", () => {
|
|
it("emits a PB-friendly filter for the collection_pool tab", () => {
|
|
// ready_delivery must show up under the collection_pool filter
|
|
// so an order containing a marked-ready item appears on that tab.
|
|
const filter = tabGroupFilter("collection_pool");
|
|
expect(filter).toContain(`item_status = "ready_delivery"`);
|
|
expect(filter).toContain(`item_status = "collection_pool"`);
|
|
expect(filter).toContain(`item_status = "assigned"`);
|
|
});
|
|
|
|
it("does NOT include ready_delivery under the collected filter", () => {
|
|
expect(tabGroupFilter("collected")).not.toContain("ready_delivery");
|
|
});
|
|
});
|
|
|
|
describe("getItemStatusVisual", () => {
|
|
it("returns the 'Ready for Collection' visual for ready_delivery", () => {
|
|
expect(getItemStatusVisual("ready_delivery").label).toBe("Ready for Collection");
|
|
});
|
|
|
|
it("falls back to a sane visual for unknown statuses", () => {
|
|
const v = getItemStatusVisual("definitely-not-a-real-status");
|
|
expect(v.label).toBe("Unknown");
|
|
});
|
|
});
|