corrade-http-templates – Blame information for rev 62

Subversion Repositories:
Rev:
Rev Author Line No. Line
62 office 1 define( [
2 "qunit",
3 "jquery",
4 "ui/widgets/draggable"
5 ], function( QUnit, $ ) {
6  
7 var element;
8  
9 QUnit.module( "draggable: events", {
10 beforeEach: function() {
11 element = $( "<div>" ).appendTo( "#qunit-fixture" );
12 },
13 afterEach: function() {
14 element.draggable( "destroy" );
15 }
16 } );
17  
18 QUnit.test( "callbacks occurrence count", function( assert ) {
19 assert.expect( 3 );
20  
21 var start = 0,
22 stop = 0,
23 dragc = 0;
24  
25 element.draggable( {
26 start: function() {
27 start++;
28 },
29 drag: function() {
30 dragc++;
31 },
32 stop: function() {
33 stop++;
34 }
35 } );
36  
37 element.simulate( "drag", {
38 dx: 10,
39 dy: 10
40 } );
41  
42 assert.equal( start, 1, "start callback should happen exactly once" );
43 assert.equal( dragc, 3, "drag callback should happen exactly once per mousemove" );
44 assert.equal( stop, 1, "stop callback should happen exactly once" );
45 } );
46  
47 QUnit.test( "stopping the start callback", function( assert ) {
48 assert.expect( 3 );
49  
50 var start = 0,
51 stop = 0,
52 dragc = 0;
53  
54 element.draggable( {
55 start: function() {
56 start++;
57 return false;
58 },
59 drag: function() {
60 dragc++;
61 },
62 stop: function() {
63 stop++;
64 }
65 } );
66  
67 element.simulate( "drag", {
68 dx: 10,
69 dy: 10
70 } );
71  
72 assert.equal( start, 1, "start callback should happen exactly once" );
73 assert.equal( dragc, 0, "drag callback should not happen at all" );
74 assert.equal( stop, 0, "stop callback should not happen if there wasnt even a start" );
75 } );
76  
77 QUnit.test( "stopping the drag callback", function( assert ) {
78 assert.expect( 2 );
79  
80 var start = 0,
81 stop = 0,
82 dragc = 0;
83  
84 element.draggable( {
85 start: function() {
86 start++;
87 },
88 drag: function() {
89 dragc++;
90 return false;
91 },
92 stop: function() {
93 stop++;
94 }
95 } );
96  
97 element.simulate( "drag", {
98 dx: 10,
99 dy: 10
100 } );
101  
102 assert.equal( start, 1, "start callback should happen exactly once" );
103 assert.equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" );
104 } );
105  
106 QUnit.test( "stopping the stop callback", function( assert ) {
107 assert.expect( 1 );
108  
109 element.draggable( {
110 helper: "clone",
111 stop: function() {
112 return false;
113 }
114 } );
115  
116 element.simulate( "drag", {
117 dx: 10,
118 dy: 10
119 } );
120  
121 assert.ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
122 } );
123  
124 // http://bugs.jqueryui.com/ticket/6884
125 // Draggable: ui.offset.left differs between the "start" and "drag" hooks
126 QUnit.test( "position and offset in hash is consistent between start, drag, and stop", function( assert ) {
127 assert.expect( 4 );
128  
129 var startPos, startOffset, dragPos, dragOffset, stopPos, stopOffset;
130  
131 element = $( "<div style='margin: 2px;'></div>" ).appendTo( "#qunit-fixture" );
132  
133 element.draggable( {
134 start: function( event, ui ) {
135 startPos = ui.position;
136 startOffset = ui.offset;
137 },
138 drag: function( event, ui ) {
139 dragPos = ui.position;
140 dragOffset = ui.offset;
141 },
142 stop: function( event, ui ) {
143 stopPos = ui.position;
144 stopOffset = ui.offset;
145 }
146 } );
147  
148 element.simulate( "drag", {
149 dx: 10,
150 dy: 10,
151 moves: 1
152 } );
153  
154 startPos.left += 10;
155 startPos.top += 10;
156 startOffset.left += 10;
157 startOffset.top += 10;
158  
159 assert.deepEqual( startPos, dragPos, "start position equals drag position plus distance" );
160 assert.deepEqual( dragPos, stopPos, "drag position equals stop position" );
161 assert.deepEqual( startOffset, dragOffset, "start offset equals drag offset plus distance" );
162 assert.deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" );
163 } );
164  
165 } );