/** * Windows Compatibility Tests * Tests TUI functionality specifically on Windows systems including * Windows Terminal, Command Prompt, and PowerShell environments */ import { render } from "ink-testing-library"; import React from "react"; import { Text, Box } from "ink"; import { TuiApplication } from "../../../src/tui/TuiApplication.jsx"; import { detectWindowsTerminal, getWindowsTerminalCapabilities, } from "../../../src/tui/utils/modernTerminal.js"; // Mock process.platform for Windows testing const originalPlatform = process.platform; describe("Windows Compatibility Tests", () => { beforeAll(() => { // Mock Windows environment Object.defineProperty(process, "platform", { value: "win32", writable: true, }); }); afterAll(() => { // Restore original platform Object.defineProperty(process, "platform", { value: originalPlatform, writable: true, }); }); describe("Windows Terminal Detection", () => { test("should detect Windows Terminal environment", () => { // Mock Windows Terminal environment variables const originalEnv = process.env; process.env = { ...originalEnv, WT_SESSION: "test-session-id", TERM_PROGRAM: "Windows Terminal", }; const isWindowsTerminal = detectWindowsTerminal(); expect(isWindowsTerminal).toBe(true); process.env = originalEnv; }); test("should detect Command Prompt environment", () => { const originalEnv = process.env; process.env = { ...originalEnv, PROMPT: "$P$G", COMSPEC: "C:\\Windows\\system32\\cmd.exe", }; delete process.env.WT_SESSION; delete process.env.TERM_PROGRAM; const capabilities = getWindowsTerminalCapabilities(); expect(capabilities.isCommandPrompt).toBe(true); expect(capabilities.supportsUnicode).toBe(false); expect(capabilities.supportsTrueColor).toBe(false); process.env = originalEnv; }); test("should detect PowerShell environment", () => { const originalEnv = process.env; process.env = { ...originalEnv, PSModulePath: "C:\\Program Files\\PowerShell\\Modules", TERM_PROGRAM: "PowerShell", }; delete process.env.WT_SESSION; const capabilities = getWindowsTerminalCapabilities(); expect(capabilities.isPowerShell).toBe(true); expect(capabilities.supportsUnicode).toBe(true); expect(capabilities.supportsTrueColor).toBe(false); process.env = originalEnv; }); }); describe("Unicode Character Rendering", () => { test("should render basic Unicode characters on Windows", () => { const TestComponent = () => ( Progress: ░░░░░░░░░░ 0% Status: ● Connected Arrow: ► Selected ); const { lastFrame } = render(); const output = lastFrame(); // Test that Unicode characters are present (may be replaced with fallbacks) expect(output).toMatch(/Progress:.*0%/); expect(output).toMatch(/Status:.*Connected/); expect(output).toMatch(/Arrow:.*Selected/); }); test("should handle Unicode fallbacks for Command Prompt", () => { // Mock Command Prompt environment const originalEnv = process.env; process.env = { ...originalEnv, COMSPEC: "C:\\Windows\\system32\\cmd.exe", }; delete process.env.WT_SESSION; delete process.env.TERM_PROGRAM; const TestComponent = () => { const capabilities = getWindowsTerminalCapabilities(); return ( Progress:{" "} {capabilities.supportsUnicode ? "░░░░░░░░░░" : "----------"} 0% Status: {capabilities.supportsUnicode ? "●" : "*"} Connected ); }; const { lastFrame } = render(); const output = lastFrame(); expect(output).toContain("Progress: ---------- 0%"); expect(output).toContain("Status: * Connected"); process.env = originalEnv; }); }); describe("Color Support", () => { test("should detect color support in Windows Terminal", () => { const originalEnv = process.env; process.env = { ...originalEnv, WT_SESSION: "test-session", COLORTERM: "truecolor", }; const capabilities = getWindowsTerminalCapabilities(); expect(capabilities.supportsTrueColor).toBe(true); expect(capabilities.supportsColor).toBe(true); process.env = originalEnv; }); test("should handle limited color support in Command Prompt", () => { const originalEnv = process.env; process.env = { ...originalEnv, COMSPEC: "C:\\Windows\\system32\\cmd.exe", }; delete process.env.WT_SESSION; delete process.env.COLORTERM; const capabilities = getWindowsTerminalCapabilities(); expect(capabilities.supportsTrueColor).toBe(false); expect(capabilities.supportsColor).toBe(true); // Basic 16 colors process.env = originalEnv; }); }); describe("Keyboard Input Handling", () => { test("should handle Windows-specific key combinations", () => { const TestComponent = () => { const [keyPressed, setKeyPressed] = React.useState(""); React.useEffect(() => { const handleInput = (input, key) => { if (key) { // Windows-specific key handling if (key.ctrl && key.name === "c") { setKeyPressed("ctrl+c"); } else if (key.name === "escape") { setKeyPressed("escape"); } else if (key.name === "return") { setKeyPressed("enter"); } } }; process.stdin.on("keypress", handleInput); return () => process.stdin.off("keypress", handleInput); }, []); return Last key: {keyPressed}; }; const { lastFrame, stdin } = render(); // Simulate Windows key events stdin.write("\x03"); // Ctrl+C expect(lastFrame()).toContain("Last key: ctrl+c"); }); }); describe("Terminal Resizing", () => { test("should handle Windows terminal resize events", () => { const TestComponent = () => { const [size, setSize] = React.useState({ width: 80, height: 24 }); React.useEffect(() => { const handleResize = () => { setSize({ width: process.stdout.columns || 80, height: process.stdout.rows || 24, }); }; process.stdout.on("resize", handleResize); return () => process.stdout.off("resize", handleResize); }, []); return ( Terminal: {size.width}x{size.height} ); }; const { lastFrame } = render(); expect(lastFrame()).toMatch(/Terminal: \d+x\d+/); }); }); describe("File Path Handling", () => { test("should handle Windows file paths correctly", () => { const windowsPath = "C:\\Users\\Test\\AppData\\Local\\Temp\\test.log"; const normalizedPath = windowsPath.replace(/\\/g, "/"); expect(normalizedPath).toBe("C:/Users/Test/AppData/Local/Temp/test.log"); }); test("should handle UNC paths", () => { const uncPath = "\\\\server\\share\\file.txt"; const isUncPath = uncPath.startsWith("\\\\"); expect(isUncPath).toBe(true); }); }); describe("Process Management", () => { test("should handle Windows process signals", () => { const originalPlatform = process.platform; Object.defineProperty(process, "platform", { value: "win32" }); // Windows doesn't support SIGTERM the same way const supportsSigterm = process.platform !== "win32"; expect(supportsSigterm).toBe(false); Object.defineProperty(process, "platform", { value: originalPlatform }); }); }); });