|
|
import { describe, expect, it } from "vitest";
|
|
|
import { buildCcHoldFormValue } from "@/components/CcHoldMoveTypePanel";
|
|
|
import { buildCcOutStockFormValue } from "@/components/CcOutStockPanel";
|
|
|
import { buildCcSplitFormValue } from "@/components/CcSplitForm";
|
|
|
import {
|
|
|
isHoldSplitOpsMail,
|
|
|
resolveHoldSplitSubIntent,
|
|
|
} from "@/services/parse/mail-intent";
|
|
|
import { resolveOpsChannelCounts } from "@/services/parse/ops-subject-template";
|
|
|
import type { ShipmentRow } from "@/types/mail";
|
|
|
|
|
|
const MAIL3_SUBJECT =
|
|
|
"Fw: 转发:派送要求更新: 拆柜清单更新: DO请查收+拆柜清单更新: WHSU5574991+WHL063G550810+船名航次:OOCL SINGAPORE / 065W+ETA:6/28+FedEx-29件+UPS-102件+亚马逊卡派-289件+私人地址-166件+拦截-209件+拆柜清单";
|
|
|
|
|
|
describe("resolveHoldSplitSubIntent", () => {
|
|
|
it("defaults mail3 拆柜清单 to hold (no 拆分 keyword)", () => {
|
|
|
expect(
|
|
|
resolveHoldSplitSubIntent({ subject: MAIL3_SUBJECT }),
|
|
|
).toBe("hold");
|
|
|
});
|
|
|
|
|
|
it("maps 拆分 keyword to split", () => {
|
|
|
expect(
|
|
|
resolveHoldSplitSubIntent({
|
|
|
subject: "请拆分货件 WHSU5574991",
|
|
|
}),
|
|
|
).toBe("split");
|
|
|
});
|
|
|
|
|
|
it("maps 出库 keyword / filename to outbound", () => {
|
|
|
expect(
|
|
|
resolveHoldSplitSubIntent({
|
|
|
subject: "作业通知",
|
|
|
filenames: ["YT2604021091=76件换标走HIA1卡派出库操作指令.xlsx"],
|
|
|
}),
|
|
|
).toBe("outbound");
|
|
|
});
|
|
|
|
|
|
it("priority: 出库 wins over 拆分", () => {
|
|
|
expect(
|
|
|
resolveHoldSplitSubIntent({
|
|
|
subject: "拆分后出库",
|
|
|
}),
|
|
|
).toBe("outbound");
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe("isHoldSplitOpsMail", () => {
|
|
|
it("detects mail3 style subject", () => {
|
|
|
expect(
|
|
|
isHoldSplitOpsMail({
|
|
|
mailType: "WORK_ORDER",
|
|
|
subject: MAIL3_SUBJECT,
|
|
|
isForecast: false,
|
|
|
isTransfer: false,
|
|
|
}),
|
|
|
).toBe(true);
|
|
|
});
|
|
|
|
|
|
it("excludes forecast and transfer", () => {
|
|
|
expect(
|
|
|
isHoldSplitOpsMail({
|
|
|
mailType: "NEW_CONTAINER",
|
|
|
subject: MAIL3_SUBJECT,
|
|
|
isForecast: true,
|
|
|
isTransfer: false,
|
|
|
}),
|
|
|
).toBe(false);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe("resolveOpsChannelCounts", () => {
|
|
|
it("re-parses channels from subject when record empty", () => {
|
|
|
const ch = resolveOpsChannelCounts({ subject: MAIL3_SUBJECT });
|
|
|
expect(ch).toEqual(
|
|
|
expect.arrayContaining([
|
|
|
{ channel: "FedEx", ctns: 29 },
|
|
|
{ channel: "拦截", ctns: 209 },
|
|
|
]),
|
|
|
);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe("buildCcHoldFormValue", () => {
|
|
|
it("builds hold rows from mail3 channels", () => {
|
|
|
const channels = resolveOpsChannelCounts({ subject: MAIL3_SUBJECT });
|
|
|
const { value, rows } = buildCcHoldFormValue({
|
|
|
containerNo: "WHSU5574991",
|
|
|
modules: { container_no: "WHSU5574991" },
|
|
|
channels,
|
|
|
});
|
|
|
expect(value.F_Transporter).toBe("留仓");
|
|
|
expect(value.F_ContainerNo).toBe("WHSU5574991");
|
|
|
expect(rows.length).toBeGreaterThanOrEqual(5);
|
|
|
expect(rows.some((r) => /拦截|扣货/.test(r.F_Transporter))).toBe(true);
|
|
|
expect(value.selectedKeys.length).toBeGreaterThan(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe("buildCcSplitFormValue", () => {
|
|
|
it("prefills qty fields from first shipment", () => {
|
|
|
const shipments: ShipmentRow[] = [
|
|
|
{
|
|
|
row_index: 0,
|
|
|
row_status: "VALID",
|
|
|
F_FBACode: "MDW2",
|
|
|
F_CTNS: 76,
|
|
|
F_CBM: 1.2,
|
|
|
F_Weight: 300,
|
|
|
},
|
|
|
];
|
|
|
const v = buildCcSplitFormValue({
|
|
|
containerNo: "WHSU5574991",
|
|
|
shipments,
|
|
|
});
|
|
|
expect(v.F_FBACode).toBe("MDW2");
|
|
|
expect(v.F_CTNS).toBe("76");
|
|
|
expect(v.maxCTNS).toBe(76);
|
|
|
expect(v.F_CBM).toBe("1.2");
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe("buildCcOutStockFormValue", () => {
|
|
|
it("guesses TRUCK outstock from 卡派出库 filename and prefills SplitCTNS", () => {
|
|
|
const shipments: ShipmentRow[] = [
|
|
|
{
|
|
|
row_index: 0,
|
|
|
row_status: "VALID",
|
|
|
F_FBACode: "HIA1",
|
|
|
F_CTNS: 76,
|
|
|
F_FBAID: "FBA199R49LD6",
|
|
|
},
|
|
|
];
|
|
|
const v = buildCcOutStockFormValue({
|
|
|
containerNo: "TCLU1234567",
|
|
|
shipments,
|
|
|
filenames: ["YT2604021091=76件换标走HIA1卡派出库操作指令.xlsx"],
|
|
|
});
|
|
|
expect(v.header.F_OutStockType).toBe("TRUCK");
|
|
|
expect(v.shipments[0].SplitCTNS).toBe("76");
|
|
|
expect(v.shipments[0].F_FBACode).toBe("HIA1");
|
|
|
expect(v.header.F_FBACode).toBe("HIA1");
|
|
|
});
|
|
|
});
|