-
Notifications
You must be signed in to change notification settings - Fork 1
/
intinput_test.go
81 lines (69 loc) · 1.65 KB
/
intinput_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 (
"reflect"
"runtime"
"testing"
"bitbucket.org/rj/goey/base"
)
func TestIntInputMount(t *testing.T) {
testingMountWidgets(t,
&IntInput{Value: 1},
&IntInput{Value: 2, Placeholder: "..."},
&IntInput{Value: 3, Disabled: true},
&IntInput{Value: 4, Min: 0, Max: 10},
&IntInput{Value: 5, Min: -1000, Max: 1000},
)
}
func TestIntInputClose(t *testing.T) {
testingCloseWidgets(t,
&IntInput{Value: 1},
&IntInput{Value: 2, Placeholder: "..."},
&IntInput{Value: 3, Disabled: true},
&IntInput{Value: 4, Min: 0, Max: 10},
&IntInput{Value: 5, Min: -1000, Max: 1000},
)
}
func TestIntInputOnFocus(t *testing.T) {
testingCheckFocusAndBlur(t,
&IntInput{},
&IntInput{},
&IntInput{},
)
}
func TestIntInputOnChange(t *testing.T) {
log := make([]int64, 0)
testingTypeKeys(t, "1234",
&IntInput{OnChange: func(v int64) {
log = append(log, v)
}})
want := []int64{1, 12, 123, 1234}
if runtime.GOOS == "linux" {
// Control does not output events for intermediate typing.
want = []int64{1234}
}
if !reflect.DeepEqual(want, log) {
t.Errorf("Wanted %v, got %v", want, log)
}
}
func TestIntInputOnEnterKey(t *testing.T) {
got := int64(0)
testingTypeKeys(t, "1234\n",
&IntInput{OnEnterKey: func(v int64) {
got = v
}})
const want = 1234
if got != want {
t.Errorf("Wanted %v, got %v", want, got)
}
}
func TestIntInputUpdateProps(t *testing.T) {
testingUpdateWidgets(t, []base.Widget{
&IntInput{Value: 1},
&IntInput{Value: 2, Placeholder: "..."},
&IntInput{Value: 3, Disabled: true},
}, []base.Widget{
&IntInput{Value: 1},
&IntInput{Value: 4, Disabled: true},
&IntInput{Value: 5, Placeholder: "***"},
})
}