6 module("sortable: events");
8 test("start", function() {
12 $("#sortable").sortable({
13 start: function( e, ui ) {
16 }).find("li:eq(0)").simulate( "drag", {
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");
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");
33 test("sort", function() {
37 $("#sortable").sortable({
38 sort: function( e, ui ) {
41 }).find("li:eq(0)").simulate( "drag", {
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");
55 test("change", function() {
59 $("#sortable").sortable({
60 change: function( e, ui ) {
63 }).find("li:eq(0)").simulate( "drag", {
68 ok(!hash, "1px drag, change event should not be triggered");
70 $("#sortable").sortable({
71 change: function( e, ui ) {
74 }).find("li:eq(0)").simulate( "drag", {
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");
88 test("beforeStop", function() {
92 $("#sortable").sortable({
93 beforeStop: function( e, ui ) {
96 }).find("li:eq(0)").simulate( "drag", {
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");
110 test("stop", function() {
114 $("#sortable").sortable({
115 stop: function( e, ui ) {
118 }).find("li:eq(0)").simulate( "drag", {
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");
132 test("update", function() {
136 $("#sortable").sortable({
137 update: function( e, ui ) {
140 }).find("li:eq(0)").simulate( "drag", {
145 ok(!hash, "1px drag, update event should not be triggered");
147 $("#sortable").sortable({
148 update: function( e, ui ) {
151 }).find("li:eq(0)").simulate( "drag", {
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");
165 test("#3019: Stop fires too early", function() {
169 el = $("#sortable").sortable({
170 stop: function(event, ui) {
175 TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, "Dragging the sortable");
176 equal(helper, null, "helper should be false");
180 test("#4752: link event firing on sortable with connect list", function () {
184 hasFired = function (type) { return (type in fired) && (true === fired[type]); };
186 $("#sortable").clone().attr("id", "sortable2").insertAfter("#sortable");
188 $("#qunit-fixture ul").sortable({
189 connectWith: "#qunit-fixture ul",
190 change: function () {
193 receive: function () {
194 fired.receive = true;
196 remove: function () {
201 $("#qunit-fixture ul").bind("click.ui-sortable-test", function () {
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");
209 // Drag an item within the first list
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");
217 // Drag an item from the first list to the second, connected list
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");
227 test("receive", function() {
228 ok(false, "missing test - untested code is broken code.");
231 test("remove", function() {
232 ok(false, "missing test - untested code is broken code.");
236 test( "over", function() {
242 $( "#sortable" ).sortable({
243 over: function( e, ui ) {
247 }).find( "li:eq(0)" ).simulate( "drag", {
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" );
262 test("out", function() {
263 ok(false, "missing test - untested code is broken code.");
266 test("activate", function() {
267 ok(false, "missing test - untested code is broken code.");
270 test("deactivate", function() {
271 ok(false, "missing test - untested code is broken code.");