aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/droppable/options.js
blob: f2d1757c25b668b511a62eded07b4e08b6bdf6d2 (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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
define( [
	"jquery",
	"ui/droppable"
], function( $ ) {

module( "droppable: options" );

/*
test( "{ accept '*' }, default ", function() {
	ok(false, 'missing test - untested code is broken code');
});

test( "{ accept: Selector }", function() {
	ok(false, 'missing test - untested code is broken code');
});

test( "{ accept: function(draggable) }", function() {
	ok(false, 'missing test - untested code is broken code');
});

test( "activeClass", function() {
	ok(false, 'missing test - untested code is broken code');
});
*/
test( "{ addClasses: true }, default", function( assert ) {
	expect( 1 );
	var el = $( "<div />" ).droppable({ addClasses: true });
	assert.hasClasses( el, "ui-droppable" );
	el.droppable( "destroy" );
});

test( "{ addClasses: false }", function( assert ) {
	expect( 1 );
	var el = $( "<div />" ).droppable({ addClasses: false });

	assert.lacksClasses( el, "ui-droppable" );
	el.droppable( "destroy" );
});

test( "scope", function() {
	expect( 4 );
	var droppableOffset, draggableOffset, oldDraggableOffset, dx, dy,
		draggable1 = $( "<div />" ).appendTo( "#qunit-fixture" ).draggable({ revert: "invalid" }),
		draggable2 = $( "<div />" ).appendTo( "#qunit-fixture" ).droppable(),
		droppable = $( "<div />" ).appendTo( "#qunit-fixture" ).droppable(),
		newScope = "test";

	draggable1.draggable( "option", "scope", newScope );
	droppable.droppable( "option", "scope", newScope );

	// Test that droppable accepts draggable with new scope.
	droppableOffset = droppable.offset();
	draggableOffset = draggable1.offset();
	dx = droppableOffset.left - draggableOffset.left;
	dy = droppableOffset.top - draggableOffset.top;

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

	draggableOffset = draggable1.offset();
	equal( draggableOffset.left, droppableOffset.left );
	equal( draggableOffset.top, droppableOffset.top );

	// Test that droppable doesn't accept draggable with old scope.
	draggableOffset = draggable2.offset();
	dx = droppableOffset.left - draggableOffset.left;
	dy = droppableOffset.top - draggableOffset.top;
	oldDraggableOffset = draggableOffset;

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

	draggableOffset = draggable2.offset();
	equal( draggableOffset.left, oldDraggableOffset.left );
	equal( draggableOffset.top, oldDraggableOffset.top );
});
/*
test( "greedy", function() {
	ok(false, 'missing test - untested code is broken code');
});

test( "hoverClass", function() {
	ok(false, 'missing test - untested code is broken code');
});

test( "tolerance, fit", function() {
	ok(false, 'missing test - untested code is broken code');
});
*/

test( "tolerance, intersect", function() {
	expect( 2 );

	var draggable, droppable,
		dataset = [
			[ 0, 0, false, "too far up and left" ],
			[ 6, 0, false, "too far up" ],
			[ 0, 6, false, "too far left" ],
			[ 6, 6, true, "top left corner" ],
			[ 14, 14, true, "bottom right corner" ],
			[ 15, 6, false, "too far right" ],
			[ 6, 15, false, "too far down" ],
			[ 15, 15, false, "too far down and right" ]
		];

	draggable = $( "<div />" )
		.appendTo( "#qunit-fixture" )
		.css({
			width: 10,
			height: 10,
			position: "absolute",

			// http://bugs.jqueryui.com/ticket/6876
			// Droppable: droppable region is offset by draggables margin
			marginTop: 3,
			marginLeft: 3
		})
		.draggable();

	droppable = $( "<div />" )
		.appendTo( "#qunit-fixture" )
		.css({ width: 10, height: 10, position: "absolute", top: 13, left: 13 })
		.droppable({ tolerance: "intersect" });

	$.each( dataset, function() {
		var data = this;

		draggable.css({
			top: 0,
			left: 0
		});

		droppable.unbind( "drop" ).bind( "drop", function() {
			equal( true, data[ 2 ], data[ 3 ] );
		});

		$( draggable ).simulate( "drag", {
			dx: data[ 0 ],
			dy: data[ 1 ]
		});
	});
});

test( "tolerance, pointer", function() {
	expect( 3 );

	var draggable, droppable,
		dataset = [
			[ -1, -1, false, "too far up and left" ],
			[ -1, 0, false, "too far left" ],
			[ 0, -1, false, "too far up" ],
			[ 0, 0, true, "top left corner" ],
			[ 9, 9, true, "bottom right corner" ],
			[ 10, 9, false, "too far right" ],
			[ 9, 10, false, "too far down" ],
			[ 10, 10, false, "too far down and right" ]
		];

	draggable = $( "<div />" )
		.appendTo( "#qunit-fixture" )
		.css({ width: 10, height: 10, position: "absolute" })
		.draggable();

	droppable = $( "<div />" )
		.appendTo( "#qunit-fixture" )
		.css({ width: 10, height: 10, position: "absolute", top: 5, left: 5 })
		.droppable({ tolerance: "pointer" });

	$.each( dataset, function() {
		var data = this;

		droppable.unbind( "drop" ).bind( "drop", function() {
			equal( true, data[ 2 ], data[ 3 ] );
		});

		$( draggable ).simulate( "drag", {
			dx: ( data[ 0 ] - $( draggable ).position().left ),
			dy: ( data[ 1 ] - $( draggable ).position().top )
		});
	});

	// http://bugs.jqueryui.com/ticket/4977 - tolerance, pointer - bug when pointer outside draggable
	draggable.css({ top: 0, left: 0 }).draggable( "option", "axis", "x" );
	droppable.css({ top: 15, left: 15 });

	droppable.unbind( "drop" ).bind( "drop", function() {
		ok( true, "drop fires as long as pointer is within droppable" );
	});

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

/*
test( "tolerance, touch", function() {
	ok(false, 'missing test - untested code is broken code');
});
*/
} );