user-message.test.ts 984 B

12345678910111213141516171819202122232425
  1. import { describe, expect, test } from "vitest";
  2. import { UserMessageComponent } from "../src/modes/interactive/components/user-message.ts";
  3. import { initTheme } from "../src/modes/interactive/theme/theme.ts";
  4. const OSC133_ZONE_START = "\x1b]133;A\x07";
  5. const OSC133_ZONE_END = "\x1b]133;B\x07";
  6. const OSC133_ZONE_FINAL = "\x1b]133;C\x07";
  7. const BG_RESET = "\x1b[49m";
  8. describe("UserMessageComponent", () => {
  9. test("keeps user message height stable while moving closing OSC markers off line end", () => {
  10. initTheme("dark");
  11. const component = new UserMessageComponent("hello");
  12. const lines = component.render(20);
  13. expect(lines).toHaveLength(3);
  14. expect(lines[0]).toContain(OSC133_ZONE_START);
  15. expect(lines[0].endsWith(BG_RESET)).toBe(true);
  16. expect(lines[0]).not.toContain(OSC133_ZONE_END);
  17. expect(lines[1]).toContain("hello");
  18. expect(lines[2].startsWith(OSC133_ZONE_END + OSC133_ZONE_FINAL)).toBe(true);
  19. expect(lines[2].endsWith(BG_RESET)).toBe(true);
  20. });
  21. });