|
8 | 8 | "github.com/charmbracelet/bubbles/list" |
9 | 9 | "github.com/charmbracelet/bubbles/viewport" |
10 | 10 | tea "github.com/charmbracelet/bubbletea" |
| 11 | + "github.com/charmbracelet/lipgloss" |
11 | 12 |
|
12 | 13 | "github.com/babarot/gomi/internal/config" |
13 | 14 | "github.com/babarot/gomi/internal/trash" |
@@ -60,6 +61,88 @@ func TestUpdate_WindowSizeMsg(t *testing.T) { |
60 | 61 | } |
61 | 62 | } |
62 | 63 |
|
| 64 | +func TestUpdate_WindowSizeMsg_ShrinksListHeight(t *testing.T) { |
| 65 | + m := newTestModel() |
| 66 | + |
| 67 | + const termHeight = 20 |
| 68 | + msg := tea.WindowSizeMsg{Width: 80, Height: termHeight} |
| 69 | + updated, _ := m.Update(msg) |
| 70 | + model := asModel(t, updated) |
| 71 | + |
| 72 | + if model.list.Height() > termHeight { |
| 73 | + t.Errorf("list height = %d, want <= %d (terminal height); "+ |
| 74 | + "list is not following the terminal height and will push items off-screen", |
| 75 | + model.list.Height(), termHeight) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +func TestUpdate_WindowSizeMsg_SetsHelpWidth(t *testing.T) { |
| 80 | + m := newTestModel() |
| 81 | + |
| 82 | + const termWidth = 70 |
| 83 | + msg := tea.WindowSizeMsg{Width: termWidth, Height: 20} |
| 84 | + updated, _ := m.Update(msg) |
| 85 | + model := asModel(t, updated) |
| 86 | + |
| 87 | + if model.help.Width == 0 { |
| 88 | + t.Fatal("help.Width = 0; the help model was not informed of the " + |
| 89 | + "terminal width, so its View() will not truncate and may overflow") |
| 90 | + } |
| 91 | + if model.help.Width > termWidth { |
| 92 | + t.Errorf("help.Width = %d, want <= %d (terminal width)", |
| 93 | + model.help.Width, termWidth) |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +func TestView_FitsSmallTerminal(t *testing.T) { |
| 98 | + m := newTestModel() |
| 99 | + m.help = newHelpModel() |
| 100 | + m.state.SetView(ListView) |
| 101 | + |
| 102 | + const ( |
| 103 | + termWidth = 70 |
| 104 | + termHeight = 20 |
| 105 | + ) |
| 106 | + msg := tea.WindowSizeMsg{Width: termWidth, Height: termHeight} |
| 107 | + updated, _ := m.Update(msg) |
| 108 | + model := asModel(t, updated) |
| 109 | + |
| 110 | + view := model.View() |
| 111 | + |
| 112 | + if h := lipgloss.Height(view); h > termHeight { |
| 113 | + t.Errorf("View height = %d lines, want <= %d; "+ |
| 114 | + "output is taller than the terminal so the top rows scroll off", |
| 115 | + h, termHeight) |
| 116 | + } |
| 117 | + if w := lipgloss.Width(view); w > termWidth { |
| 118 | + t.Errorf("View width = %d cols, want <= %d; "+ |
| 119 | + "output is wider than the terminal so the right edge is clipped/wrapped", |
| 120 | + w, termWidth) |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +// TestUpdate_WindowSizeMsg_HeightZero verifies that a synthetic |
| 125 | +// WindowSizeMsg with only Width set (sent by confirm-view cancel |
| 126 | +// paths in update.go) does not collapse the list height. |
| 127 | +func TestUpdate_WindowSizeMsg_HeightZero(t *testing.T) { |
| 128 | + m := newTestModel() |
| 129 | + |
| 130 | + // First, set a real terminal size. |
| 131 | + updated, _ := m.Update(tea.WindowSizeMsg{Width: 120, Height: 40}) |
| 132 | + m = asModel(t, updated) |
| 133 | + prevHeight := m.list.Height() |
| 134 | + |
| 135 | + // Then send a width-only message (Height == 0). |
| 136 | + updated, _ = m.Update(tea.WindowSizeMsg{Width: m.list.Width()}) |
| 137 | + model := asModel(t, updated) |
| 138 | + |
| 139 | + if model.list.Height() != prevHeight { |
| 140 | + t.Errorf("list height = %d, want %d; "+ |
| 141 | + "width-only WindowSizeMsg must not change list height", |
| 142 | + model.list.Height(), prevHeight) |
| 143 | + } |
| 144 | +} |
| 145 | + |
63 | 146 | func TestUpdate_ErrorMsg(t *testing.T) { |
64 | 147 | m := newTestModel() |
65 | 148 |
|
|
0 commit comments