~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/tests/event-gestures/tests/flick-tests.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('flick-tests', function(Y) {
2
 
 
3
 
    var eventData = {
4
 
            flick: Y.Node.DOM_EVENTS.flick.eventDef,
5
 
        },
6
 
        Assert = Y.Assert,
7
 
        noop = function() { },
8
 
        CE = {
9
 
            fire: noop
10
 
        },
11
 
        node = Y.one('#tester'),
12
 
        event = {
13
 
            target: node,
14
 
            currentTarget: node,
15
 
            touches: [
16
 
                {
17
 
                    pageX: 100,
18
 
                    pageY: 100,
19
 
                    clientX: 100,
20
 
                    clientY: 100,
21
 
                    screenX: 100,
22
 
                    screenY: 100
23
 
                }
24
 
            ]
25
 
        },
26
 
        suite = new Y.Test.Suite('Flick Event Suite');
27
 
 
28
 
    suite.add(new Y.Test.Case({
29
 
        name: 'flick',
30
 
        setUp: function() {
31
 
            this.handles = [];
32
 
            this.handles.push(node.on('flick', noop));
33
 
            this.handles.push(node.delegate('flick', noop));
34
 
        },
35
 
        tearDown: function() {
36
 
            Y.Array.each(this.handles, function(h) {
37
 
                h.detach();
38
 
            });
39
 
        },
40
 
        'test: _onStart()': function() {
41
 
            eventData.flick._onStart(event,node, {
42
 
                _extra: {
43
 
                    minTime: 5,
44
 
                    minDistance: 5
45
 
                }
46
 
            }, {
47
 
                fire: function(e) {
48
 
                    Assert.areSame(event.target, e.target, 'Target not set properly');
49
 
                    Assert.areSame('flick', e.type, 'Event type is wrong');
50
 
                    Assert.areEqual(1, e.button, 'e.button is not set');
51
 
                }
52
 
            });
53
 
        },
54
 
        'test: _onMove()': function() {
55
 
            var sub = { '_fs': { flick: { } } };
56
 
            eventData.flick._onMove(event,node, sub);
57
 
            Assert.isTrue((sub['_fs'].flick.time > 0), 'Flick time was not set on move');
58
 
        },
59
 
        'test: _onEnd()': function() {
60
 
            var en = event;
61
 
            en.changedTouches = en.touches;
62
 
            en.touches = [];
63
 
 
64
 
            eventData.flick._onEnd(en,node, {
65
 
                _fs: {
66
 
                    flick: {
67
 
                        time: ((new Date().getTime()) - 3000)
68
 
                    },
69
 
                    pageX: 5,
70
 
                    pageY: 5,
71
 
                    detach: noop
72
 
                },
73
 
                _fmh: {
74
 
                    detach: noop
75
 
                },
76
 
                _extra: {
77
 
                    axis: 'x',
78
 
                    minTime: 1,
79
 
                    minDistance: 0,
80
 
                    minVelocity: 0,
81
 
                    preventDefault: noop
82
 
                }
83
 
            }, {
84
 
                fire: function(e) {
85
 
                    Assert.areSame('flick', e.type, 'Event type is incorrect');
86
 
                    Assert.isObject(e.flick, 'e.click is not an Object');
87
 
                    Assert.areSame('x', e.flick.axis, 'flick axis is not X');
88
 
                    Assert.areSame(95, e.flick.distance, 'Did not flick the proper distance');
89
 
                    Assert.isTrue((e.flick.time >- 3000), 'flick time is not set properly');
90
 
                    Assert.isTrue((e.flick.velocity >= 0.020), 'Failed to move in the proper velocity');
91
 
                    Assert.areSame(0, e.touches.length, 'e.touches.length should be 0');
92
 
                    Assert.areSame(1, e.changedTouches.length), 'e.changedTouches.length should be 1';
93
 
                    Assert.areSame(node, e.target, 'Event target is not set properly');
94
 
                    Assert.areSame(node, e.currentTarget, 'Event currentTarget is not set properly');
95
 
                }
96
 
            });
97
 
        }
98
 
    }));
99
 
 
100
 
 
101
 
 
102
 
    Y.Test.Runner.add(suite);
103
 
 
104
 
});