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.
mail-yubao/tests/unit/cc-forecast-form-order.test.ts

126 lines
3.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { describe, expect, it } from "vitest";
import { buildCcForecastFormValue } from "@/components/CcForecastFormOrder";
describe("buildCcForecastFormValue", () => {
it("maps header + modules to FormOrder fields", () => {
const v = buildCcForecastFormValue({
customerName: "新辰泽",
header: {
F_TransMode: 0,
F_OperationType: 0,
F_ContainerNo: "WHSU8127240",
F_CabinetType: "40HQ",
F_ETD: "2026-04-25",
F_ETA: "2026-05-15",
F_Dock: "洛杉矶",
F_BLCopyCode: "WHLC027G597465",
F_Classis: 0,
F_Instruction: "船名航次 HMM EMERALD 013E",
F_MemoRemark: "提拆派组合柜-不带托架",
},
modules: {
customer_name: "新辰泽",
port: "洛杉矶",
vessel_voyage: "HMM EMERALD 013E",
service: "提拆派组合柜",
classis: 0,
},
});
expect(v.customerName).toBe("新辰泽");
expect(v.F_ContainerNo).toBe("WHSU8127240");
expect(v.F_CabinetType).toBe("40HQ");
expect(v.F_Dock).toBe("洛杉矶");
expect(v.F_BLCopyCode).toBe("WHLC027G597465");
expect(v.F_ETD).toBe("2026-04-25");
expect(v.F_ETA).toBe("2026-05-15");
expect(v.F_TransMode).toBe(0);
expect(v.F_OperationType).toBe(0);
expect(v.F_Classis).toBe(0);
expect(v.F_Instruction).toContain("HMM EMERALD");
});
it("does not invent 柜型 or other optional fields", () => {
const v = buildCcForecastFormValue({
customerName: "YWZD",
header: {
F_ContainerNo: "TRHU8524770",
F_BLCopyCode: "EGLV143661466958",
F_OperationType: 2,
F_Classis: 0,
F_MemoRemark: "封号:EMCEJJ0635",
},
});
expect(v.F_CabinetType).toBe("");
expect(v.F_ETD).toBe("");
expect(v.F_ETA).toBe("");
expect(v.F_LoadPort).toBe("");
expect(v.F_Dock).toBe("");
expect(v.F_ContainerId).toBe("");
expect(v.F_CustomerService).toBe("");
expect(v.F_TransMode).toBeUndefined();
expect(v.F_OperationType).toBe(2);
expect(v.F_Classis).toBe(0);
expect(v.F_MemoRemark).toBe("封号:EMCEJJ0635");
});
it("falls back modules when header empty", () => {
const v = buildCcForecastFormValue({
modules: {
customer_name: "A",
container_no: "ABCD1234567",
cabinet_type: "20GP",
bl_no: "BL1",
port: "LA",
vessel_voyage: "V1",
},
});
expect(v.F_ContainerNo).toBe("ABCD1234567");
expect(v.F_CabinetType).toBe("20GP");
expect(v.F_BLCopyCode).toBe("BL1");
expect(v.F_Dock).toBe("洛杉矶");
expect(v.F_Instruction).toBe("船名航次 V1");
});
it("clears customer/memo that reuse container number", () => {
const v = buildCcForecastFormValue({
customerName: "回复:柜号:TRHU8524770",
header: {
F_ContainerNo: "TRHU8524770",
F_BLCopyCode: "EGLV143661466958",
F_Dock: "提单号:EGLV143661466958",
F_MemoRemark: "回复:柜号:TRHU8524770 / 不带车架",
F_Classis: 0,
F_OperationType: 2,
},
modules: {
customer_name: "回复:柜号:TRHU8524770",
container_no: "TRHU8524770",
bl_no: "EGLV143661466958",
port: "提单号:EGLV143661466958",
service: "不带车架",
},
});
expect(v.customerName).toBe("");
expect(v.F_ContainerNo).toBe("TRHU8524770");
expect(v.F_BLCopyCode).toBe("EGLV143661466958");
expect(v.F_Dock).toBe("");
expect(v.F_MemoRemark).toBe("不带车架");
});
it("keeps 封号 in memo and does not treat it as customer", () => {
const v = buildCcForecastFormValue({
customerName: "YWZD",
header: {
F_ContainerNo: "TRHU8524770",
F_BLCopyCode: "EGLV143661466958",
F_MemoRemark: "封号:EMCEJJ0635",
F_Classis: 0,
F_OperationType: 2,
},
});
expect(v.customerName).toBe("YWZD");
expect(v.F_MemoRemark).toBe("封号:EMCEJJ0635");
});
});