-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckbox_test.go
81 lines (68 loc) · 2.02 KB
/
checkbox_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
package goey
import (
"math/rand"
"reflect"
"testing"
"testing/quick"
"bitbucket.org/rj/goey/base"
)
func checkboxValues(values []reflect.Value, rand *rand.Rand) {
// Get a string
labelValues(values, rand)
// Create a choices for value and disabled
values[1] = reflect.ValueOf(rand.Uint64()%2 == 0)
values[2] = reflect.ValueOf(rand.Uint64()%2 == 0)
}
func TestCheckboxMount(t *testing.T) {
testingMountWidgets(t,
&Checkbox{Value: false, Text: "A"},
&Checkbox{Value: true, Text: "B"},
&Checkbox{Value: false, Text: "C", Disabled: true},
&Checkbox{Value: true, Text: "D", Disabled: true},
&Checkbox{Text: ""},
)
t.Run("QuickCheck", func(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
f := func(text string, value, disabled bool) bool {
return testingMountWidget(t, &Checkbox{Text: text, Value: value, Disabled: disabled})
}
if err := quick.Check(f, &quick.Config{Values: checkboxValues}); err != nil {
t.Errorf("quick: %s", err)
}
})
}
func TestCheckboxClose(t *testing.T) {
testingCloseWidgets(t,
&Checkbox{Value: false, Text: "A"},
&Checkbox{Value: true, Text: "B", Disabled: true},
)
}
func TestCheckboxFocus(t *testing.T) {
testingCheckFocusAndBlur(t,
&Checkbox{Text: "A"},
&Checkbox{Text: "B"},
&Checkbox{Text: "C"},
)
}
func TestCheckboxClick(t *testing.T) {
var values [3]bool
testingCheckClick(t,
&Checkbox{Text: "A", OnChange: func(v bool) { values[0] = v }},
&Checkbox{Text: "B", Value: true, OnChange: func(v bool) { values[1] = v }},
&Checkbox{Text: "C", OnChange: func(v bool) { values[2] = v }},
)
if !values[0] || values[1] || !values[2] {
t.Errorf("OnChange failed, expected %v, got %v", [3]bool{true, false, true}, values[:])
}
}
func TestCheckboxUpdateProps(t *testing.T) {
testingUpdateWidgets(t, []base.Widget{
&Checkbox{Value: false, Text: "A"},
&Checkbox{Value: true, Text: "B", Disabled: true},
}, []base.Widget{
&Checkbox{Value: true, Text: "A--", Disabled: true},
&Checkbox{Value: false, Text: "B--", Disabled: false},
})
}