60255
Zn
Zoea-Nova / files
Zoea-Nova / internal / tui / error_display_test.go
3.2 KB
1package tui 2 3import ( 4 "errors" 5 "strings" 6 "testing" 7 8 "github.com/charmbracelet/bubbles/viewport" 9 "github.com/charmbracelet/lipgloss" 10) 11 12func TestErrorDisplayInDashboard(t *testing.T) { 13 testErr := errors.New("test error message") 14 15 // Render dashboard with error 16 output := RenderDashboard( 17 []MysisInfo{}, 18 []SwarmMessageInfo{}, 19 0, 20 100, 21 30, 22 make(map[string]bool), 23 "⠋", 24 0, 25 testErr, 26 ) 27 28 // Error should appear in the hint line 29 if !strings.Contains(output, "Error: test error message") { 30 t.Error("expected error message to appear in dashboard output") 31 } 32 33 // Error should be on the same line as keyboard controls 34 lines := strings.Split(output, "\n") 35 foundErrorLine := false 36 for _, line := range lines { 37 if strings.Contains(line, "HELP") && strings.Contains(line, "Error:") { 38 foundErrorLine = true 39 break 40 } 41 } 42 if !foundErrorLine { 43 t.Error("expected error to appear on same line as keyboard controls") 44 } 45} 46 47func TestErrorDisplayInFocusView(t *testing.T) { 48 testErr := errors.New("focus view error") 49 50 mysis := MysisInfo{ 51 ID: "test-id", 52 Name: "TestMysis", 53 State: "running", 54 Provider: "opencode", 55 } 56 57 vp := viewport.New(120, 20) 58 vp.SetContent("Test content") 59 60 // Render focus view with error (use wider terminal to fit error) 61 output := RenderFocusViewWithViewport( 62 mysis, 63 vp, 64 120, 65 false, 66 "⠋", 67 false, 68 1, 69 1, 70 1, 71 0, 72 nil, // gameStateSnapshots 73 0, // sidebarScrollOffset 74 testErr, 75 ) 76 77 // Error should appear in the hint line 78 if !strings.Contains(output, "Error: focus view error") { 79 t.Logf("Output:\n%s", output) 80 t.Error("expected error message to appear in focus view output") 81 } 82 83 // Error should be on the same line as keyboard controls 84 lines := strings.Split(output, "\n") 85 foundErrorLine := false 86 for _, line := range lines { 87 if strings.Contains(line, "ESC") && strings.Contains(line, "Error:") { 88 foundErrorLine = true 89 break 90 } 91 } 92 if !foundErrorLine { 93 t.Error("expected error to appear on same line as keyboard controls in focus view") 94 } 95} 96 97func TestNoErrorDisplay(t *testing.T) { 98 // Render dashboard without error 99 output := RenderDashboard( 100 []MysisInfo{}, 101 []SwarmMessageInfo{}, 102 0, 103 100, 104 30, 105 make(map[string]bool), 106 "⠋", 107 0, 108 nil, 109 ) 110 111 // Should not contain "Error:" 112 if strings.Contains(output, "Error:") { 113 t.Error("expected no error message when err is nil") 114 } 115} 116 117func TestLongErrorTruncation(t *testing.T) { 118 longErr := errors.New("this is a very long error message that should be truncated to fit within the available space on the terminal line without breaking the layout") 119 120 output := RenderDashboard( 121 []MysisInfo{}, 122 []SwarmMessageInfo{}, 123 0, 124 100, 125 30, 126 make(map[string]bool), 127 "⠋", 128 0, 129 longErr, 130 ) 131 132 // Error should be present but truncated 133 if !strings.Contains(output, "Error:") { 134 t.Error("expected error message to appear") 135 } 136 137 // Check that no line exceeds terminal width (using display width, not byte length) 138 lines := strings.Split(output, "\n") 139 for i, line := range lines { 140 // Use lipgloss.Width for accurate display width (ignores ANSI codes) 141 displayWidth := lipgloss.Width(line) 142 if displayWidth > 100 { 143 t.Errorf("line %d exceeds terminal width: %d display chars", i, displayWidth) 144 } 145 } 146}