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, "/", func(string) {}) go l.Run() defer l.Shutdown() // Drain frameChan to prevent deadlocks go func() { for range l.FrameChan() { } }() // Initialize global state on the owner withState(t, l, func(st *State) { TheState = st }) // 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 ReadChunkTask completes success := false for i := 0; i < 20; i++ { v, ok := l.Inspect(func(st *State) any { return st.Editor.GetBuffer() }) if ok && v.(string) == content { success = true break } time.Sleep(100 * time.Millisecond) } // 4. Assert if !success { got, _ := l.Inspect(func(st *State) any { return st.Editor.Buffer }) t.Errorf("Expected content %q, got %q", content, got) } }