import { test } from "node:test"; import assert from "node:assert/strict"; import { h } from "preact"; import { render, cleanup } from "@testing-library/preact"; import { LogRow, levelKind, fmtValue, shortTime } from "../src/base/log-row.jsx"; test("levelKind maps known levels to their pill kind", () => { assert.equal(levelKind("ERROR"), "danger"); assert.equal(levelKind("warn"), "warn"); assert.equal(levelKind("Debug"), "idle"); assert.equal(levelKind("info"), "info"); assert.equal(levelKind(""), "info"); }); test("fmtValue stringifies objects, passes scalars through, and blanks nullish", () => { assert.equal(fmtValue(null), ""); assert.equal(fmtValue(undefined), ""); assert.equal(fmtValue(5), 5); assert.equal(fmtValue({ a: 1 }), JSON.stringify({ a: 1 })); }); test("shortTime falls back to a placeholder for an unparsable time", () => { assert.equal(shortTime("not a date"), "--:--:--"); }); test("LogRow renders every field generically, including the ones the daemon-wide feed drops", () => { const { container } = render( , ); const row = container.querySelector(".log-row"); assert.match(row.className, /log-row/); assert.match(row.textContent, /attempt finished/); for (const key of ["stage", "prompt_tokens", "completion_tokens", "cached_tokens", "stop_reason", "model"]) { assert.match(row.textContent, new RegExp(key), `missing field ${key}`); } cleanup(); }); test("LogRow colours the row by level", () => { const { container } = render(); assert.match(container.querySelector(".log-row").className, /log-danger/); assert.equal(container.querySelector(".log-level").textContent, "ERROR"); cleanup(); });