|
|
import { describe, expect, it } from "vitest";
|
|
|
import {
|
|
|
columnValueFromCell,
|
|
|
parseLabeledAddressBlock,
|
|
|
parseLabeledCell,
|
|
|
} from "@/services/parse/address-block";
|
|
|
|
|
|
const SAMPLE = `仓库代码: LAS1
|
|
|
收件人: LAS1
|
|
|
公司名称: AMAZON COM SERVICES INC
|
|
|
联系电话: 0123456789
|
|
|
省/市/区: NV / HENDERSON /
|
|
|
邮政编码: 89044-8746
|
|
|
收货地址: 12300 Bermuda Road
|
|
|
备注:三票分开打托`;
|
|
|
|
|
|
describe("parseLabeledCell", () => {
|
|
|
it("takes the home field and still harvests the rest", () => {
|
|
|
const p = parseLabeledCell(
|
|
|
"仓库代码: LAS1\n收件人: LAS1\n收货地址: 12300 Bermuda Road",
|
|
|
);
|
|
|
expect(p?.F_FBACode).toBe("LAS1");
|
|
|
expect(p?.F_Contact).toBe("LAS1");
|
|
|
expect(p?.F_Address).toBe("12300 Bermuda Road");
|
|
|
expect(columnValueFromCell("F_FBACode", SAMPLE)).toBe("LAS1");
|
|
|
expect(columnValueFromCell("F_Address", SAMPLE)).toBe("12300 Bermuda Road");
|
|
|
expect(columnValueFromCell("F_Remark", SAMPLE)).toBe("三票分开打托");
|
|
|
});
|
|
|
|
|
|
it("splits Address 单元格里的中文键值块", () => {
|
|
|
const p = parseLabeledAddressBlock(SAMPLE);
|
|
|
expect(p).toBeTruthy();
|
|
|
expect(p!.warehouseCode).toBe("LAS1");
|
|
|
expect(p!.contact).toBe("LAS1");
|
|
|
expect(p!.company).toBe("AMAZON COM SERVICES INC");
|
|
|
expect(p!.mobile).toBe("0123456789");
|
|
|
expect(p!.state).toBe("NV");
|
|
|
expect(p!.city).toBe("HENDERSON");
|
|
|
expect(p!.zip).toBe("89044-8746");
|
|
|
expect(p!.street).toBe("12300 Bermuda Road");
|
|
|
expect(p!.remark).toBe("三票分开打托");
|
|
|
});
|
|
|
|
|
|
it("ignores a plain street with no labels", () => {
|
|
|
expect(parseLabeledAddressBlock("12924 Pierce St")).toBeNull();
|
|
|
});
|
|
|
});
|