nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery.event.drag-new / event.drop / test / handlers.js
1 ;(function(){
2         
3         module("Event Handlers");
4         
5         // a simple re-usable test harness object
6         var obj = {
7                 init: function( opts ){
8                         obj.$drag = $('<div class="drag"/>')
9                                 .appendTo( document.body )
10                                 .css({
11                                         position: 'absolute',
12                                         top: 0,
13                                         left: 0,
14                                         height: 100,
15                                         width: 100
16                                 })
17                                 .bind("dragend",{ drop:'.drop' },function( event, dd ){
18                                         same( dd.drop, obj.dragend, "drop (dragend)" );
19                                 });
20                         obj.$drop = $('<div class="drop"/><div class="extra"/>')
21                                 .appendTo( document.body )
22                                 .css({
23                                         position: 'absolute',
24                                         top: 0,
25                                         left: 0,
26                                         height: 100,
27                                         width: 100
28                                 })
29                                 .bind("dropinit dropstart drop dropend",function( event, dd ){
30                                         obj[ event.type ] += 1;
31                                         return obj.returned[ event.type ];
32                                 });
33                         $.extend( obj, { dropinit:0, dropstart:0, drop:0, dropend:0 });
34                         $.drop({ mode:'overlap', multi:false });
35                         obj.returned = {};
36                         obj.dragend = null;
37                 },
38                 mouse: function(){
39                         var start = {
40                                 pageX: Math.round( Math.random() * 90 ) + 5,
41                                 pageY: Math.round( Math.random() * 90 ) + 5
42                         },
43                         end = {
44                                 pageX: Math.round( Math.random() * 90 ) + start.pageX,
45                                 pageY: Math.round( Math.random() * 90 ) + start.pageY
46                         };
47                         // simulate a complete mouse drag
48                         obj.$drag
49                                 .fire("mousedown", start )
50                                 .fire("mousemove", end )
51                                 .fire("mouseup", end )
52                                 .fire("click", end );
53                 },
54                 done: function( ms ){
55                         obj.$drag.remove();
56                         obj.$drop.remove();
57                         start();
58                 }
59         };
60         
61         asyncTest('"dropinit" return false',function(){ 
62                 expect( 5 );
63                 // test prep
64                 obj.init();
65                 obj.returned['dropinit'] = false;
66                 obj.dragend = [];
67                 // simulate a partial drag
68                 obj.mouse();
69                 // check counts
70                 equals( obj.dropinit, 1, "dropinit");
71                 equals( obj.dropstart, 0, "dropstart");
72                 equals( obj.drop, 0, "drop");
73                 equals( obj.dropend, 0, "dropend");
74                 // continue
75                 obj.done();
76         });
77         
78         asyncTest('"dropstart" return false',function(){        
79                 expect( 5 );
80                 // test prep
81                 obj.init();
82                 obj.returned['dropstart'] = false;
83                 obj.dragend = [];
84                 // simulate a partial drag
85                 obj.mouse();
86                 // check counts
87                 equals( obj.dropinit, 1, "dropinit");
88                 equals( obj.dropstart, 1, "dropstart");
89                 equals( obj.drop, 0, "drop");
90                 equals( obj.dropend, 0, "dropend");
91                 // continue
92                 obj.done();
93         });
94
95         
96         asyncTest('"drop" return false',function(){     
97                 expect( 5 );
98                 // test prep
99                 obj.init();// test DROP FALSE
100                 obj.returned['drop'] = false;
101                 obj.dragend = [];
102                 // simulate a partial drag
103                 obj.mouse();
104                 // check counts
105                 equals( obj.dropinit, 1, "dropinit");
106                 equals( obj.dropstart, 1, "dropstart");
107                 equals( obj.drop, 1, "drop");
108                 equals( obj.dropend, 0, "dropend");
109                 // continue
110                 obj.done();
111         });
112         
113         asyncTest('"dropinit" return elements',function(){      
114                 expect( 5 );
115                 // test prep
116                 obj.init();
117                 obj.returned['dropinit'] = obj.$drop.eq(1);
118                 obj.dragend = [ obj.$drop[1] ];
119                 // simulate a partial drag
120                 obj.mouse();
121                 // check counts
122                 equals( obj.dropinit, 1, "dropinit");
123                 equals( obj.dropstart, 1, "dropstart");
124                 equals( obj.drop, 1, "drop");
125                 equals( obj.dropend, 1, "dropend");
126                 // continue
127                 obj.done();
128         });
129                 
130 })();