|
| 1 | +package tui |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestLogPanelHeights_DefaultPanel(t *testing.T) { |
| 8 | + // When stderr is not focused, it should get 20% and stdout 80% |
| 9 | + m := Model{ |
| 10 | + height: 101, // totalH = 100 |
| 11 | + width: 200, |
| 12 | + activePanel: panelJobs, |
| 13 | + } |
| 14 | + |
| 15 | + stdoutH, stderrH := m.logPanelHeights() |
| 16 | + |
| 17 | + if stderrH != 20 { |
| 18 | + t.Errorf("stderrH = %d, want 20 (20%% of 100)", stderrH) |
| 19 | + } |
| 20 | + if stdoutH != 80 { |
| 21 | + t.Errorf("stdoutH = %d, want 80 (100 - 20)", stdoutH) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +func TestLogPanelHeights_StderrFocused(t *testing.T) { |
| 26 | + // When stderr is focused, it should get 80% and stdout 20% |
| 27 | + m := Model{ |
| 28 | + height: 101, // totalH = 100 |
| 29 | + width: 200, |
| 30 | + activePanel: panelStderr, |
| 31 | + } |
| 32 | + |
| 33 | + stdoutH, stderrH := m.logPanelHeights() |
| 34 | + |
| 35 | + if stderrH != 80 { |
| 36 | + t.Errorf("stderrH = %d, want 80 (80%% of 100)", stderrH) |
| 37 | + } |
| 38 | + if stdoutH != 20 { |
| 39 | + t.Errorf("stdoutH = %d, want 20 (100 - 80)", stdoutH) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func TestLogPanelHeights_StdoutFocused(t *testing.T) { |
| 44 | + // Stdout focused should behave like default (stderr stays small) |
| 45 | + m := Model{ |
| 46 | + height: 101, |
| 47 | + width: 200, |
| 48 | + activePanel: panelStdout, |
| 49 | + } |
| 50 | + |
| 51 | + stdoutH, stderrH := m.logPanelHeights() |
| 52 | + |
| 53 | + if stderrH != 20 { |
| 54 | + t.Errorf("stderrH = %d, want 20", stderrH) |
| 55 | + } |
| 56 | + if stdoutH != 80 { |
| 57 | + t.Errorf("stdoutH = %d, want 80", stdoutH) |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +func TestLogPanelHeights_MinimumStderrHeight(t *testing.T) { |
| 62 | + // With very small terminal, stderr should be at least 4 |
| 63 | + m := Model{ |
| 64 | + height: 10, // totalH = 9 |
| 65 | + width: 200, |
| 66 | + activePanel: panelJobs, |
| 67 | + } |
| 68 | + |
| 69 | + stdoutH, stderrH := m.logPanelHeights() |
| 70 | + |
| 71 | + // 9 * 20 / 100 = 1, which is less than 4 |
| 72 | + if stderrH < 4 { |
| 73 | + t.Errorf("stderrH = %d, want >= 4 (minimum)", stderrH) |
| 74 | + } |
| 75 | + if stdoutH+stderrH != 9 { |
| 76 | + t.Errorf("stdoutH(%d) + stderrH(%d) = %d, want 9 (totalH)", stdoutH, stderrH, stdoutH+stderrH) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +func TestLogPanelHeights_MinimumTotalHeight(t *testing.T) { |
| 81 | + // With tiny terminal, totalH should be clamped to 8 |
| 82 | + m := Model{ |
| 83 | + height: 3, // totalH = 2, clamped to 8 |
| 84 | + width: 200, |
| 85 | + activePanel: panelJobs, |
| 86 | + } |
| 87 | + |
| 88 | + stdoutH, stderrH := m.logPanelHeights() |
| 89 | + |
| 90 | + // totalH clamped to 8, stderrH = 8 * 20 / 100 = 1, clamped to 4 |
| 91 | + if stderrH < 4 { |
| 92 | + t.Errorf("stderrH = %d, want >= 4 (minimum)", stderrH) |
| 93 | + } |
| 94 | + if stdoutH+stderrH != 8 { |
| 95 | + t.Errorf("stdoutH(%d) + stderrH(%d) = %d, want 8 (clamped totalH)", stdoutH, stderrH, stdoutH+stderrH) |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +func TestLogPanelHeights_SumEqualsTotal(t *testing.T) { |
| 100 | + // Heights should always sum to totalH for all panels |
| 101 | + panels := []panel{panelJobs, panelPorts, panelRuns, panelStdout, panelStderr} |
| 102 | + |
| 103 | + for _, p := range panels { |
| 104 | + m := Model{ |
| 105 | + height: 51, // totalH = 50 |
| 106 | + width: 200, |
| 107 | + activePanel: p, |
| 108 | + } |
| 109 | + |
| 110 | + stdoutH, stderrH := m.logPanelHeights() |
| 111 | + totalH := 50 |
| 112 | + |
| 113 | + if stdoutH+stderrH != totalH { |
| 114 | + t.Errorf("panel %d: stdoutH(%d) + stderrH(%d) = %d, want %d", |
| 115 | + p, stdoutH, stderrH, stdoutH+stderrH, totalH) |
| 116 | + } |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +func TestUpdateLogViewportSizes_SetsCorrectDimensions(t *testing.T) { |
| 121 | + m := New() |
| 122 | + m.width = 200 |
| 123 | + m.height = 101 // totalH = 100 |
| 124 | + m.activePanel = panelJobs |
| 125 | + |
| 126 | + m.updateLogViewportSizes() |
| 127 | + |
| 128 | + // jobPanelWidth for width=200: 200*40/100 = 80, capped at 60 |
| 129 | + // rightPanelW = 200 - 60 = 140 |
| 130 | + // viewportWidth = 140 - 4 = 136 |
| 131 | + expectedWidth := 136 |
| 132 | + |
| 133 | + // stderrH = 100 * 20 / 100 = 20, viewportHeight = 20 - 3 = 17 |
| 134 | + // stdoutH = 100 - 20 = 80, viewportHeight = 80 - 3 = 77 |
| 135 | + expectedStderrHeight := 17 |
| 136 | + expectedStdoutHeight := 77 |
| 137 | + |
| 138 | + if m.stderrView.Width != expectedWidth { |
| 139 | + t.Errorf("stderrView.Width = %d, want %d", m.stderrView.Width, expectedWidth) |
| 140 | + } |
| 141 | + if m.stderrView.Height != expectedStderrHeight { |
| 142 | + t.Errorf("stderrView.Height = %d, want %d", m.stderrView.Height, expectedStderrHeight) |
| 143 | + } |
| 144 | + if m.stdoutView.Width != expectedWidth { |
| 145 | + t.Errorf("stdoutView.Width = %d, want %d", m.stdoutView.Width, expectedWidth) |
| 146 | + } |
| 147 | + if m.stdoutView.Height != expectedStdoutHeight { |
| 148 | + t.Errorf("stdoutView.Height = %d, want %d", m.stdoutView.Height, expectedStdoutHeight) |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +func TestUpdateLogViewportSizes_StderrExpands(t *testing.T) { |
| 153 | + m := New() |
| 154 | + m.width = 200 |
| 155 | + m.height = 101 // totalH = 100 |
| 156 | + |
| 157 | + // First set to jobs panel (stderr = 20%) |
| 158 | + m.activePanel = panelJobs |
| 159 | + m.updateLogViewportSizes() |
| 160 | + smallStderrHeight := m.stderrView.Height |
| 161 | + smallStdoutHeight := m.stdoutView.Height |
| 162 | + |
| 163 | + // Switch to stderr panel (stderr = 80%) |
| 164 | + m.activePanel = panelStderr |
| 165 | + m.updateLogViewportSizes() |
| 166 | + bigStderrHeight := m.stderrView.Height |
| 167 | + bigStdoutHeight := m.stdoutView.Height |
| 168 | + |
| 169 | + if bigStderrHeight <= smallStderrHeight { |
| 170 | + t.Errorf("stderr focused: Height %d should be > unfocused Height %d", |
| 171 | + bigStderrHeight, smallStderrHeight) |
| 172 | + } |
| 173 | + if bigStdoutHeight >= smallStdoutHeight { |
| 174 | + t.Errorf("stderr focused: stdout Height %d should be < unfocused stdout Height %d", |
| 175 | + bigStdoutHeight, smallStdoutHeight) |
| 176 | + } |
| 177 | +} |
0 commit comments