1 |
/* |
2 |
* sortable_events.js |
3 |
*/ |
4 |
(function($) { |
5 |
|
6 |
module("sortable: events"); |
7 |
|
8 |
test("start", function() { |
9 |
expect( 7 ); |
10 |
|
11 |
var hash; |
12 |
$("#sortable").sortable({ |
13 |
start: function( e, ui ) { |
14 |
hash = ui; |
15 |
} |
16 |
}).find("li:eq(0)").simulate( "drag", { |
17 |
dy: 10 |
18 |
}); |
19 |
|
20 |
ok(hash, "start event triggered"); |
21 |
ok(hash.helper, "UI hash includes: helper"); |
22 |
ok(hash.placeholder, "UI hash includes: placeholder"); |
23 |
ok(hash.item, "UI hash includes: item"); |
24 |
ok(!hash.sender, "UI hash does not include: sender"); |
25 |
|
26 |
// todo: see if these events should actually have sane values in them |
27 |
ok("position" in hash, "UI hash includes: position"); |
28 |
ok("offset" in hash, "UI hash includes: offset"); |
29 |
|
30 |
|
31 |
}); |
32 |
|
33 |
test("sort", function() { |
34 |
expect( 7 ); |
35 |
|
36 |
var hash; |
37 |
$("#sortable").sortable({ |
38 |
sort: function( e, ui ) { |
39 |
hash = ui; |
40 |
} |
41 |
}).find("li:eq(0)").simulate( "drag", { |
42 |
dy: 10 |
43 |
}); |
44 |
|
45 |
ok(hash, "sort event triggered"); |
46 |
ok(hash.helper, "UI hash includes: helper"); |
47 |
ok(hash.placeholder, "UI hash includes: placeholder"); |
48 |
ok(hash.position && ("top" in hash.position && "left" in hash.position), "UI hash includes: position"); |
49 |
ok(hash.offset && (hash.offset.top && hash.offset.left), "UI hash includes: offset"); |
50 |
ok(hash.item, "UI hash includes: item"); |
51 |
ok(!hash.sender, "UI hash does not include: sender"); |
52 |
|
53 |
}); |
54 |
|
55 |
test("change", function() { |
56 |
expect( 8 ); |
57 |
|
58 |
var hash; |
59 |
$("#sortable").sortable({ |
60 |
change: function( e, ui ) { |
61 |
hash = ui; |
62 |
} |
63 |
}).find("li:eq(0)").simulate( "drag", { |
64 |
dx: 1, |
65 |
dy: 1 |
66 |
}); |
67 |
|
68 |
ok(!hash, "1px drag, change event should not be triggered"); |
69 |
|
70 |
$("#sortable").sortable({ |
71 |
change: function( e, ui ) { |
72 |
hash = ui; |
73 |
} |
74 |
}).find("li:eq(0)").simulate( "drag", { |
75 |
dy: 22 |
76 |
}); |
77 |
|
78 |
ok(hash, "change event triggered"); |
79 |
ok(hash.helper, "UI hash includes: helper"); |
80 |
ok(hash.placeholder, "UI hash includes: placeholder"); |
81 |
ok(hash.position && ("top" in hash.position && "left" in hash.position), "UI hash includes: position"); |
82 |
ok(hash.offset && (hash.offset.top && hash.offset.left), "UI hash includes: offset"); |
83 |
ok(hash.item, "UI hash includes: item"); |
84 |
ok(!hash.sender, "UI hash does not include: sender"); |
85 |
|
86 |
}); |
87 |
|
88 |
test("beforeStop", function() { |
89 |
expect( 7 ); |
90 |
|
91 |
var hash; |
92 |
$("#sortable").sortable({ |
93 |
beforeStop: function( e, ui ) { |
94 |
hash = ui; |
95 |
} |
96 |
}).find("li:eq(0)").simulate( "drag", { |
97 |
dy: 20 |
98 |
}); |
99 |
|
100 |
ok(hash, "beforeStop event triggered"); |
101 |
ok(hash.helper, "UI hash includes: helper"); |
102 |
ok(hash.placeholder, "UI hash includes: placeholder"); |
103 |
ok(hash.position && ("top" in hash.position && "left" in hash.position), "UI hash includes: position"); |
104 |
ok(hash.offset && (hash.offset.top && hash.offset.left), "UI hash includes: offset"); |
105 |
ok(hash.item, "UI hash includes: item"); |
106 |
ok(!hash.sender, "UI hash does not include: sender"); |
107 |
|
108 |
}); |
109 |
|
110 |
test("stop", function() { |
111 |
expect( 7 ); |
112 |
|
113 |
var hash; |
114 |
$("#sortable").sortable({ |
115 |
stop: function( e, ui ) { |
116 |
hash = ui; |
117 |
} |
118 |
}).find("li:eq(0)").simulate( "drag", { |
119 |
dy: 20 |
120 |
}); |
121 |
|
122 |
ok(hash, "stop event triggered"); |
123 |
ok(!hash.helper, "UI should not include: helper"); |
124 |
ok(hash.placeholder, "UI hash includes: placeholder"); |
125 |
ok(hash.position && ("top" in hash.position && "left" in hash.position), "UI hash includes: position"); |
126 |
ok(hash.offset && (hash.offset.top && hash.offset.left), "UI hash includes: offset"); |
127 |
ok(hash.item, "UI hash includes: item"); |
128 |
ok(!hash.sender, "UI hash does not include: sender"); |
129 |
|
130 |
}); |
131 |
|
132 |
test("update", function() { |
133 |
expect( 8 ); |
134 |
|
135 |
var hash; |
136 |
$("#sortable").sortable({ |
137 |
update: function( e, ui ) { |
138 |
hash = ui; |
139 |
} |
140 |
}).find("li:eq(0)").simulate( "drag", { |
141 |
dx: 1, |
142 |
dy: 1 |
143 |
}); |
144 |
|
145 |
ok(!hash, "1px drag, update event should not be triggered"); |
146 |
|
147 |
$("#sortable").sortable({ |
148 |
update: function( e, ui ) { |
149 |
hash = ui; |
150 |
} |
151 |
}).find("li:eq(0)").simulate( "drag", { |
152 |
dy: 22 |
153 |
}); |
154 |
|
155 |
ok(hash, "update event triggered"); |
156 |
ok(!hash.helper, "UI hash should not include: helper"); |
157 |
ok(hash.placeholder, "UI hash includes: placeholder"); |
158 |
ok(hash.position && ("top" in hash.position && "left" in hash.position), "UI hash includes: position"); |
159 |
ok(hash.offset && (hash.offset.top && hash.offset.left), "UI hash includes: offset"); |
160 |
ok(hash.item, "UI hash includes: item"); |
161 |
ok(!hash.sender, "UI hash does not include: sender"); |
162 |
|
163 |
}); |
164 |
|
165 |
test("#3019: Stop fires too early", function() { |
166 |
expect(2); |
167 |
|
168 |
var helper = null, |
169 |
el = $("#sortable").sortable({ |
170 |
stop: function(event, ui) { |
171 |
helper = ui.helper; |
172 |
} |
173 |
}); |
174 |
|
175 |
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, "Dragging the sortable"); |
176 |
equal(helper, null, "helper should be false"); |
177 |
|
178 |
}); |
179 |
|
180 |
test("#4752: link event firing on sortable with connect list", function () { |
181 |
expect( 10 ); |
182 |
|
183 |
var fired = {}, |
184 |
hasFired = function (type) { return (type in fired) && (true === fired[type]); }; |
185 |
|
186 |
$("#sortable").clone().attr("id", "sortable2").insertAfter("#sortable"); |
187 |
|
188 |
$("#qunit-fixture ul").sortable({ |
189 |
connectWith: "#qunit-fixture ul", |
190 |
change: function () { |
191 |
fired.change = true; |
192 |
}, |
193 |
receive: function () { |
194 |
fired.receive = true; |
195 |
}, |
196 |
remove: function () { |
197 |
fired.remove = true; |
198 |
} |
199 |
}); |
200 |
|
201 |
$("#qunit-fixture ul").bind("click.ui-sortable-test", function () { |
202 |
fired.click = true; |
203 |
}); |
204 |
|
205 |
$("#sortable li:eq(0)").simulate("click"); |
206 |
ok(!hasFired("change"), "Click only, change event should not have fired"); |
207 |
ok(hasFired("click"), "Click event should have fired"); |
208 |
|
209 |
// Drag an item within the first list |
210 |
fired = {}; |
211 |
$("#sortable li:eq(0)").simulate("drag", { dx: 0, dy: 40 }); |
212 |
ok(hasFired("change"), "40px drag, change event should have fired"); |
213 |
ok(!hasFired("receive"), "Receive event should not have fired"); |
214 |
ok(!hasFired("remove"), "Remove event should not have fired"); |
215 |
ok(!hasFired("click"), "Click event should not have fired"); |
216 |
|
217 |
// Drag an item from the first list to the second, connected list |
218 |
fired = {}; |
219 |
$("#sortable li:eq(0)").simulate("drag", { dx: 0, dy: 150 }); |
220 |
ok(hasFired("change"), "150px drag, change event should have fired"); |
221 |
ok(hasFired("receive"), "Receive event should have fired"); |
222 |
ok(hasFired("remove"), "Remove event should have fired"); |
223 |
ok(!hasFired("click"), "Click event should not have fired"); |
224 |
}); |
225 |
|
226 |
/* |
227 |
test("receive", function() { |
228 |
ok(false, "missing test - untested code is broken code."); |
229 |
}); |
230 |
|
231 |
test("remove", function() { |
232 |
ok(false, "missing test - untested code is broken code."); |
233 |
}); |
234 |
*/ |
235 |
|
236 |
test( "over", function() { |
237 |
expect( 8 ); |
238 |
|
239 |
var hash, |
240 |
overCount = 0; |
241 |
|
242 |
$( "#sortable" ).sortable({ |
243 |
over: function( e, ui ) { |
244 |
hash = ui; |
245 |
overCount++; |
246 |
} |
247 |
}).find( "li:eq(0)" ).simulate( "drag", { |
248 |
dy: 20 |
249 |
}); |
250 |
|
251 |
ok( hash, "stop event triggered" ); |
252 |
ok( hash.helper, "UI should not include: helper" ); |
253 |
ok( hash.placeholder, "UI hash includes: placeholder" ); |
254 |
ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); |
255 |
ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); |
256 |
ok( hash.item, "UI hash includes: item" ); |
257 |
ok( hash.sender, "UI hash does not include: sender" ); |
258 |
equal( overCount, 1, "over fires only once" ); |
259 |
}); |
260 |
|
261 |
/* |
262 |
test("out", function() { |
263 |
ok(false, "missing test - untested code is broken code."); |
264 |
}); |
265 |
|
266 |
test("activate", function() { |
267 |
ok(false, "missing test - untested code is broken code."); |
268 |
}); |
269 |
|
270 |
test("deactivate", function() { |
271 |
ok(false, "missing test - untested code is broken code."); |
272 |
}); |
273 |
*/ |
274 |
|
275 |
})(jQuery); |