import assert from "node:assert/strict"; import test from "node:test"; import { createElement } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { DailyBranchState, DailyTreeButton } from "./daily-detail-controls"; import { dailySummaryRows, formatDailyChange } from "../model/daily-detail-format"; import type { H2BiDailyResponse } from "../types"; test("每日环比区分真实零值、缺失值和非数值", () => { for (const value of [null, undefined, NaN, Infinity, "0"]) assert.equal(formatDailyChange(value), "环比 —"); assert.equal(formatDailyChange(0), "环比 0.00%"); assert.equal(formatDailyChange(-12.5), "环比 -12.50%"); assert.equal(formatDailyChange(12.5), "环比 +12.50%"); }); test("日期汇总导出包含全部日期,不依赖已展开明细并保留真零", () => { const daily = { kpis: { stationCount: 2, totalKg: 15.25, totalCost: 450 }, days: [ { date: "2026-09-03", stationCount: 2, kg: 15.25, cost: 450 }, { date: "2026-09-02", stationCount: 0, kg: 0, cost: 0 }, ], } as H2BiDailyResponse; const rows = dailySummaryRows(daily); assert.equal(rows.length, 4); assert.deepEqual(rows[1], ["区间合计", 2, 15.25, 450]); assert.deepEqual(rows[3], ["2026-09-02", 0, 0, 0]); }); test("层级按钮包含键盘原生语义与明确展开状态", () => { for (const open of [false, true]) { const html = renderToStaticMarkup(createElement(DailyTreeButton, { open, label: "测试站客户明细", children: "测试站", onClick() {}, })); assert.match(html, /