import { describe, expect, it } from "vitest"; import { formatWidgetQuoteTierLabel, mergeWidgetTabQuotePrice, } from "@/workers/rpa/quote-capture/widget-truck-tab-quotes"; import { validateQuoteSchema } from "@/workers/rpa/quote-capture/quote-schema-validator"; import type { QuoteItem } from "@/modules/providers/quote-provider"; function item(serviceLevel: string, rateOption: string, rawTotal: number): QuoteItem { return { serviceLevel, rateOption, carrier: "Mothership", transitDays: "—", transitDescription: "—", rawFreight: rawTotal, surcharges: 0, rawTotal, }; } describe("formatWidgetQuoteTierLabel", () => { it("Shared truck · Best value 文案", () => { expect(formatWidgetQuoteTierLabel(item("standard", "bestValue", 81.71))).toBe( "standard/bestValue (Shared truck · Best value)", ); }); it("Dedicated truck 文案", () => { expect(formatWidgetQuoteTierLabel(item("dedicated", "bestValue", 246.11))).toBe( "dedicated/bestValue (Dedicated truck)", ); }); }); describe("mergeWidgetTabQuotePrice", () => { it("Tab 价覆盖金额但保留 axel 时效", () => { const axel: QuoteItem = { ...item("standard", "bestValue", 80), transitDays: "3 business days", transitDescription: "3 个工作日", carrier: "Mothership Carrier", }; const tab = item("standard", "bestValue", 81.71); const merged = mergeWidgetTabQuotePrice(axel, tab); const dedicated = mergeWidgetTabQuotePrice( undefined, item("dedicated", "bestValue", 246.11), ); expect(merged.rawTotal).toBe(81.71); expect(merged.transitDays).toBe("3 business days"); expect(dedicated.transitDays).toBe("待确认"); expect(validateQuoteSchema([merged, dedicated])).toHaveLength(2); }); });