60255
Zn
Zoea-Nova / files
Zoea-Nova / internal / tui / focus_header_test.go
3.2 KB
1package tui 2 3import ( 4 "strings" 5 "testing" 6 "time" 7 8 "github.com/charmbracelet/bubbles/viewport" 9) 10 11// TestFocusViewHeaderPresence verifies that the focus view header is present in rendered output. 12func TestFocusViewHeaderPresence(t *testing.T) { 13 tests := []struct { 14 name string 15 termWidth int 16 termHeight int 17 mysisName string 18 }{ 19 { 20 name: "small_terminal_20_lines", 21 termWidth: 80, 22 termHeight: 20, 23 mysisName: "test-mysis", 24 }, 25 { 26 name: "normal_terminal_40_lines", 27 termWidth: 120, 28 termHeight: 40, 29 mysisName: "alpha-mysis", 30 }, 31 { 32 name: "large_terminal_60_lines", 33 termWidth: 160, 34 termHeight: 60, 35 mysisName: "production-bot", 36 }, 37 } 38 39 for _, tt := range tests { 40 t.Run(tt.name, func(t *testing.T) { 41 // Create test mysis 42 mysis := MysisInfo{ 43 ID: "test-id", 44 Name: tt.mysisName, 45 State: "running", 46 Provider: "ollama-qwen", 47 AccountUsername: "test_account", 48 CreatedAt: time.Date(2026, 1, 15, 10, 0, 0, 0, time.UTC), 49 } 50 51 // Calculate viewport height (same as app.go) 52 headerHeight := 6 53 footerHeight := 2 54 vpHeight := tt.termHeight - headerHeight - footerHeight - 3 55 if vpHeight < 5 { 56 vpHeight = 5 57 } 58 vpWidth := tt.termWidth - 6 - 2 59 60 // Create viewport 61 vp := viewport.New(vpWidth, vpHeight) 62 63 // Add some content 64 logs := []LogEntry{ 65 {Role: "user", Source: "direct", Content: "Test message", Timestamp: time.Now()}, 66 } 67 var contentLines []string 68 for _, log := range logs { 69 lines := renderLogEntryImpl(log, tt.termWidth-4, false, 0) 70 contentLines = append(contentLines, lines...) 71 } 72 vp.SetContent(strings.Join(contentLines, "\n")) 73 vp.GotoTop() 74 75 // Render focus view 76 output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, len(contentLines), 1, 1, 0, nil, 0, nil) 77 78 // Split into lines 79 lines := strings.Split(output, "\n") 80 81 // Verify output is not empty 82 if output == "" { 83 t.Fatal("Focus view output is empty") 84 } 85 86 // Verify we have lines 87 if len(lines) == 0 { 88 t.Fatal("Focus view has no lines") 89 } 90 91 // Verify first line contains header elements 92 firstLine := lines[0] 93 94 // Check for header decorations 95 if !strings.Contains(firstLine, "⬥") { 96 t.Errorf("First line does not contain header decoration '⬥'\nFirst line: %s", firstLine) 97 } 98 99 // Check for mysis name marker 100 if !strings.Contains(firstLine, "⬡") { 101 t.Errorf("First line does not contain mysis marker '⬡'\nFirst line: %s", firstLine) 102 } 103 104 // Check for "MYSIS:" text 105 if !strings.Contains(firstLine, "MYSIS:") { 106 t.Errorf("First line does not contain 'MYSIS:' text\nFirst line: %s", firstLine) 107 } 108 109 // Check for mysis name 110 if !strings.Contains(firstLine, tt.mysisName) { 111 t.Errorf("First line does not contain mysis name '%s'\nFirst line: %s", tt.mysisName, firstLine) 112 } 113 114 // Check for position indicator (1/1) 115 if !strings.Contains(firstLine, "(1/1)") { 116 t.Errorf("First line does not contain position indicator '(1/1)'\nFirst line: %s", firstLine) 117 } 118 119 t.Logf("Header successfully found at terminal height %d:\n%s", tt.termHeight, firstLine) 120 }) 121 } 122}