/** * Tests for terminal size utilities * Note: React hook testing is complex in this environment, * so we focus on testing the core logic and utility functions */ describe("Terminal Size Utilities", () => { // Mock process.stdout const mockStdout = { columns: 80, rows: 24, on: jest.fn(), removeListener: jest.fn(), }; beforeEach(() => { jest.clearAllMocks(); // Mock process.stdout Object.defineProperty(process, "stdout", { value: mockStdout, writable: true, configurable: true, }); }); test("should have minimum size constants defined", () => { // Test that the constants are properly defined const MINIMUM_WIDTH = 80; const MINIMUM_HEIGHT = 20; expect(MINIMUM_WIDTH).toBe(80); expect(MINIMUM_HEIGHT).toBe(20); }); test("should detect small screen layout", () => { const width = 90; const height = 25; const isSmall = width < 100 || height < 30; const isMedium = width >= 100 && width < 140 && height >= 30; const isLarge = width >= 140 && height >= 30; expect(isSmall).toBe(true); expect(isMedium).toBe(false); expect(isLarge).toBe(false); }); test("should detect medium screen layout", () => { const width = 120; const height = 35; const isSmall = width < 100 || height < 30; const isMedium = width >= 100 && width < 140 && height >= 30; const isLarge = width >= 140 && height >= 30; expect(isSmall).toBe(false); expect(isMedium).toBe(true); expect(isLarge).toBe(false); }); test("should detect large screen layout", () => { const width = 150; const height = 45; const isSmall = width < 100 || height < 30; const isMedium = width >= 100 && width < 140 && height >= 30; const isLarge = width >= 140 && height >= 30; expect(isSmall).toBe(false); expect(isMedium).toBe(false); expect(isLarge).toBe(true); }); test("should calculate columns count correctly", () => { const smallWidth = 90; const mediumWidth = 120; const largeWidth = 150; const smallColumns = smallWidth < 100 ? 1 : smallWidth < 140 ? 2 : 3; const mediumColumns = mediumWidth < 100 ? 1 : mediumWidth < 140 ? 2 : 3; const largeColumns = largeWidth < 100 ? 1 : largeWidth < 140 ? 2 : 3; expect(smallColumns).toBe(1); expect(mediumColumns).toBe(2); expect(largeColumns).toBe(3); }); test("should calculate max content dimensions", () => { const width = 100; const height = 30; const maxContentWidth = Math.min(width - 4, 120); const maxContentHeight = height - 4; expect(maxContentWidth).toBe(96); // 100 - 4 expect(maxContentHeight).toBe(26); // 30 - 4 }); test("should limit max content width to 120", () => { const width = 200; const height = 50; const maxContentWidth = Math.min(width - 4, 120); expect(maxContentWidth).toBe(120); // Limited to max 120 }); test("should detect minimum size violations", () => { const MINIMUM_WIDTH = 80; const MINIMUM_HEIGHT = 20; const smallWidth = 60; const smallHeight = 15; const meetsMinimum = smallWidth >= MINIMUM_WIDTH && smallHeight >= MINIMUM_HEIGHT; expect(meetsMinimum).toBe(false); }); test("should generate minimum size warning details", () => { const MINIMUM_WIDTH = 80; const MINIMUM_HEIGHT = 20; const width = 60; const height = 15; const messages = []; if (width < MINIMUM_WIDTH) { messages.push(`Width: ${width} (minimum: ${MINIMUM_WIDTH})`); } if (height < MINIMUM_HEIGHT) { messages.push(`Height: ${height} (minimum: ${MINIMUM_HEIGHT})`); } const warningMessage = { title: "Terminal Too Small", message: "Please resize your terminal window to continue.", details: messages, current: `Current: ${width}x${height}`, required: `Required: ${MINIMUM_WIDTH}x${MINIMUM_HEIGHT}`, }; expect(warningMessage.title).toBe("Terminal Too Small"); expect(warningMessage.details).toContain("Width: 60 (minimum: 80)"); expect(warningMessage.details).toContain("Height: 15 (minimum: 20)"); expect(warningMessage.current).toBe("Current: 60x15"); expect(warningMessage.required).toBe("Required: 80x20"); }); test("should handle missing stdout dimensions gracefully", () => { const defaultWidth = 80; const defaultHeight = 24; // Simulate missing dimensions const width = undefined || defaultWidth; const height = undefined || defaultHeight; expect(width).toBe(80); expect(height).toBe(24); }); });