49 lines
958 B
Go
49 lines
958 B
Go
package editor
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"pad/internal/io/pool/mock"
|
|
)
|
|
|
|
func TestOpenFileIntegration(t *testing.T) {
|
|
// 1. Setup Logic
|
|
mockFS := mock.NewFileSystem()
|
|
filename := "/README.md"
|
|
content := "Hello World"
|
|
mockFS.AddFile(filename, []byte(content), time.Now())
|
|
|
|
l := NewLogic(mockFS)
|
|
go l.Run()
|
|
defer l.Done()
|
|
|
|
// Drain frameChan to prevent deadlocks
|
|
go func() {
|
|
for range l.FrameChan() {
|
|
}
|
|
}()
|
|
|
|
TheState = l.state // Initialize global state
|
|
|
|
// 2. Open File
|
|
// OpenFile dispatches the task to openFileChan, which Run() will consume
|
|
OpenFile(filename)
|
|
|
|
// 3. Process the Result
|
|
// We wait for the state to update, which happens when ReadFileTask completes
|
|
success := false
|
|
for i := 0; i < 20; i++ {
|
|
if l.state.Editor.Buffer == content {
|
|
success = true
|
|
break
|
|
}
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
|
|
// 4. Assert
|
|
if !success {
|
|
t.Errorf("Expected content %q, got %q", content, l.state.Editor.Buffer)
|
|
}
|
|
}
|