fix: resolve navigation and file content loading issues

This commit is contained in:
gmp
2026-06-02 10:23:43 -04:00
parent ec87e95b35
commit b838b4c75f
5 changed files with 69 additions and 13 deletions
+56
View File
@@ -0,0 +1,56 @@
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.ActiveFileContent = string(content)
}
}
// 4. Assert
if state.ActiveFileContent != content {
t.Errorf("Expected content %q, got %q", content, state.ActiveFileContent)
}
}