~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/tests/event-custom/tests/src/event-do.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var suite = new Y.Test.Suite("AOP");
2
 
 
3
 
suite.add(new Y.Test.Case({
4
 
    name: "Y.Do",
5
 
 
6
 
    _should: {
7
 
        fail: {
8
 
            //"test before/after with falsy context binds args": "ticket pending"
9
 
        },
10
 
        ignore: {
11
 
            // Trac ticket noted as value
12
 
            "test originalRetVal not overwritten by nested call": 2530030
13
 
        }
14
 
    },
15
 
 
16
 
    "test before/after with falsy context binds args": function () {
17
 
        //Y.Do.before(fn, obj, "method", null, "a", obj, null);
18
 
    },
19
 
 
20
 
    "test Y.AlterReturn": function() {
21
 
        var et = new Y.EventTarget(), count = 0;
22
 
 
23
 
        et.after(function() {
24
 
            count++;
25
 
            Y.Assert.isTrue(Y.Do.originalRetVal);
26
 
            Y.Assert.isTrue(Y.Do.currentRetVal);
27
 
            return new Y.Do.AlterReturn("altered return", "altered");
28
 
        }, et, 'fire');
29
 
 
30
 
        et.after(function() {
31
 
            count++;
32
 
            Y.Assert.isTrue(Y.Do.originalRetVal);
33
 
            Y.Assert.areEqual("altered", Y.Do.currentRetVal);
34
 
        }, et, 'fire');
35
 
 
36
 
 
37
 
        et.fire('yay');
38
 
        Y.Assert.areEqual(2, count);
39
 
 
40
 
    },
41
 
 
42
 
    "test originalRetVal not overwritten by nested call": function () {
43
 
        var obj = {
44
 
            a: function () {
45
 
                this.b();
46
 
                return 'A';
47
 
            },
48
 
 
49
 
            b: function () {
50
 
                return 'B';
51
 
            }
52
 
        };
53
 
 
54
 
        Y.Do.after(function () {
55
 
            return Y.Do.originalRetVal.toLowerCase();
56
 
        }, obj, 'a');
57
 
 
58
 
        Y.Do.after(function () {
59
 
            // It doesn't matter what happens here, but for example, we
60
 
            // don't interfere with the return value
61
 
        }, obj, 'b');
62
 
 
63
 
        Y.Assert.areSame('a', obj.a());
64
 
    }
65
 
}));
66
 
 
67
 
suite.add(new Y.Test.Case({
68
 
    name: "EventTarget on/before/after",
69
 
 
70
 
    "test target.on(fn, host, methodName)": function () {
71
 
        var target = new Y.EventTarget(),
72
 
            called = [],
73
 
            handle, before;
74
 
 
75
 
        before = Y.Do.before;
76
 
        Y.Do.before = function () {
77
 
            called.push("before");
78
 
            return before.apply(this, arguments);
79
 
        };
80
 
 
81
 
        function callback() {
82
 
            called.push("callback");
83
 
        }
84
 
 
85
 
        function method() {
86
 
            called.push("method");
87
 
        }
88
 
 
89
 
        target.method = method;
90
 
            
91
 
        // awkward that you have to pass the target, and even more so
92
 
        // because this means every EventTarget is effectively an alias
93
 
        // for Y.Do
94
 
        handle = target.on(callback, target, "method");
95
 
 
96
 
        Y.Assert.areNotSame(method, target.method);
97
 
        Y.Assert.isObject(handle);
98
 
        Y.Assert.isInstanceOf(Y.Do.Method, handle.evt);
99
 
 
100
 
        target.method();
101
 
 
102
 
        Y.ArrayAssert.itemsAreSame(["before", "callback", "method"], called);
103
 
 
104
 
        // restore the method for other tests
105
 
        Y.Do.before = before;
106
 
    },
107
 
 
108
 
    "test target.on(fn, host, methodName, context)": function () {
109
 
        var target = new Y.EventTarget(),
110
 
            called = [],
111
 
            handle, before;
112
 
 
113
 
        before = Y.Do.before;
114
 
        Y.Do.before = function () {
115
 
            called.push("before");
116
 
            return before.apply(this, arguments);
117
 
        };
118
 
 
119
 
        function callback() {
120
 
            called.push("callback");
121
 
        }
122
 
 
123
 
        function method() {
124
 
            called.push("method");
125
 
        }
126
 
 
127
 
        target.method = method;
128
 
            
129
 
        // awkward that you have to pass the target, and even more so
130
 
        // because this means every EventTarget is effectively an alias
131
 
        // for Y.Do
132
 
        handle = target.on(callback, target, "method");
133
 
 
134
 
        Y.Assert.areNotSame(method, target.method);
135
 
        Y.Assert.isObject(handle);
136
 
        Y.Assert.isInstanceOf(Y.Do.Method, handle.evt);
137
 
 
138
 
        target.method();
139
 
 
140
 
        Y.ArrayAssert.itemsAreSame(["before", "callback", "method"], called);
141
 
 
142
 
        // restore the method for other tests
143
 
        Y.Do.before = before;
144
 
    },
145
 
 
146
 
    "test target.on(fn, host, noSuchMethod)": function () {
147
 
    },
148
 
 
149
 
    "test target.on([fnA, fnB, fnC], host, noSuchMethod)": function () {
150
 
    },
151
 
 
152
 
    "test target.before() is an alias for target.on()": function () {
153
 
    }
154
 
}));
155
 
 
156
 
suite.add(new Y.Test.Case({
157
 
    name: "return Y.Do.Classes to affect fn flow"
158
 
 
159
 
    // Test each in before and after phases
160
 
    // AlterArgs
161
 
    // AlterReturn
162
 
    // Halt
163
 
    // Prevent
164
 
}));
165
 
 
166
 
Y.Test.Runner.add(suite);