aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/draggable/draggable_events.js
blob: 07a53e22e5431e4c6af31f8352a8cc364e8079e7 (plain)
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
/*
 * draggable_events.js
 */
(function($) {

module("draggable: events");

test("callbacks occurrence count", function() {

	expect(3);

	var start = 0,
		stop = 0,
		dragc = 0,
		el = $("#draggable2").draggable({
			start: function() { start++; },
			drag: function() { dragc++; },
			stop: function() { stop++; }
		});

	el.simulate( "drag", {
		dx: 10,
		dy: 10
	});

	equal(start, 1, "start callback should happen exactly once");
	equal(dragc, 3, "drag callback should happen exactly once per mousemove");
	equal(stop, 1, "stop callback should happen exactly once");

});

test("stopping the start callback", function() {

	expect(3);

	var start = 0,
		stop = 0,
		dragc = 0,
		el = $("#draggable2").draggable({
			start: function() { start++; return false; },
			drag: function() { dragc++; },
			stop: function() { stop++; }
		});

	el.simulate( "drag", {
		dx: 10,
		dy: 10
	});

	equal(start, 1, "start callback should happen exactly once");
	equal(dragc, 0, "drag callback should not happen at all");
	equal(stop, 0, "stop callback should not happen if there wasnt even a start");

});

test("stopping the drag callback", function() {

	expect(3);

	var start = 0,
		stop = 0,
		dragc = 0,
		el = $("#draggable2").draggable({
			start: function() { start++;},
			drag: function() { dragc++; return false;  },
			stop: function() { stop++; }
		});

	el.simulate( "drag", {
		dx: 10,
		dy: 10
	});

	equal(start, 1, "start callback should happen exactly once");
	equal(dragc, 1, "drag callback should happen exactly once");
	equal(stop, 1, "stop callback should happen, as we need to actively stop the drag");

});

test("stopping the stop callback", function() {

	expect(1);

	var el = $("#draggable2").draggable({
		helper: 'clone',
		stop: function() { return false; }
	});

	el.simulate( "drag", {
		dx: 10,
		dy: 10
	});

	ok($("#draggable2").data('ui-draggable').helper, "the clone should not be deleted if the stop callback is stopped");


});

})(jQuery);