package editor import ( "testing" "time" "pad/internal/browser" "pad/internal/io/pool" "pad/internal/io/pool/mock" ) func TestOpenFileIntegration(t *testing.T) { // 1. Setup Logic // We need to re-create the setup logic to control the environment mockFS := mock.NewFileSystem() // Add a file filename := "/README.md" content := "Hello World" mockFS.AddFile(filename, []byte(content), time.Now()) wp := pool.NewWorkerPool(4) wp.Start() // Initialize state manually state := NewState() TheState = state // Initialize global state state.Browser.CurrentPath = "/" _, _ = browser.NewBrowserManager(&state.Browser, wp, mockFS) // 2. Simulate File Tap // We need to trigger the file tap, which dispatches a ReadFileTask // and calls OpenFile(filename). // OpenFile sets filename and changes page OpenFile(filename) // Dispatch ReadFileTask task := pool.NewReadFileTask(filename, mockFS) wp.Dispatch(task) // 3. Process the Result // The logic loop would normally do this, we do it manually for the test res := <-wp.ResultChan() // Apply result if res.Success { if content, ok := res.Data.([]byte); ok { state.Editor.Buffer = string(content) } } // 4. Assert if state.Editor.Buffer != content { t.Errorf("Expected content %q, got %q", content, state.Editor.Buffer) } }