~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/tests/dd/tests/dd.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var dd_events = [
2
 
    'drag:drag',
3
 
    'drag:drophit',
4
 
    'drag:end',
5
 
    'drag:start',
6
 
    'drag:enter',
7
 
    'drag:over',
8
 
    'drop:over',
9
 
    'drop:enter',
10
 
    'drop:hit'
11
 
],
12
 
moveCount = 728,
13
 
dropCount = 30;
14
 
 
15
 
 
16
 
 
17
 
YUI({
18
 
    base: '../../../build/',
19
 
    //filter: 'DEBUG',
20
 
    filter: 'RAW',
21
 
    logExclude: {
22
 
        'YUI': true,
23
 
        Event: true,
24
 
        Base: true,
25
 
        Attribute: true,
26
 
        augment: true,
27
 
        useConsole: true
28
 
    }
29
 
}).use('event-synthetic', 'event-gestures', 'dd', 'console', 'test', 'substitute', 'selector-css3', function(Y) {
30
 
            
31
 
            if (Y.UA.ie) {
32
 
                if (Y.UA.ie >= 9) {
33
 
                    dropCount = 30;
34
 
                } else if (Y.UA.ie > 7) {
35
 
                    dropCount = 32;
36
 
                } else if (Y.UA.ie < 7) {
37
 
                    dropCount = 26;
38
 
                } else if (Y.UA.ie < 8) {
39
 
                    dropCount = 28;
40
 
                }
41
 
            }
42
 
 
43
 
        var myConsole = new Y.Console({
44
 
            height: Y.one(window).get('winHeight') + 'px',
45
 
            width: '375px'
46
 
        }).render();    
47
 
            
48
 
        var _count = {},
49
 
        _resetCount = function() {
50
 
            Y.each(_count, function(v, k) {
51
 
                _count[k] = 0;
52
 
            });
53
 
        },
54
 
        _fakeStart = function(node) {
55
 
            _resetCount();
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;
61
 
            Y.DD.DDM._start();
62
 
            node.start();
63
 
        },
64
 
        _fakeEnd = function(node) {
65
 
            Y.DD.DDM._end();
66
 
            node.end();
67
 
            node._handleMouseUp();
68
 
            Y.DD.DDM._noShim = false;
69
 
        },
70
 
        _moveNode = function(node, num, flip) {
71
 
            if (flip) {
72
 
                Y.DD.DDM._move({ pageX: 110, pageY: num });
73
 
            } else {
74
 
                Y.DD.DDM._move({ pageX: num, pageY: 110 });
75
 
            }
76
 
        },
77
 
        _moveNodeAll = function(node, max, flip) {
78
 
            for (var i = 0; i < max; i++) {
79
 
                _moveNode(node, i, flip);
80
 
            }
81
 
        },
82
 
        _fakeMove = function(node, max, flip) {
83
 
            _fakeStart(node);
84
 
            _moveNodeAll(node, max, flip);
85
 
            _fakeEnd(node);
86
 
        },
87
 
        _data = {
88
 
            one: 1,
89
 
            two: 2,
90
 
            three: 3
91
 
        },
92
 
        _handleCount = function(e) {
93
 
            if (!_count[e.type]) {
94
 
                _count[e.type] = 0;
95
 
            }
96
 
            _count[e.type]++;
97
 
        },
98
 
        dd, drop, proxy, del,
99
 
 
100
 
    template = {
101
 
        name: 'DD Test',
102
 
        setUp : function() {
103
 
        },
104
 
        
105
 
        tearDown : function() {
106
 
        },
107
 
        test_shim: function() {
108
 
            var s = Y.DD.DDM._pg;
109
 
            Y.Assert.isNull(s, 'Shim: Node Instance');
110
 
        },
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');
115
 
        },
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');
120
 
            });
121
 
        },
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');
126
 
        },
127
 
        test_shim_after: function() {
128
 
            var s = Y.DD.DDM._pg;
129
 
            Y.Assert.isInstanceOf(Y.Node, s, 'Shim: Node Instance');
130
 
        },
131
 
        test_drag_drop_setup: function() {
132
 
            dd.destroy();
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');
139
 
            });
140
 
        },
141
 
        test_drag_drop_group_setup: function() {
142
 
            dd.destroy();
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');
145
 
        },
146
 
        test_drag_drop_group_pass_setup: function() {
147
 
            dd.destroy();
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');
151
 
        },
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');
159
 
            dd.addHandle('h2');
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');
165
 
            dd.addHandle(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');
170
 
        },
171
 
        test_drag_setup_events: function() {
172
 
            Y.each(dd_events, function(v) {
173
 
                _count[v] = 0;
174
 
                var handle = dd.on(v, _handleCount);
175
 
                Y.Assert.isInstanceOf(Y.EventHandle, handle, 'drag:handle [' + v + ']: Handle Instance');
176
 
            });
177
 
        },
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');
187
 
 
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');
191
 
            });
192
 
            _fakeMove(dd, moveCount);
193
 
        },
194
 
        */
195
 
        test_drag_destroy: function() {
196
 
            dd.destroy();
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');
199
 
        },
200
 
        test_proxy: function() {
201
 
            _resetCount();
202
 
            Y.one('#drag').setStyles({ top: '', left: '' });
203
 
            proxy = new Y.DD.Drag({
204
 
                node: '#drag'
205
 
            }).plug(Y.Plugin.DDProxy, {
206
 
                moveOnEnd: false
207
 
            });
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');
212
 
        },
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');
217
 
            });
218
 
        },
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);
222
 
            
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');
229
 
 
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');
233
 
        },
234
 
        */
235
 
        test_proxy_destroy: function() {
236
 
            proxy.destroy();
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');
239
 
        },
240
 
        test_drop_destroy: function() {
241
 
            drop.destroy();
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');
244
 
        },
245
 
        
246
 
        test_constrain_node_setup: function() {
247
 
            Y.one('#drag').setStyles({ top: '10px', left: '950px' });
248
 
            dd = new Y.DD.Drag({
249
 
                node: '#drag'
250
 
            }).plug(Y.Plugin.DDConstrained, {
251
 
                constrain2node: '#wrap'
252
 
            });
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');
256
 
        },
257
 
        test_constrain_node_move: function() {
258
 
            var inRegion_before = dd.get('node').inRegion(Y.one('#wrap'));
259
 
 
260
 
            _fakeMove(dd, 25);
261
 
 
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');
265
 
            dd.destroy();
266
 
        },
267
 
        
268
 
        test_constrain_view_setup: function() {
269
 
            Y.one('#drag').setStyles({ top: '-150px', left: '200px' });
270
 
            dd = new Y.DD.Drag({
271
 
                node: '#drag'
272
 
            }).plug(Y.Plugin.DDConstrained, {
273
 
                constrain2view: true
274
 
            });
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');
278
 
        },
279
 
        test_constrain_view_move: function() {
280
 
            var inRegion_before = dd.get('node').inViewportRegion();
281
 
 
282
 
            _fakeMove(dd, 250);
283
 
 
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');
287
 
            dd.destroy();
288
 
        },
289
 
        test_window_scroll: function() {
290
 
            Y.one('body').setStyle('height', '3000px');
291
 
            Y.one('#drag').setStyles({ top: '', left: '' });
292
 
            dd = new Y.DD.Drag({
293
 
                node: '#drag'
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');
297
 
 
298
 
            Y.one(window).set('scrollTop', 0);
299
 
            Y.one(window).set('scrollLeft', 0);
300
 
            _fakeStart(dd);
301
 
            var self = this,
302
 
            winHeight = Y.one(window).get('winHeight'),
303
 
            i = (winHeight - dd.get('node').get('offsetHeight') - 100),
304
 
            wait = function() {
305
 
                if (i < (Y.one(window).get('winHeight') - 30)) {
306
 
                    _moveNode(dd, i, true);
307
 
                    i++;
308
 
                    self.wait.call(self, wait, 0);
309
 
                } else {
310
 
                    self.wait.call(self, function() {
311
 
                        _fakeEnd(dd);
312
 
                        Y.Assert.isTrue((Y.one(window).get('scrollTop') > 0), 'window.scrollTop is not greater than 0');
313
 
                        dd.destroy();
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', '');
318
 
                    }, 1500);
319
 
                }
320
 
            };
321
 
            this.wait(wait, 0);
322
 
        },
323
 
        test_delegate: function() {
324
 
            Y.one('#wrap').setStyle('display', 'none');
325
 
            Y.one('#del').setStyle('display', 'block');
326
 
            del = new Y.DD.Delegate({
327
 
                cont: '#del',
328
 
                nodes: 'li',
329
 
                invalid: '.disabled'
330
 
            });
331
 
            Y.Assert.isInstanceOf(Y.DD.Delegate, del, 'del: Delegate Instance');
332
 
            Y.Assert.isInstanceOf(Y.DD.Drag, del.dd, 'del.dd: Drag Instance');
333
 
        },
334
 
        test_delegate_setup_events: function() {
335
 
            Y.each(dd_events, function(v) {
336
 
                _count[v] = 0;
337
 
                var handle = del.on(v, _handleCount);
338
 
                Y.Assert.isInstanceOf(Y.EventHandle, handle, 'drag:handle [' + v + ']: Handle Instance');
339
 
            });
340
 
        },
341
 
        test_delegate_move: function() {
342
 
            _resetCount();
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({
348
 
                    top: 0, left: 0
349
 
                });
350
 
            });
351
 
            del._delMouseDown({
352
 
                currentTarget: Y.one('#del ul li')
353
 
            });
354
 
            _fakeMove(del.dd, moveCount);
355
 
        },
356
 
        test_delegate_move2: function() {
357
 
            _resetCount();
358
 
            del._delMouseDown({
359
 
                currentTarget: Y.one('#del ul li:nth-child(4)')
360
 
            });
361
 
            _fakeMove(del.dd, moveCount);
362
 
        },
363
 
        test_delegate_disabled: function() {
364
 
            del.detachAll();
365
 
            _resetCount();
366
 
            var mDown = false;
367
 
            del.on('drag:mouseDown', function() {
368
 
                mDown = true;
369
 
            });
370
 
            del._delMouseDown({
371
 
                currentTarget: Y.one('#del ul li:nth-child(6)')
372
 
            });
373
 
            Y.Assert.isFalse(mDown, 'Delegate mouseDown fired on a disabled item');
374
 
        }
375
 
    };
376
 
    
377
 
    var suite = new Y.Test.Suite("DD");
378
 
    
379
 
    suite.add(new Y.Test.Case(template));
380
 
    Y.Test.Runner.add(suite);
381
 
    Y.Test.Runner.run();
382
 
});
383