|
|
import { describe, expect, it } from "vitest";
|
|
|
import {
|
|
|
extractMothershipPortalMessagesFromAlerts,
|
|
|
extractMothershipPortalQuoteMessages,
|
|
|
formatMothershipPortalQuoteMessage,
|
|
|
isPortalHardBusinessBlock,
|
|
|
isPortalNeedsDetailsMessage,
|
|
|
looksLikePortalBusinessAlert,
|
|
|
translatePortalMessageToZh,
|
|
|
} from "@/lib/mothership/portal-quote-messages";
|
|
|
|
|
|
describe("portal-quote-messages", () => {
|
|
|
it("合并 No rates + required fields", () => {
|
|
|
const body =
|
|
|
"Nicotine/Tobacco\nNo rates found\nPlease review all required fields to proceed.";
|
|
|
const msgs = extractMothershipPortalQuoteMessages(body);
|
|
|
expect(msgs).toContain(
|
|
|
"No rates found\nPlease review all required fields to proceed",
|
|
|
);
|
|
|
});
|
|
|
|
|
|
it("必填提示判为 NEEDS_DETAILS,不按硬拒价", () => {
|
|
|
const zh = translatePortalMessageToZh(
|
|
|
"No rates found\nPlease review all required fields to proceed",
|
|
|
);
|
|
|
expect(isPortalNeedsDetailsMessage(zh)).toBe(true);
|
|
|
expect(isPortalHardBusinessBlock(zh)).toBe(false);
|
|
|
expect(isPortalNeedsDetailsMessage("Please review all required fields")).toBe(
|
|
|
true,
|
|
|
);
|
|
|
});
|
|
|
|
|
|
it("lane 无价 toast 判为硬拒价", () => {
|
|
|
const zh = translatePortalMessageToZh(
|
|
|
"Unfortunately we were unable to find any rates for this lane and freight details.",
|
|
|
);
|
|
|
expect(isPortalHardBusinessBlock(zh)).toBe(true);
|
|
|
expect(isPortalNeedsDetailsMessage(zh)).toBe(false);
|
|
|
});
|
|
|
|
|
|
it("同时出现 lane 无价与 required fields → 硬拒,禁止引导补二级", () => {
|
|
|
const body =
|
|
|
"No rates found\nPlease review all required fields to proceed.\nUnfortunately we were unable to find any rates for this lane and freight details. Please check your shipment details and try again.";
|
|
|
const msgs = extractMothershipPortalQuoteMessages(body);
|
|
|
expect(
|
|
|
msgs.some((m) => /unable to find any rates for this lane/i.test(m)),
|
|
|
).toBe(true);
|
|
|
expect(
|
|
|
msgs.some((m) => /please review all required fields/i.test(m)),
|
|
|
).toBe(false);
|
|
|
const zh = formatMothershipPortalQuoteMessage(msgs)!;
|
|
|
expect(zh).toMatch(/该线路与货物|暂无可用报价/);
|
|
|
expect(isPortalHardBusinessBlock(zh)).toBe(true);
|
|
|
expect(isPortalNeedsDetailsMessage(zh)).toBe(false);
|
|
|
});
|
|
|
|
|
|
it("提取附加服务/住宅取件阻断(中文)", () => {
|
|
|
const body =
|
|
|
"不支持附加服务,我们的承运合作伙伴不提供住宅地址上门取件服务";
|
|
|
const msgs = extractMothershipPortalQuoteMessages(body);
|
|
|
expect(msgs.some((m) => m.includes("不支持附加服务"))).toBe(true);
|
|
|
});
|
|
|
|
|
|
it("提取 carrier partner residential pickup(英文)", () => {
|
|
|
const body =
|
|
|
"Unsupported accessorial. Our carrier partners do not provide residential pickup at this location.";
|
|
|
const msgs = extractMothershipPortalQuoteMessages(body);
|
|
|
expect(
|
|
|
msgs.some((m) => /carrier partners? do not provide/i.test(m)),
|
|
|
).toBe(true);
|
|
|
});
|
|
|
|
|
|
it("提取线路红色 toast:unable to find any rates for this lane", () => {
|
|
|
const body =
|
|
|
"No rates found\nPlease review all required fields to proceed.\nUnfortunately we were unable to find any rates for this lane and freight details. Please check your shipment details and try again.";
|
|
|
const msgs = extractMothershipPortalQuoteMessages(body);
|
|
|
expect(
|
|
|
msgs.some((m) => /unable to find any rates for this lane/i.test(m)),
|
|
|
).toBe(true);
|
|
|
const zh = formatMothershipPortalQuoteMessage(msgs)!;
|
|
|
expect(zh).toMatch(/该线路与货物|暂无可用报价/);
|
|
|
// 不得再附带「请填必填」以免前端走 NEEDS_DETAILS
|
|
|
expect(zh).not.toMatch(/必填/);
|
|
|
});
|
|
|
|
|
|
it("提取线路/地址类红色报错", () => {
|
|
|
const body =
|
|
|
"Unable to obtain a quote for this lane. Address is outside our service area.";
|
|
|
const msgs = extractMothershipPortalQuoteMessages(body);
|
|
|
expect(msgs.length).toBeGreaterThan(0);
|
|
|
const zh = formatMothershipPortalQuoteMessage(msgs)!;
|
|
|
expect(zh).toMatch(/报价|服务范围/);
|
|
|
});
|
|
|
|
|
|
it("Freight ready before operation hours → 中文", () => {
|
|
|
expect(
|
|
|
translatePortalMessageToZh(
|
|
|
"Freight ready time is before pickup location operation hours",
|
|
|
),
|
|
|
).toMatch(/就绪时刻不能早于提货点开门时间/);
|
|
|
});
|
|
|
|
|
|
it("format 将英文官网提示译为中文", () => {
|
|
|
const out = formatMothershipPortalQuoteMessage([
|
|
|
"No rates found",
|
|
|
"Unsupported accessorial",
|
|
|
]);
|
|
|
expect(out).toBe("未找到可用报价\n\n不支持该附加服务");
|
|
|
});
|
|
|
|
|
|
it("format 保留中文官网提示", () => {
|
|
|
const out = formatMothershipPortalQuoteMessage([
|
|
|
"不支持附加服务,承运合作伙伴不提供住宅地址上门取件",
|
|
|
]);
|
|
|
expect(out).toContain("不支持附加服务");
|
|
|
});
|
|
|
|
|
|
it("未知英文仍带回承运商提示前缀", () => {
|
|
|
const zh = translatePortalMessageToZh(
|
|
|
"Something unexpected blocked quoting XYZ",
|
|
|
);
|
|
|
expect(zh.startsWith("承运商提示:")).toBe(true);
|
|
|
expect(zh).toContain("Something unexpected");
|
|
|
});
|
|
|
|
|
|
it("DOM alert 片段可提取业务红字", () => {
|
|
|
const msgs = extractMothershipPortalMessagesFromAlerts([
|
|
|
"Got it",
|
|
|
"该线路暂无可用运力,请更换地址后重试",
|
|
|
]);
|
|
|
expect(msgs.some((m) => m.includes("该线路"))).toBe(true);
|
|
|
expect(looksLikePortalBusinessAlert("该线路暂无可用运力")).toBe(true);
|
|
|
expect(looksLikePortalBusinessAlert("Got it")).toBe(false);
|
|
|
});
|
|
|
});
|