-
Notifications
You must be signed in to change notification settings - Fork 1
/
decoration_test.go
120 lines (104 loc) · 3.2 KB
/
decoration_test.go
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
package goey
import (
"errors"
"image/color"
"testing"
"bitbucket.org/rj/goey/base"
"bitbucket.org/rj/goey/mock"
)
var (
black = color.RGBA{0, 0, 0, 0xff}
white = color.RGBA{0xff, 0xff, 0xff, 0xff}
red = color.RGBA{0xcc, 0xaa, 0x88, 0xff}
)
func (w *decorationElement) Props() base.Widget {
widget := w.props()
if w.child != nil {
widget.Child = w.child.(Proper).Props()
}
return widget
}
func decorationChildWidget(child base.Element) base.Widget {
if child == nil {
return nil
}
return child.(Proper).Props()
}
func TestDecorationMount(t *testing.T) {
child := &mock.Widget{Size: base.Size{15 * base.DIP, 15 * base.DIP}}
// These should all be able to mount without error.
testingMountWidgets(t,
&Decoration{Child: &Button{Text: "A"}, Insets: DefaultInsets()},
&Decoration{Child: &Label{Text: "A"}, Fill: red, Insets: DefaultInsets()},
&Decoration{Child: child},
&Decoration{Child: child, Stroke: black},
&Decoration{Child: child, Stroke: white},
&Decoration{Child: child, Stroke: red},
&Decoration{Child: child, Fill: black, Stroke: white, Radius: 4 * DIP, Insets: DefaultInsets()},
&Decoration{Child: child, Fill: white, Stroke: black},
&Decoration{Child: child, Fill: red},
)
// These should mount with an error.
err := errors.New("Mock error 1")
testingMountWidgetsFail(t, err,
&Decoration{Child: &mock.Widget{Err: err}},
)
testingMountWidgetsFail(t, err,
&Decoration{Insets: DefaultInsets(), Child: &mock.Widget{Err: err}},
)
}
func TestDecorationClose(t *testing.T) {
testingCloseWidgets(t,
&Decoration{Child: &Button{Text: "A"}},
&Decoration{},
&Decoration{Stroke: black},
&Decoration{Fill: black, Stroke: white, Radius: 4 * DIP},
)
}
func TestDecorationUpdate(t *testing.T) {
testingUpdateWidgets(t, []base.Widget{
&Decoration{Child: &Button{Text: "A"}},
&Decoration{},
&Decoration{Stroke: black},
&Decoration{Fill: black, Stroke: white, Radius: 4 * DIP},
&Decoration{Fill: white, Stroke: black},
&Decoration{Fill: red},
}, []base.Widget{
&Decoration{},
&Decoration{Child: &Button{Text: "A"}},
&Decoration{Fill: black, Stroke: white, Radius: 4 * DIP},
&Decoration{Stroke: black},
&Decoration{Fill: black, Stroke: black},
&Decoration{Fill: white},
})
}
func TestDecorationMinIntrinsicSize(t *testing.T) {
size1 := base.Size{10 * DIP, 20 * DIP}
size2 := base.Size{15 * DIP, 25 * DIP}
sizeZ := base.Size{}
insets := Insets{1 * DIP, 2 * DIP, 3 * DIP, 4 * DIP}
cases := []struct {
mockSize base.Size
insets Insets
out base.Size
}{
{size1, Insets{}, size1},
{size2, Insets{}, size2},
{sizeZ, Insets{}, sizeZ},
{size1, insets, base.Size{16 * DIP, 24 * DIP}},
{size2, insets, base.Size{21 * DIP, 29 * DIP}},
{sizeZ, insets, base.Size{6 * DIP, 4 * DIP}},
}
for i, v := range cases {
elem := decorationElement{
child: mock.NewIfNotZero(v.mockSize),
insets: v.insets,
}
if out := elem.MinIntrinsicWidth(base.Inf); out != v.out.Width {
t.Errorf("Case %d: Returned min intrinsic width does not match, got %v, want %v", i, out, v.out.Width)
}
if out := elem.MinIntrinsicHeight(base.Inf); out != v.out.Height {
t.Errorf("Case %d: Returned min intrinsic width does not match, got %v, want %v", i, out, v.out.Height)
}
}
}