~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/tests/datasource/tests/datasource-cache-tests.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
 
YUI.add('datasource-cache-tests', function(Y) {
2
 
 
3
 
var Assert = Y.Assert,
4
 
 
5
 
    suite = new Y.Test.Suite("Plugin.DataSourceCache Test Suite");
6
 
 
7
 
 
8
 
suite.add(new Y.Test.Case({
9
 
    name: "DataSource Caching Tests",
10
 
 
11
 
    setUp: function () {
12
 
        this.ds = new Y.DataSource.Local({ source: ["a","b","c","d"] });
13
 
    },
14
 
 
15
 
    testCacheDefaultMax: function() {
16
 
        this.ds.plug(Y.Plugin.DataSourceCache);
17
 
        Assert.isInstanceOf(Y.Cache, this.ds.cache, "Expected Cache instance.");
18
 
        Assert.areSame(0, this.ds.cache.get("max"), "Expected 0 max in Cache.");
19
 
    },
20
 
 
21
 
    testCacheInitMax: function() {
22
 
        this.ds.plug(Y.Plugin.DataSourceCache, { max: 3 });
23
 
        Assert.isInstanceOf(Y.Cache, this.ds.cache, "Expected Cache instance.");
24
 
        Assert.areSame(3, this.ds.cache.get("max"), "Expected 3 max in Cache.");
25
 
    },
26
 
 
27
 
    testCacheSetMax: function() {
28
 
        this.ds.plug(Y.Plugin.DataSourceCache);
29
 
        this.ds.cache.set("max", 5);
30
 
        Assert.isInstanceOf(Y.Cache, this.ds.cache, "Expected Cache instance.");
31
 
        Assert.areSame(5, this.ds.cache.get("max"), "Expected 5 max in Cache.");
32
 
    },
33
 
    
34
 
    testLocalCache: function() {
35
 
        var cached;
36
 
 
37
 
        this.ds.plug(Y.Plugin.DataSourceCache, { max: 3 });
38
 
 
39
 
        this.ds.sendRequest({ request: "a" });
40
 
 
41
 
        this.ds.sendRequest({
42
 
            request: "a",
43
 
            callback: {
44
 
                success: function (e) {
45
 
                    cached = e.cached;
46
 
                }
47
 
            }
48
 
        });
49
 
 
50
 
        Assert.isInstanceOf(Date, cached);
51
 
    },
52
 
 
53
 
    testLocalCacheUnplug: function() {
54
 
        var cached;
55
 
 
56
 
        this.ds.plug(Y.Plugin.DataSourceCache, { max: 3 });
57
 
 
58
 
        this.ds.sendRequest({ request: "a" });
59
 
 
60
 
        this.ds.sendRequest({
61
 
            request: "a",
62
 
            callback: {
63
 
                success: function (e) {
64
 
                    cached = e.cached;
65
 
                }
66
 
            }
67
 
        });
68
 
 
69
 
        Assert.isInstanceOf(Date, cached);
70
 
 
71
 
        this.ds.unplug(Y.Plugin.DataSourceCache);
72
 
 
73
 
        Assert.isUndefined(this.ds.cache);
74
 
 
75
 
        this.ds.sendRequest({
76
 
            request: "a",
77
 
            callback: {
78
 
                success: function (e) {
79
 
                    cached = e.cached;
80
 
                }
81
 
            }
82
 
        });
83
 
 
84
 
        Assert.isUndefined(cached);
85
 
    },
86
 
 
87
 
    "cache retrieval should not overwrite callback": function () {
88
 
        var response, callbackA, callbackB;
89
 
 
90
 
        this.ds.plug(Y.Plugin.DataSourceCache, { max: 3 });
91
 
 
92
 
        this.ds.sendRequest({
93
 
            request: "a", 
94
 
            callback: {
95
 
                success: function (e) {
96
 
                    response = e.response;
97
 
                    callbackA = true;
98
 
                    Assert.isUndefined(e.cached);
99
 
                }
100
 
            }
101
 
        });
102
 
 
103
 
        this.ds.sendRequest({
104
 
            request: "a",
105
 
            callback: {
106
 
                success: function (e) {
107
 
                    Assert.areSame(response, e.response);
108
 
                    Assert.isInstanceOf(Date, e.cached);
109
 
                    callbackB = true;
110
 
                }
111
 
            }
112
 
        });
113
 
 
114
 
        Assert.isTrue(callbackA);
115
 
        Assert.isTrue(callbackB);
116
 
    }
117
 
}));
118
 
 
119
 
Y.Test.Runner.add(suite);
120
 
 
121
 
 
122
 
}, '@VERSION@' ,{requires:['datasource-cache', 'test']});