-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathbutton_test.go
More file actions
101 lines (79 loc) · 2.11 KB
/
button_test.go
File metadata and controls
101 lines (79 loc) · 2.11 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
package pony
import (
"testing"
uv "github.com/charmbracelet/ultraviolet"
)
func TestButtonWithMethods(t *testing.T) {
style := NewStyle().Fg(Hex("#00FF00")).Build()
hoverStyle := NewStyle().Fg(Hex("#00FFFF")).Build()
activeStyle := NewStyle().Fg(Hex("#FF00FF")).Build()
btn := NewButton("Click Me").
Style(style).
HoverStyle(hoverStyle).
ActiveStyle(activeStyle).
Border("rounded").
Padding(2).
Width(NewFixedConstraint(20)).
Height(NewFixedConstraint(3))
// Methods work - verified by golden tests
if btn == nil {
t.Error("Button should not be nil")
}
}
func TestButtonLayout(t *testing.T) {
btn := NewButton("Submit")
size := btn.Layout(Fixed(40, 10))
if size.Width == 0 || size.Height == 0 {
t.Errorf("Button size is zero: %v", size)
}
}
func TestButtonDraw(t *testing.T) {
btn := NewButton("Test").
Style(NewStyle().Bold().Build()).
Border("rounded").
Padding(1)
scr := uv.NewScreenBuffer(30, 10)
area := uv.Rect(0, 0, 30, 10)
btn.Draw(scr, area)
bounds := btn.Bounds()
if bounds.Dx() == 0 || bounds.Dy() == 0 {
t.Error("Button bounds not set after draw")
}
}
func TestButtonChildren(t *testing.T) {
btn := NewButton("Test")
children := btn.Children()
if children != nil {
t.Error("Button should have nil children")
}
}
func TestBoundsMapAllElements(t *testing.T) {
text1 := NewText("Hello")
text1.SetID("text1")
text2 := NewText("World")
text2.SetID("text2")
vstack := NewVStack(text1, text2)
vstack.SetID("vstack")
constraints := Fixed(20, 10)
vstack.Layout(constraints)
scr := uv.NewScreenBuffer(20, 10)
area := uv.Rect(0, 0, 20, 10)
vstack.Draw(scr, area)
boundsMap := NewBoundsMap()
walkAndRegister(vstack, boundsMap)
allElements := boundsMap.AllElements()
if len(allElements) == 0 {
t.Error("AllElements returned empty list")
}
if len(allElements) != 3 {
t.Errorf("AllElements returned %d elements, want 3", len(allElements))
}
for _, eb := range allElements {
if eb.Element == nil {
t.Error("Element in AllElements is nil")
}
if eb.Bounds.Dx() == 0 && eb.Bounds.Dy() == 0 {
t.Errorf("Element %s has zero bounds", eb.Element.ID())
}
}
}