overlay-short-content.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import assert from "node:assert";
  2. import { describe, it } from "node:test";
  3. import { type Component, TUI } from "../src/tui.ts";
  4. import { VirtualTerminal } from "./virtual-terminal.ts";
  5. class SimpleContent implements Component {
  6. private lines: string[];
  7. constructor(lines: string[]) {
  8. this.lines = lines;
  9. }
  10. render(): string[] {
  11. return this.lines;
  12. }
  13. invalidate() {}
  14. }
  15. class SimpleOverlay implements Component {
  16. render(): string[] {
  17. return ["OVERLAY_TOP", "OVERLAY_MID", "OVERLAY_BOT"];
  18. }
  19. invalidate() {}
  20. }
  21. describe("TUI overlay with short content", () => {
  22. it("should render overlay when content is shorter than terminal height", async () => {
  23. // Terminal has 24 rows, but content only has 3 lines
  24. const terminal = new VirtualTerminal(80, 24);
  25. const tui = new TUI(terminal);
  26. // Only 3 lines of content
  27. tui.addChild(new SimpleContent(["Line 1", "Line 2", "Line 3"]));
  28. // Show overlay centered - should be around row 10 in a 24-row terminal
  29. const overlay = new SimpleOverlay();
  30. tui.showOverlay(overlay);
  31. // Trigger render
  32. tui.start();
  33. await terminal.waitForRender();
  34. const viewport = terminal.getViewport();
  35. const hasOverlay = viewport.some((line) => line.includes("OVERLAY"));
  36. console.log("Terminal rows:", terminal.rows);
  37. console.log("Content lines: 3");
  38. console.log("Overlay visible:", hasOverlay);
  39. if (!hasOverlay) {
  40. console.log("\nViewport contents:");
  41. for (let i = 0; i < viewport.length; i++) {
  42. console.log(` [${i}]: "${viewport[i]}"`);
  43. }
  44. }
  45. assert.ok(hasOverlay, "Overlay should be visible when content is shorter than terminal");
  46. tui.stop();
  47. });
  48. });