import { describe, it, expect } from "vitest"; import { pickRecordTitle, formatCellValue } from "./record-detail"; import type { DataRow } from "./table-filters"; describe("pickRecordTitle", () => { it("prefers 生产订单号", () => { const row: DataRow = { 生产订单号: "PO-1", 总排号: "X", ID: 1 }; expect(pickRecordTitle(row)).toBe("PO-1"); }); it("falls back to 总排号 when 生产订单号 blank", () => { const row: DataRow = { 生产订单号: " ", 总排号: "X-9", ID: 1 }; expect(pickRecordTitle(row)).toBe("X-9"); }); it("falls back to ID when earlier are null/empty", () => { const row: DataRow = { 生产订单号: null, 总排号: "", ID: 42 }; expect(pickRecordTitle(row)).toBe("42"); }); it("returns (未命名) when all blank", () => { const row: DataRow = { 生产订单号: null, 总排号: null, ID: null }; expect(pickRecordTitle(row)).toBe("(未命名)"); }); }); describe("formatCellValue", () => { it("null -> em dash", () => { expect(formatCellValue(null)).toBe("—"); }); it("empty / whitespace -> em dash", () => { expect(formatCellValue("")).toBe("—"); expect(formatCellValue(" ")).toBe("—"); }); it("0 is NOT blank", () => { expect(formatCellValue(0)).toBe("0"); }); it("number stringified", () => { expect(formatCellValue(123)).toBe("123"); }); it("text preserved", () => { expect(formatCellValue("量程0-1.6MPa")).toBe("量程0-1.6MPa"); }); });