1
YUI.add('datasource-cache-tests', function(Y) {
5
suite = new Y.Test.Suite("Plugin.DataSourceCache Test Suite");
8
suite.add(new Y.Test.Case({
9
name: "DataSource Caching Tests",
12
this.ds = new Y.DataSource.Local({ source: ["a","b","c","d"] });
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.");
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.");
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.");
34
testLocalCache: function() {
37
this.ds.plug(Y.Plugin.DataSourceCache, { max: 3 });
39
this.ds.sendRequest({ request: "a" });
44
success: function (e) {
50
Assert.isInstanceOf(Date, cached);
53
testLocalCacheUnplug: function() {
56
this.ds.plug(Y.Plugin.DataSourceCache, { max: 3 });
58
this.ds.sendRequest({ request: "a" });
63
success: function (e) {
69
Assert.isInstanceOf(Date, cached);
71
this.ds.unplug(Y.Plugin.DataSourceCache);
73
Assert.isUndefined(this.ds.cache);
78
success: function (e) {
84
Assert.isUndefined(cached);
87
"cache retrieval should not overwrite callback": function () {
88
var response, callbackA, callbackB;
90
this.ds.plug(Y.Plugin.DataSourceCache, { max: 3 });
95
success: function (e) {
96
response = e.response;
98
Assert.isUndefined(e.cached);
103
this.ds.sendRequest({
106
success: function (e) {
107
Assert.areSame(response, e.response);
108
Assert.isInstanceOf(Date, e.cached);
114
Assert.isTrue(callbackA);
115
Assert.isTrue(callbackB);
119
Y.Test.Runner.add(suite);
122
}, '@VERSION@' ,{requires:['datasource-cache', 'test']});