import { describe, expect, test } from "vitest"; import { formatDialogMessageLines, getMessageContentWidth, getMessageDialogWidth, } from "../../src/tui/utils/format-dialog-message.js"; describe("formatDialogMessageLines", () => { test("drops empty lines from leading newlines", () => { const lines = formatDialogMessageLines("\n- first\n- second", 80); expect(lines).toEqual(["- first", "- second"]); }); test("keeps short lines unchanged", () => { const lines = formatDialogMessageLines("- actions.receive: Invalid", 80); expect(lines).toEqual(["- actions.receive: Invalid"]); }); test("breaks long dot-separated paths at segment boundaries", () => { const line = '- actions.requestFungibleTokens.roles.receiver.requirements: Unrecognized key: "generate"'; const lines = formatDialogMessageLines(line, 56); expect(lines.length).toBeGreaterThan(1); expect(lines.join("\n")).toContain("actions.requestFungibleTokens."); expect(lines.every((entry) => entry.length <= 58)).toBe(true); expect(lines[1]?.startsWith(" ")).toBe(true); }); }); describe("dialog width helpers", () => { test("getMessageDialogWidth respects terminal bounds", () => { expect(getMessageDialogWidth(120)).toBe(100); expect(getMessageDialogWidth(80)).toBe(76); expect(getMessageDialogWidth(40)).toBe(60); }); test("getMessageContentWidth subtracts border and padding", () => { expect(getMessageContentWidth(76)).toBe(70); }); });