import { describe, test, expect, beforeEach, afterEach } from "bun:test"; import { mkdir, rm } from "fs/promises"; import { existsSync } from "fs"; import { join } from "path"; import { tmpdir } from "os"; import { HybridDirectoryBrowser } from "./DirectoriesStep.tsx"; // NOTE: Integration tests for HybridDirectoryBrowser are documented below // but not implemented because Ink's useInput hook requires a TTY with raw mode, // which is not available in the test environment. // // These would need to be tested with: // - A custom testing wrapper that provides a mock stdin // - Integration testing in a real terminal environment // - Or by extracting the logic into testable pure functions (already done in unit tests) // // Documented test scenarios: // - initialization: should start with tilde in input buffer, show folders in starting directory // - backspace behavior: should allow backspacing the initial tilde // - path input: should accept absolute paths, expand tilde, reject non-existent paths // - folder filtering: show all folders with slash, filter by name without slash // - escape behavior: go back to parent, cancel at root, clear input // - scrolling: scroll with many folders, show indicators, reset on navigate // - navigation: select with arrows, navigate with Enter/Space, clamp selection // - Ctrl+U: clear input and reset selection describe("HybridDirectoryBrowser", () => { let testDir: string; beforeEach(async () => { // Create a temporary directory structure for testing testDir = join(tmpdir(), `gitforest-test-${Date.now()}`); await mkdir(testDir, { recursive: true }); // Create test directory structure await mkdir(join(testDir, "projects")); await mkdir(join(testDir, "code")); await mkdir(join(testDir, "documents")); }); afterEach(async () => { // Clean up test directory if (existsSync(testDir)) { await rm(testDir, { recursive: true, force: true }); } }); // Basic smoke test to ensure the component can be imported test("should export HybridDirectoryBrowser component", () => { expect(HybridDirectoryBrowser).toBeDefined(); }); });