forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_test.go
151 lines (117 loc) · 3 KB
/
container_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
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
package fyne
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestContainer_Add(t *testing.T) {
box := new(dummyObject)
container := NewContainerWithoutLayout()
assert.Equal(t, 0, len(container.Objects))
container.Add(box)
assert.Equal(t, 1, len(container.Objects))
}
func TestContainer_CustomLayout(t *testing.T) {
box := new(dummyObject)
layout := new(customLayout)
container := NewContainerWithLayout(layout, box)
size := layout.MinSize(container.Objects)
assert.Equal(t, size, container.MinSize())
assert.Equal(t, size, container.Size())
assert.Equal(t, size, box.Size())
}
func TestContainer_Hide(t *testing.T) {
box := new(dummyObject)
container := NewContainerWithoutLayout(box)
assert.True(t, container.Visible())
assert.True(t, box.Visible())
container.Hide()
assert.False(t, container.Visible())
assert.True(t, box.Visible())
}
func TestContainer_MinSize(t *testing.T) {
box := new(dummyObject)
minSize := box.MinSize()
container := NewContainerWithoutLayout(box)
assert.Equal(t, minSize, container.MinSize())
}
func TestContainer_Move(t *testing.T) {
box := new(dummyObject)
container := NewContainerWithoutLayout(box)
size := NewSize(100, 100)
pos := NewPos(0, 0)
container.Resize(size)
assert.Equal(t, pos, box.Position())
pos = NewPos(10, 10)
container.Move(pos)
assert.Equal(t, pos, container.Position())
assert.Equal(t, NewPos(0, 0), box.Position())
box.Move(pos)
assert.Equal(t, pos, box.Position())
}
func TestContainer_NilLayout(t *testing.T) {
box := new(dummyObject)
boxSize := box.size
container := NewContainerWithoutLayout(box)
size := NewSize(100, 100)
container.Resize(size)
assert.Equal(t, size, container.Size())
assert.Equal(t, boxSize, box.Size())
}
func TestContainer_Remove(t *testing.T) {
box := new(dummyObject)
container := NewContainerWithoutLayout(box)
assert.Equal(t, 1, len(container.Objects))
container.Remove(box)
assert.Equal(t, 0, len(container.Objects))
}
func TestContainer_Show(t *testing.T) {
box := new(dummyObject)
container := NewContainerWithoutLayout(box)
container.Hide()
assert.True(t, box.Visible())
assert.False(t, container.Visible())
container.Show()
assert.True(t, box.Visible())
assert.True(t, container.Visible())
}
type customLayout struct {
}
func (c *customLayout) Layout(objs []CanvasObject, size Size) {
for _, child := range objs {
child.Resize(size)
}
}
func (c *customLayout) MinSize(_ []CanvasObject) Size {
return NewSize(10, 10)
}
type dummyObject struct {
size Size
pos Position
hidden bool
}
func (d *dummyObject) Size() Size {
return d.size
}
func (d *dummyObject) Resize(size Size) {
d.size = size
}
func (d *dummyObject) Position() Position {
return d.pos
}
func (d *dummyObject) Move(pos Position) {
d.pos = pos
}
func (d *dummyObject) MinSize() Size {
return NewSize(5, 5)
}
func (d *dummyObject) Visible() bool {
return !d.hidden
}
func (d *dummyObject) Show() {
d.hidden = false
}
func (d *dummyObject) Hide() {
d.hidden = true
}
func (d *dummyObject) Refresh() {
}