productId.spec.js 882 Bytes
import {
	createProductIdColumn,
	createProductIdFilter,
	formatProductId,
} from "./productId";

describe("product ID UI config", () => {
	it("builds the shared fuzzy-search filter", () => {
		expect(createProductIdFilter()).toEqual({
			label: "产品ID",
			name: "commodityCode",
			type: "input",
			isClear: true,
			placeholder: "请输入产品ID",
		});
	});

	it("builds a product ID column from the API response field", () => {
		const column = createProductIdColumn({ width: 120 });

		expect(column.label).toBe("产品ID");
		expect(column.prop).toBe("upgradeGoodsCommodityCode");
		expect(column.width).toBe(120);
		expect(column.formatter({
			upgradeGoodsCommodityCode: "U2509010001",
		})).toBe("U2509010001");
	});

	it.each([undefined, null, ""])("shows missing historical product IDs as a dash", (value) => {
		expect(formatProductId(value)).toBe("-");
	});
});