Pad/internal/editor/integration_test.go
Greg Pomerantz 0dac354f2a fix(editor): wire key events to cursor movement
- Replace gtx.Event(nil) with key.Filter{Focus: focusedID} and
  key.FocusFilter{Target: focusedID} so Gio correctly routes key
  and edit events to the focused editor text field.

- Convert EditorState.CursorPosition (byte offset) to line/column
  coordinates for accurate cursor rendering.

- Add debug logging in HandleKeyDown and HandleCursorMove.
2026-06-03 07:41:18 -04:00

57 lines
1.3 KiB
Go

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)
}
}