-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathcheck_test.go
102 lines (85 loc) · 1.92 KB
/
check_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
package widget_test
import (
"testing"
"github.com/stretchr/testify/assert"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/test"
"fyne.io/fyne/v2/widget"
)
func TestCheck_Binding(t *testing.T) {
c := widget.NewCheck("", nil)
c.SetChecked(true)
assert.Equal(t, true, c.Checked)
val := binding.NewBool()
c.Bind(val)
waitForBinding()
assert.Equal(t, false, c.Checked)
err := val.Set(true)
assert.Nil(t, err)
waitForBinding()
assert.Equal(t, true, c.Checked)
c.SetChecked(false)
v, err := val.Get()
assert.Nil(t, err)
assert.Equal(t, false, v)
c.Unbind()
waitForBinding()
assert.Equal(t, false, c.Checked)
}
func TestCheck_Layout(t *testing.T) {
test.NewTempApp(t)
for name, tt := range map[string]struct {
text string
checked bool
disabled bool
}{
"checked": {
text: "Test",
checked: true,
},
"unchecked": {
text: "Test",
},
"checked_disabled": {
text: "Test",
checked: true,
disabled: true,
},
"unchecked_disabled": {
text: "Test",
disabled: true,
},
} {
t.Run(name, func(t *testing.T) {
check := &widget.Check{
Text: tt.text,
Checked: tt.checked,
}
if tt.disabled {
check.Disable()
}
window := test.NewTempWindow(t, &fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{check}})
window.Resize(check.MinSize().Max(fyne.NewSize(150, 200)))
test.AssertRendersToMarkup(t, "check/layout_"+name+".xml", window.Canvas())
})
}
}
func TestNewCheckWithData(t *testing.T) {
val := binding.NewBool()
err := val.Set(true)
assert.Nil(t, err)
c := widget.NewCheckWithData("", val)
waitForBinding()
assert.Equal(t, true, c.Checked)
c.SetChecked(false)
v, err := val.Get()
assert.Nil(t, err)
assert.Equal(t, false, v)
}
func TestCheck_SetText(t *testing.T) {
check := &widget.Check{Text: "Test"}
check.SetText("New")
assert.Equal(t, "New", check.Text)
}