-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout_test.go
More file actions
197 lines (172 loc) · 5.07 KB
/
Copy pathlayout_test.go
File metadata and controls
197 lines (172 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//go:build !js
package wui
import (
"strings"
"testing"
"github.com/charmbracelet/lipgloss"
)
func TestFullscreenFillsTerminal(t *testing.T) {
r := newTestRenderer() // 80x24
out := r.Render(Fullscreen(Text("hi")))
if got := lipgloss.Height(out); got != 24 {
t.Errorf("height = %d, want 24", got)
}
if got := lipgloss.Width(out); got != 80 {
t.Errorf("width = %d, want 80", got)
}
}
func TestFullscreenRespectsReservedRows(t *testing.T) {
r := newTestRenderer()
r.Reserved = 1
out := r.Render(Fullscreen(Text("hi")))
if got := lipgloss.Height(out); got != 23 {
t.Errorf("height = %d, want 23 with one reserved row", got)
}
}
func TestAppShellPinsHeaderAndFooter(t *testing.T) {
r := newTestRenderer()
out := r.Render(AppShell(Text("HEADER"), Text("BODY"), Text("FOOTER")))
lines := strings.Split(out, "\n")
if len(lines) != 24 {
t.Fatalf("line count = %d, want 24", len(lines))
}
if !strings.Contains(lines[0], "HEADER") {
t.Errorf("header not on first line: %q", lines[0])
}
if !strings.Contains(lines[1], "BODY") {
t.Errorf("body not directly under header: %q", lines[1])
}
if !strings.Contains(lines[23], "FOOTER") {
t.Errorf("footer not on last line: %q", lines[23])
}
}
func TestCenteredPlacesChildInMiddle(t *testing.T) {
r := newTestRenderer()
out := r.Render(Centered(Text("X")))
lines := strings.Split(out, "\n")
if len(lines) != 24 {
t.Fatalf("line count = %d, want 24", len(lines))
}
row := -1
for i, l := range lines {
if strings.Contains(l, "X") {
row = i
break
}
}
if row < 10 || row > 13 {
t.Errorf("content on row %d, want vertically centered", row)
}
col := strings.Index(lines[row], "X")
if col < 35 || col > 44 {
t.Errorf("content at column %d, want horizontally centered", col)
}
}
func TestSidebarLaysOutSideBySide(t *testing.T) {
r := newTestRenderer() // 80 wide: 24 + 2 + 40 fits
out := r.Render(Sidebar(Text("SIDE"), Text("MAIN")))
lines := strings.Split(out, "\n")
first := lines[0]
if !strings.Contains(first, "SIDE") || !strings.Contains(first, "MAIN") {
t.Fatalf("panes not side by side: %q", first)
}
if got := strings.Index(first, "MAIN"); got != 26 {
t.Errorf("main pane starts at %d, want 26 (24 sidebar + 2 gap)", got)
}
if got := lipgloss.Width(out); got != 80 {
t.Errorf("width = %d, want 80 (main grows to fill)", got)
}
}
func TestSidebarCollapsesWhenNarrow(t *testing.T) {
r := newTestRenderer()
r.Width = 50 // 24 + 2 + 40 no longer fits
out := r.Render(Sidebar(Text("SIDE"), Text("MAIN")))
lines := strings.Split(out, "\n")
if len(lines) < 2 {
t.Fatalf("expected stacked panes, got %q", out)
}
if !strings.Contains(lines[0], "SIDE") {
t.Errorf("sidebar not on top: %q", lines[0])
}
if strings.Contains(lines[0], "MAIN") {
t.Errorf("panes did not collapse: %q", lines[0])
}
found := false
for _, l := range lines[1:] {
if strings.Contains(l, "MAIN") {
found = true
}
}
if !found {
t.Errorf("main pane missing below sidebar: %q", out)
}
}
func TestSidebarRightSwapsPaneOrder(t *testing.T) {
r := newTestRenderer()
out := r.Render(Sidebar(Text("SIDE"), Text("MAIN"), SidebarRight()))
first := strings.Split(out, "\n")[0]
if strings.Index(first, "MAIN") > strings.Index(first, "SIDE") {
t.Errorf("sidebar not on the right: %q", first)
}
}
func TestSplitSharesWidthEqually(t *testing.T) {
r := newTestRenderer()
out := r.Render(Split(Text("LEFT"), Text("RIGHT")))
first := strings.Split(out, "\n")[0]
if got := lipgloss.Width(first); got != 80 {
t.Errorf("width = %d, want 80", got)
}
col := strings.Index(first, "RIGHT")
// Two panes and a 1-cell gap: the right pane starts just past the
// midpoint.
if col < 38 || col > 42 {
t.Errorf("right pane starts at %d, want ~40", col)
}
}
func TestGrowChildTakesLeftoverRowWidth(t *testing.T) {
r := newTestRenderer()
out := r.Render(BoxEl{
Direction: Row,
Style: Style{Width: 10},
Children: []Element{
Text("ab", WithTextStyle(Style{Grow: 1})),
Text("cd"),
},
})
first := strings.Split(out, "\n")[0]
if got := lipgloss.Width(first); got != 10 {
t.Errorf("width = %d, want 10", got)
}
if !strings.HasSuffix(first, "cd") {
t.Errorf("fixed child not pushed to the end: %q", first)
}
}
func TestJustifyEndPinsColumnContentToBottom(t *testing.T) {
r := newTestRenderer()
out := r.Render(BoxEl{
Direction: Column,
Justify: AlignEnd,
Style: Style{Height: 5, Width: 10},
Children: []Element{Text("X")},
})
lines := strings.Split(out, "\n")
if len(lines) != 5 {
t.Fatalf("line count = %d, want 5", len(lines))
}
if !strings.Contains(lines[4], "X") {
t.Errorf("content not on bottom line: %q", lines)
}
}
// Flex spacers keep their pre-Grow behavior: they expand against the
// terminal width even when the Row has no explicit Width.
func TestFlexSpacerStillExpandsInUnsizedRow(t *testing.T) {
r := newTestRenderer()
out := r.Render(Box(Row, Text("a"), Flex(), Text("b")))
first := strings.Split(out, "\n")[0]
if got := lipgloss.Width(first); got != 80 {
t.Errorf("width = %d, want 80", got)
}
if !strings.HasSuffix(first, "b") {
t.Errorf("trailing child not pushed to the edge: %q", first)
}
}