-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathevents.js
151 lines (118 loc) · 3.89 KB
/
events.js
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
(function() {
var NumericTextBox = kendo.ui.NumericTextBox,
input;
module("kendo.ui.NumericTextBox Events", {
setup: function() {
input = $("<input />").appendTo(QUnit.fixture);
},
teardown: function() {
kendo.destroy(QUnit.fixture);
}
});
test("_change should call value() method", 2, function() {
var textbox = new NumericTextBox(input, {
change: function() {
ok(true);
equal(textbox.value(), 22);
}
});
textbox._change("22");
});
test("raise DOM change", 2, function() {
var textbox = new NumericTextBox(input);
input.bind("change", function() {
ok(true);
equal(textbox.value(), 22);
});
textbox._change("22");
});
test("does not force element's DOM change event when the user manually edits the value and presses 'Enter'", 0, function() {
var textbox = new NumericTextBox(input);
input.bind("change", function() {
ok(false);
});
input.focus().val(1)
.trigger($.Event("keydown", {keyCode: 49}))
.trigger($.Event("keydown", {keyCode: 13}));
});
test("raise change on enter", 2, function() {
var textbox = new NumericTextBox(input);
input.bind("change", function() {
ok(true);
equal(textbox.value(), 22);
});
input.focus().val("22").trigger({type:"keydown", keyCode: 13});
});
test("click arrow should focus input", function() {
var textbox = new NumericTextBox(input);
textbox._upArrow.mousedown();
equal(input[0], document.activeElement);
});
test("value() should not raise change event", 0, function() {
var textbox = new NumericTextBox(input, {
change: function() {
ok(false);
}
});
textbox.value("22");
textbox._blur();
});
asyncTest("raise spin event", 2, function() {
var textbox = new NumericTextBox(input, {
value: 10,
spin: function() {
start();
ok(true);
equal(textbox.value(), 11);
}
});
textbox._step(1);
});
asyncTest("raise spin event on up arrrow", 2, function() {
var textbox = new NumericTextBox(input, {
value: 10,
spin: function() {
start();
ok(true);
equal(textbox.value(), 11);
}
});
input.trigger({
type: "keydown",
keyCode: kendo.keys.UP
});
});
test("focus should hide the _text and show the input value", 2, function() {
var textbox = new NumericTextBox(input);
var origin = window.setTimeout;
window.setTimeout = function(func) { func() };
textbox._text.focus();
ok(!textbox._text.is(":visible"));
equal(input[0], document.activeElement);
window.setTimeout = origin;
});
test("DOM Change event fires when value is changed and TAB is pressed", 1, function() {
var textbox = new NumericTextBox(input);
var calls = 0;
input.change(function() {
calls++;
});
input.focus().val(1)
.trigger($.Event("keydown", {keyCode: 38}))
.trigger($.Event("keydown", {keyCode: 9}));
textbox._blur();
equal(calls, 1);
});
test("Spin event is not fired if value is not altered", 1, function() {
var calls = 0;
var textbox = new NumericTextBox(input, {
value: 50,
step: 0,
spin: function() {
calls++;
}
});
textbox._step(1);
equal(calls, 0);
});
})();