import { describe, expect, it } from "vitest"; import { cellPreview, compareCells, filterRows, suggestedColumnWidth } from "./resultView"; describe("结果展示边界", () => { it("大整数文本排序不丢精度", () => { expect(compareCells("9007199254740993", "9007199254740992")).toBe(1); expect(compareCells("-9007199254740993", "-9007199254740992")).toBe(-1); expect(compareCells(null, "")).toBe(-1); expect(compareCells("1.2", "1.11")).toBeGreaterThan(0); expect(compareCells("1e3", "999")).toBeGreaterThan(0); }); it("本地筛选覆盖 NULL、JSON、布尔值,不修改原数组", () => { const rows = [{ x: null }, { x: { name: "Alice" } }, { x: false }, { x: "" }]; expect(filterRows(rows, ["x"], "alice")).toEqual([rows[1]]); expect(filterRows(rows, ["x"], "NULL")).toEqual([rows[0]]); expect(filterRows(rows, ["x"], "false")).toEqual([rows[2]]); expect(filterRows(rows, ["x"], " ")).toBe(rows); expect(rows).toHaveLength(4); }); it("长 JSON 与文本都截断预览,原值保留", () => { const value = { text: "x".repeat(500) }; expect(cellPreview(value)).toHaveLength(121); expect(value.text).toHaveLength(500); expect(cellPreview(false)).toBe("false"); expect(cellPreview(0)).toBe("0"); }); it("自动列宽有上下限并考虑中文宽度", () => { expect(suggestedColumnWidth("id", [])).toBe(88); expect(suggestedColumnWidth("数据", [{ 数据: "中".repeat(100) }])).toBe(480); expect(suggestedColumnWidth("name", [{ name: "中国数据库" }])).toBeGreaterThan(88); }); });