Commit: Initial Update

This commit is contained in:
2026-10-13 20:35:22 +07:00
parent f1c253b028
commit 43b8bfa253
24 changed files with 2440 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
package app_test
import (
"testing"
"time"
"github.com/gdamore/tcell/v2"
"github.com/nebara/nebara-os/internal/app"
"github.com/nebara/nebara-os/internal/mock"
)
func TestApplication_FullLifecycleSimulation(t *testing.T) {
simScreen := tcell.NewSimulationScreen("")
if err := simScreen.Init(); err != nil {
t.Fatalf("simScreen init: %v", err)
}
simScreen.SetSize(120, 40)
state := app.NewStateFromMock(mock.WarningState())
state.EnableSixel = true
application := app.NewApplication(state)
application.SetScreen(simScreen)
done := make(chan error, 1)
go func() {
done <- application.Run()
}()
// Allow initial frame to draw
time.Sleep(100 * time.Millisecond)
// 1. Test navigation (Down, Up)
simScreen.InjectKey(tcell.KeyDown, 0, tcell.ModNone)
time.Sleep(50 * time.Millisecond)
simScreen.InjectKey(tcell.KeyUp, 0, tcell.ModNone)
time.Sleep(50 * time.Millisecond)
// 2. Test F1 Help Modal open and close
simScreen.InjectKey(tcell.KeyF1, 0, tcell.ModNone)
time.Sleep(50 * time.Millisecond)
simScreen.InjectKey(tcell.KeyEscape, 0, tcell.ModNone)
time.Sleep(50 * time.Millisecond)
// 3. Test terminal resize (compact size and back)
simScreen.SetSize(90, 28)
time.Sleep(50 * time.Millisecond)
simScreen.SetSize(120, 40)
time.Sleep(50 * time.Millisecond)
// 4. Test normal exit (Ctrl+C)
simScreen.InjectKey(tcell.KeyCtrlC, 'c', tcell.ModCtrl)
select {
case err := <-done:
if err != nil {
t.Errorf("application run error: %v", err)
}
case <-time.After(2 * time.Second):
t.Fatal("application failed to terminate cleanly (possible deadlock)")
}
}
func TestApplication_TextFallbackLifecycle(t *testing.T) {
simScreen := tcell.NewSimulationScreen("")
if err := simScreen.Init(); err != nil {
t.Fatalf("simScreen init: %v", err)
}
simScreen.SetSize(120, 40)
state := app.NewStateFromMock(mock.NormalState())
state.EnableSixel = false // SIXEL disabled
application := app.NewApplication(state)
application.SetScreen(simScreen)
done := make(chan error, 1)
go func() {
done <- application.Run()
}()
time.Sleep(100 * time.Millisecond)
simScreen.InjectKey(tcell.KeyCtrlC, 'c', tcell.ModCtrl)
select {
case err := <-done:
if err != nil {
t.Errorf("application run error: %v", err)
}
case <-time.After(2 * time.Second):
t.Fatal("application failed to terminate cleanly")
}
}