summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-FE/client/bower_components/jquery.event.drag-new/event.drop/test/handlers.js
blob: f38526ac6e73b71b31bf9af0d846ef7460c4c496 (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
;(function(){
	
	module("Event Handlers");
	
	// a simple re-usable test harness object
	var obj = {
		init: function( opts ){
			obj.$drag = $('<div class="drag"/>')
				.appendTo( document.body )
				.css({
					position: 'absolute',
					top: 0,
					left: 0,
					height: 100,
					width: 100
				})
				.bind("dragend",{ drop:'.drop' },function( event, dd ){
					same( dd.drop, obj.dragend, "drop (dragend)" );
				});
			obj.$drop = $('<div class="drop"/><div class="extra"/>')
				.appendTo( document.body )
				.css({
					position: 'absolute',
					top: 0,
					left: 0,
					height: 100,
					width: 100
				})
				.bind("dropinit dropstart drop dropend",function( event, dd ){
					obj[ event.type ] += 1;
					return obj.returned[ event.type ];
				});
			$.extend( obj, { dropinit:0, dropstart:0, drop:0, dropend:0 });
			$.drop({ mode:'overlap', multi:false });
			obj.returned = {};
			obj.dragend = null;
		},
		mouse: function(){
			var start = {
				pageX: Math.round( Math.random() * 90 ) + 5,
				pageY: Math.round( Math.random() * 90 ) + 5
			},
			end = {
				pageX: Math.round( Math.random() * 90 ) + start.pageX,
				pageY: Math.round( Math.random() * 90 ) + start.pageY
			};
			// simulate a complete mouse drag
			obj.$drag
				.fire("mousedown", start )
				.fire("mousemove", end )
				.fire("mouseup", end )
				.fire("click", end );
		},
		done: function( ms ){
			obj.$drag.remove();
			obj.$drop.remove();
			start();
		}
	};
	
	asyncTest('"dropinit" return false',function(){	
		expect( 5 );
		// test prep
		obj.init();
		obj.returned['dropinit'] = false;
		obj.dragend = [];
		// simulate a partial drag
		obj.mouse();
		// check counts
		equals( obj.dropinit, 1, "dropinit");
		equals( obj.dropstart, 0, "dropstart");
		equals( obj.drop, 0, "drop");
		equals( obj.dropend, 0, "dropend");
		// continue
		obj.done();
	});
	
	asyncTest('"dropstart" return false',function(){	
		expect( 5 );
		// test prep
		obj.init();
		obj.returned['dropstart'] = false;
		obj.dragend = [];
		// simulate a partial drag
		obj.mouse();
		// check counts
		equals( obj.dropinit, 1, "dropinit");
		equals( obj.dropstart, 1, "dropstart");
		equals( obj.drop, 0, "drop");
		equals( obj.dropend, 0, "dropend");
		// continue
		obj.done();
	});

	
	asyncTest('"drop" return false',function(){	
		expect( 5 );
		// test prep
		obj.init();// test DROP FALSE
		obj.returned['drop'] = false;
		obj.dragend = [];
		// simulate a partial drag
		obj.mouse();
		// check counts
		equals( obj.dropinit, 1, "dropinit");
		equals( obj.dropstart, 1, "dropstart");
		equals( obj.drop, 1, "drop");
		equals( obj.dropend, 0, "dropend");
		// continue
		obj.done();
	});
	
	asyncTest('"dropinit" return elements',function(){	
		expect( 5 );
		// test prep
		obj.init();
		obj.returned['dropinit'] = obj.$drop.eq(1);
		obj.dragend = [ obj.$drop[1] ];
		// simulate a partial drag
		obj.mouse();
		// check counts
		equals( obj.dropinit, 1, "dropinit");
		equals( obj.dropstart, 1, "dropstart");
		equals( obj.drop, 1, "drop");
		equals( obj.dropend, 1, "dropend");
		// continue
		obj.done();
	});
		
})();