18
base: '../../../build/',
29
}).use('event-synthetic', 'event-gestures', 'dd', 'console', 'test', 'substitute', 'selector-css3', function(Y) {
34
} else if (Y.UA.ie > 7) {
36
} else if (Y.UA.ie < 7) {
38
} else if (Y.UA.ie < 8) {
43
var myConsole = new Y.Console({
44
height: Y.one(window).get('winHeight') + 'px',
49
_resetCount = function() {
50
Y.each(_count, function(v, k) {
54
_fakeStart = function(node) {
56
Y.DD.DDM._noShim = true;
57
node._dragThreshMet = true;
58
node.set('activeHandle', node.get('node'));
59
node._setStartPosition(node.get('node').getXY());
60
Y.DD.DDM.activeDrag = node;
64
_fakeEnd = function(node) {
67
node._handleMouseUp();
68
Y.DD.DDM._noShim = false;
70
_moveNode = function(node, num, flip) {
72
Y.DD.DDM._move({ pageX: 110, pageY: num });
74
Y.DD.DDM._move({ pageX: num, pageY: 110 });
77
_moveNodeAll = function(node, max, flip) {
78
for (var i = 0; i < max; i++) {
79
_moveNode(node, i, flip);
82
_fakeMove = function(node, max, flip) {
84
_moveNodeAll(node, max, flip);
92
_handleCount = function(e) {
93
if (!_count[e.type]) {
105
tearDown : function() {
107
test_shim: function() {
108
var s = Y.DD.DDM._pg;
109
Y.Assert.isNull(s, 'Shim: Node Instance');
111
test_drop_setup: function() {
112
drop = new Y.DD.Drop({ node: '#drop', data: { one: 1, two: 2, three: 3 } });
113
Y.Assert.isInstanceOf(Y.DD.Drop, drop, 'drop: Drop Instance');
114
Y.Assert.isTrue(drop.get('node').hasClass('yui3-dd-drop'), 'drop: Drop Instance ClassName');
116
test_drop_setup_events: function() {
117
Y.each(dd_events, function(v) {
118
var handle = drop.on(v, _handleCount);
119
Y.Assert.isInstanceOf(Y.EventHandle, handle, 'drop:handle [' + v + ']: Handle Instance');
122
test_drag_setup: function() {
123
dd = new Y.DD.Drag({ node: '#drag' });
124
Y.Assert.isInstanceOf(Y.DD.Drag, dd, 'dd: Drag Instance');
125
Y.Assert.isTrue(dd.get('node').hasClass('yui3-dd-draggable'), 'dd: Drag Instance ClassName');
127
test_shim_after: function() {
128
var s = Y.DD.DDM._pg;
129
Y.Assert.isInstanceOf(Y.Node, s, 'Shim: Node Instance');
131
test_drag_drop_setup: function() {
133
dd = new Y.DD.Drag({ node: '#drag', target: true });
134
Y.Assert.isInstanceOf(Y.DD.Drag, dd, 'dd: Drag Instance');
135
Y.Assert.isTrue(dd.get('node').hasClass('yui3-dd-draggable'), 'dd: Drag Instance ClassName');
136
Y.Assert.isInstanceOf(Y.DD.Drop, dd.target, 'drag.target: Drop Instance');
137
Y.each(dd._yuievt.targets, function(v, k) {
138
Y.Assert.areSame(v, dd.target._yuievt.targets[k], 'bubbleTargets are not the same');
141
test_drag_drop_group_setup: function() {
143
dd = new Y.DD.Drag({ node: '#drag', groups: ['one', 'two'], target: true });
144
Y.Assert.areSame(dd.get('groups').length, dd.target.get('groups').length, 'Groups failed to pass from Drag to Drop');
146
test_drag_drop_group_pass_setup: function() {
148
dd = new Y.DD.Drag({ node: '#drag', target: { groups: ['one', 'two'] } });
149
Y.Assert.areSame(1, dd.get('groups').length, 'Groups failed to pass from Drag to Drop');
150
Y.Assert.areSame(2, dd.target.get('groups').length, 'Groups failed to pass from Drag to Drop');
152
test_drag_add_handle: function() {
153
Y.Assert.isNull(dd._handles, 'dd: Handles NOT Null');
154
dd.set('handles', ['h2']);
155
Y.Assert.isObject(dd._handles, 'dd: Handles not an object');
156
Y.Assert.isNotUndefined(dd._handles.h2, 'dd: Handles H2 not there');
157
dd.set('handles', false);
158
Y.Assert.isNull(dd._handles, 'dd: Handles NOT Null');
160
Y.Assert.isObject(dd._handles, 'dd: Handles not an object');
161
Y.Assert.isNotUndefined(dd._handles.h2, 'dd: Handles H2 not there');
162
dd.set('handles', false);
163
Y.Assert.isNull(dd._handles, 'dd: Handles NOT Null');
164
var wrap = Y.one('#wrap');
166
Y.Assert.isObject(dd._handles, 'dd: Handles not an object');
167
Y.Assert.isNotUndefined(dd._handles[wrap._yuid], 'dd: Handles ' + wrap._yuid + ' not there (Node Based Handle)');
168
dd.set('handles', false);
169
Y.Assert.isNull(dd._handles, 'dd: Handles NOT Null');
171
test_drag_setup_events: function() {
172
Y.each(dd_events, function(v) {
174
var handle = dd.on(v, _handleCount);
175
Y.Assert.isInstanceOf(Y.EventHandle, handle, 'drag:handle [' + v + ']: Handle Instance');
178
/* This test is iffey on Chrome/IE9 and sometimes on FF. Removing until I find a better solution.
179
test_drag_move: function() {
180
dd.on('drag:end', function() {
181
Y.Assert.areSame(moveCount, _count['drag:drag'], 'drag:drag should fire ' + moveCount + ' times');
182
//Y.Assert.areSame(1, _count['drag:drophit'], 'drag:drophit should fire 1 time');
183
Y.Assert.areSame(1, _count['drag:end'], 'drag:end should fire 1 time');
184
Y.Assert.areSame(1, _count['drag:start'], 'drag:start should fire 1 time');
185
//Y.Assert.areSame(1, _count['drag:enter'], 'drag:enter should fire 1 time');
186
Y.Assert.areSame(dropCount, _count['drag:over'], 'drag:over should fire ' + dropCount + ' times');
188
Y.Assert.areSame(dropCount, _count['drop:over'], 'drop:over should fire ' + dropCount + ' times');
189
Y.Assert.areSame(1, _count['drop:enter'], 'drop:enter should fire 1 time');
190
Y.Assert.areSame(1, _count['drop:hit'], 'drop:hit should fire 1 time');
192
_fakeMove(dd, moveCount);
195
test_drag_destroy: function() {
197
Y.Assert.isFalse(dd.get('node').hasClass('yui3-dd-draggable'), 'drag: Drag Instance NO ClassName');
198
Y.Assert.isTrue(dd.get('destroyed'), 'drag: Destroyed Attribute');
200
test_proxy: function() {
202
Y.one('#drag').setStyles({ top: '', left: '' });
203
proxy = new Y.DD.Drag({
205
}).plug(Y.Plugin.DDProxy, {
208
var p = Y.DD.DDM._proxy;
209
Y.Assert.isInstanceOf(Y.Node, p, 'Proxy: Node Instance');
210
Y.Assert.isInstanceOf(Y.Plugin.DDProxy, proxy.proxy, 'Proxy: Proxy Instance');
211
Y.Assert.isTrue(p.hasClass('yui3-dd-proxy'), 'proxy: Proxy Node Instance ClassName');
213
test_proxy_setup_events: function() {
214
Y.each(dd_events, function(v) {
215
var handle = proxy.on(v, _handleCount);
216
Y.Assert.isInstanceOf(Y.EventHandle, handle, 'proxy:handle [' + v + ']: Handle Instance');
219
/* This test is iffey on Chrome/IE9 and sometimes on FF. Removing until I find a better solution.
220
test_proxy_move: function() {
221
_fakeMove(proxy, moveCount);
223
Y.Assert.areSame(moveCount, _count['drag:drag'], 'drag:drag should fire ' + moveCount + ' times');
224
Y.Assert.areSame(1, _count['drag:drophit'], 'drag:drophit should fire 1 time');
225
Y.Assert.areSame(1, _count['drag:end'], 'drag:end should fire 1 time');
226
Y.Assert.areSame(1, _count['drag:start'], 'drag:start should fire 1 time');
227
Y.Assert.areSame(1, _count['drag:enter'], 'drag:enter should fire 1 time');
228
Y.Assert.areSame(dropCount, _count['drag:over'], 'drag:over should fire ' + dropCount + ' times');
230
Y.Assert.areSame(dropCount, _count['drop:over'], 'drop:over should fire ' + dropCount + ' times');
231
Y.Assert.areSame(1, _count['drop:enter'], 'drop:enter should fire 1 time');
232
Y.Assert.areSame(1, _count['drop:hit'], 'drop:hit should fire 1 time');
235
test_proxy_destroy: function() {
237
Y.Assert.isFalse(proxy.get('node').hasClass('yui3-dd-draggable'), 'proxy: Drag Instance NO ClassName');
238
Y.Assert.isTrue(proxy.get('destroyed'), 'Proxy: Destroyed Attribute');
240
test_drop_destroy: function() {
242
Y.Assert.isFalse(drop.get('node').hasClass('yui3-dd-drop'), 'Drop: Drop Instance NO ClassName');
243
Y.Assert.isTrue(drop.get('destroyed'), 'Drop: Destroyed Attribute');
246
test_constrain_node_setup: function() {
247
Y.one('#drag').setStyles({ top: '10px', left: '950px' });
250
}).plug(Y.Plugin.DDConstrained, {
251
constrain2node: '#wrap'
253
Y.Assert.isInstanceOf(Y.DD.Drag, dd, 'dd: Drag Instance');
254
Y.Assert.isInstanceOf(Y.Plugin.DDConstrained, dd.con, 'Constrained: DDConstrained Instance');
255
Y.Assert.isTrue(dd.get('node').hasClass('yui3-dd-draggable'), 'dd: Drag Instance ClassName');
257
test_constrain_node_move: function() {
258
var inRegion_before = dd.get('node').inRegion(Y.one('#wrap'));
262
var inRegion_after = dd.get('node').inRegion(Y.one('#wrap'));
263
Y.Assert.isFalse(inRegion_before, 'Drag Node is in the region of #wrap');
264
Y.Assert.isTrue(inRegion_after, 'Drag Node is NOT in the region of #wrap');
268
test_constrain_view_setup: function() {
269
Y.one('#drag').setStyles({ top: '-150px', left: '200px' });
272
}).plug(Y.Plugin.DDConstrained, {
275
Y.Assert.isInstanceOf(Y.DD.Drag, dd, 'dd: Drag Instance');
276
Y.Assert.isInstanceOf(Y.Plugin.DDConstrained, dd.con, 'Constrained: DDConstrained Instance');
277
Y.Assert.isTrue(dd.get('node').hasClass('yui3-dd-draggable'), 'dd: Drag Instance ClassName');
279
test_constrain_view_move: function() {
280
var inRegion_before = dd.get('node').inViewportRegion();
284
var inRegion_after = dd.get('node').inViewportRegion();
285
Y.Assert.isFalse(inRegion_before, 'Drag Node is in the viewport');
286
Y.Assert.isTrue(inRegion_after, 'Drag Node is NOT in the viewport');
289
test_window_scroll: function() {
290
Y.one('body').setStyle('height', '3000px');
291
Y.one('#drag').setStyles({ top: '', left: '' });
294
}).plug(Y.Plugin.DDWinScroll);
295
Y.Assert.isInstanceOf(Y.DD.Drag, dd, 'dd: Drag Instance');
296
Y.Assert.isInstanceOf(Y.Plugin.DDWinScroll, dd.winscroll, 'WinScroll: WinScroll Instance');
298
Y.one(window).set('scrollTop', 0);
299
Y.one(window).set('scrollLeft', 0);
302
winHeight = Y.one(window).get('winHeight'),
303
i = (winHeight - dd.get('node').get('offsetHeight') - 100),
305
if (i < (Y.one(window).get('winHeight') - 30)) {
306
_moveNode(dd, i, true);
308
self.wait.call(self, wait, 0);
310
self.wait.call(self, function() {
312
Y.Assert.isTrue((Y.one(window).get('scrollTop') > 0), 'window.scrollTop is not greater than 0');
314
Y.one('#drag').setStyles({ top: '', left: '' });
315
Y.one(window).set('scrollTop', 0);
316
Y.one(window).set('scrollLeft', 0);
317
Y.one('body').setStyle('height', '');
323
test_delegate: function() {
324
Y.one('#wrap').setStyle('display', 'none');
325
Y.one('#del').setStyle('display', 'block');
326
del = new Y.DD.Delegate({
331
Y.Assert.isInstanceOf(Y.DD.Delegate, del, 'del: Delegate Instance');
332
Y.Assert.isInstanceOf(Y.DD.Drag, del.dd, 'del.dd: Drag Instance');
334
test_delegate_setup_events: function() {
335
Y.each(dd_events, function(v) {
337
var handle = del.on(v, _handleCount);
338
Y.Assert.isInstanceOf(Y.EventHandle, handle, 'drag:handle [' + v + ']: Handle Instance');
341
test_delegate_move: function() {
343
del.on('drag:end', function() {
344
Y.Assert.areSame(moveCount, _count['drag:drag'], 'drag:drag should fire ' + moveCount + ' times');
345
Y.Assert.areSame(1, _count['drag:end'], 'drag:end should fire 1 time');
346
Y.Assert.areSame(1, _count['drag:start'], 'drag:start should fire 1 time');
347
del.get('currentNode').setStyles({
352
currentTarget: Y.one('#del ul li')
354
_fakeMove(del.dd, moveCount);
356
test_delegate_move2: function() {
359
currentTarget: Y.one('#del ul li:nth-child(4)')
361
_fakeMove(del.dd, moveCount);
363
test_delegate_disabled: function() {
367
del.on('drag:mouseDown', function() {
371
currentTarget: Y.one('#del ul li:nth-child(6)')
373
Y.Assert.isFalse(mDown, 'Delegate mouseDown fired on a disabled item');
377
var suite = new Y.Test.Suite("DD");
379
suite.add(new Y.Test.Case(template));
380
Y.Test.Runner.add(suite);