You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.0 KiB
103 lines
3.0 KiB
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildDisplayedCheckoutSummary,
|
|
rateKey,
|
|
} from "@/components/mothership/mothership-logged-in-quote-sidebar";
|
|
import type { QuoteItem } from "@/lib/frontend/types";
|
|
|
|
function makeQuote(overrides: Partial<QuoteItem> = {}): QuoteItem {
|
|
return {
|
|
service_level: "standard",
|
|
rate_option: "lowest",
|
|
carrier: "Mothership Direct",
|
|
transit_days: "3",
|
|
transit_description: "3 business days",
|
|
raw_freight: 1000,
|
|
surcharges: 150,
|
|
raw_total: 1150,
|
|
markup_percent: 0,
|
|
markup_amount: 0,
|
|
final_total: 1150,
|
|
breakdown: [],
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("mothership logged-in quote sidebar price summary", () => {
|
|
it("rateKey 区分同承运商不同价", () => {
|
|
const a = makeQuote({
|
|
service_level: "guaranteed",
|
|
rate_option: "bestValue",
|
|
carrier: "ABF Freight Direct",
|
|
final_total: 1344.9,
|
|
raw_total: 1344.9,
|
|
transit_days: "3",
|
|
});
|
|
const b = makeQuote({
|
|
service_level: "guaranteed",
|
|
rate_option: "bestValue",
|
|
carrier: "ABF Freight Direct",
|
|
final_total: 1478.84,
|
|
raw_total: 1478.84,
|
|
transit_days: "2",
|
|
});
|
|
expect(rateKey(a, 0)).not.toBe(rateKey(b, 1));
|
|
expect(rateKey(a, 0)).not.toBe(rateKey(a, 1));
|
|
});
|
|
|
|
it("基础保障仅展示最终报价,不展示加价明细", () => {
|
|
const summary = buildDisplayedCheckoutSummary({
|
|
item: makeQuote({
|
|
markup_percent: 3,
|
|
markup_amount: 30,
|
|
final_total: 1180,
|
|
}),
|
|
coverage: "basic",
|
|
checkout: null,
|
|
});
|
|
expect(summary.headline).toContain("$1,180.00");
|
|
expect(summary.details).toBeNull();
|
|
expect(summary.headline).not.toContain("原价");
|
|
expect(summary.headline).not.toContain("客户加价");
|
|
});
|
|
|
|
it("FreightProtect 未确认时,不把承运商价冒充最终价", () => {
|
|
const summary = buildDisplayedCheckoutSummary({
|
|
item: makeQuote({
|
|
markup_amount: 30,
|
|
final_total: 1180,
|
|
}),
|
|
coverage: "full",
|
|
checkout: null,
|
|
});
|
|
expect(summary.headline).toContain("承运商价");
|
|
expect(summary.details).toContain("保障后总价待确认");
|
|
expect(summary.details).not.toContain("原价");
|
|
expect(summary.details).not.toContain("客户加价");
|
|
expect(summary.ctaAmountLabel).toBeNull();
|
|
});
|
|
|
|
it("FreightProtect 已确认后,显示确认总价", () => {
|
|
const summary = buildDisplayedCheckoutSummary({
|
|
item: makeQuote({
|
|
markup_amount: 30,
|
|
final_total: 1180,
|
|
}),
|
|
coverage: "full",
|
|
checkout: {
|
|
status: "done",
|
|
selected_total: 1202.55,
|
|
coverage: "freight_protect",
|
|
cargo_value_usd: 5000,
|
|
stage: "review",
|
|
selected_carrier: "Mothership Direct",
|
|
message: "已填齐详情(未支付)",
|
|
},
|
|
});
|
|
expect(summary.headline).toContain("确认价");
|
|
expect(summary.details).toContain("$1,202.55");
|
|
expect(summary.details).not.toContain("原价");
|
|
expect(summary.ctaAmountLabel).toBe("$1,202.55");
|
|
});
|
|
});
|