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