Debian Codegraph @

dojox/data/tests/ClientFilter.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.ClientFilter");
2 dojo.require("dojox.data.ClientFilter");
3 dojo.require("dojox.data.JsonRestStore");
4
5
6 mockService = function(query){
7 var dfd = new dojo.Deferred();
8 setTimeout(function(){
9 dfd.callback([{firstName:"John",lastName:"Smith",__id:"mock/1"},
10 {firstName:"Jim",lastName:"Smith",__id:"mock/2"},
11 {firstName:"Jill",lastName:"Smith",__id:"mock/3"},
12 {firstName:"Jerry",lastName:"Smith",__id:"mock/4"}]);
13 },10);
14 return dfd;
15 };
16 mockService.servicePath = "mock/";
17 jsonStore = new dojox.data.JsonRestStore({service:mockService});
18
19 doh.register("dojox.data.tests.ClientFilter",
20 [
21 function updateWhileLoading(t) {
22 var d = new doh.Deferred();
23 jsonStore.fetch({query:{lastName:"Smith",firstName:"*"},sort:[{attribute:"firstName",descending:true}],
24 onComplete: function(items, request){
25 t.is(5, items.length); // make sure it was added
26 t.is(newJack,items[4]); // make sure it is in the right location
27 console.log("updateWhileLoading",items[4],newJack);
28 d.callback(true);
29 }
30 });
31 newJack = jsonStore.newItem({firstName:"Jack",lastName:"Smith"}); // this should fire while we are waiting for the fetch response
32 return d;
33 },
34 function makeChanges(t) {
35 // summary:
36 // Simple test of a basic fetch on JsonRestStore of a simple query.
37 var d = new doh.Deferred();
38 jsonStore.fetch({queryOptions:{cache:true},query:{lastName:"Smith",firstName:"*"},sort:[{attribute:"firstName",descending:true}],
39 onComplete: function(items, request){
40 t.is(5, items.length); // make sure it was added
41 t.is(newJack,items[4]); // make sure it is in the right location
42 console.log("items[4]",items[4]);
43 var newJoe = jsonStore.newItem({firstName:"Joe",lastName:"Smith"});
44 t.is(5, items.length); // make sure it was not added yet
45 jsonStore.updateResultSet(items, request);
46 t.is(6, items.length); // make sure it was added
47 t.is(newJoe,items[1]); // make sure it is in the right location
48 var jackJones = jsonStore.newItem({firstName:"Jack",lastName:"Jones"});
49 jsonStore.updateResultSet(items, request);
50 t.is(6, items.length); // make sure it is not added
51 jsonStore.setValue(newJoe,"firstName","Jesse");
52 jsonStore.updateResultSet(items, request);
53 t.is(6, items.length); // make sure it is the same
54 t.is(newJoe,items[3]); // make sure it is in the new right location
55 t.f(newJoe==items[1]); // make sure it is not in the old location
56 jsonStore.deleteItem(newJack);
57 jsonStore.updateResultSet(items, request);
58 t.is(5, items.length); // make sure it is has been removed
59 jsonStore.setValue(newJoe,"lastName","Baker");
60 jsonStore.updateResultSet(items, request);
61 t.is(4, items.length); // make sure it is has been removed
62 jsonStore.setValue(jackJones,"lastName","Smith");
63 jsonStore.updateResultSet(items, request);
64 t.is(5, items.length); // make sure it is has been added
65 }
66 });
67 console.log("sent first");
68 var finished;
69 jsonStore.fetch({query:{lastName:"Smith",firstName:"Jack"},sort:[{attribute:"firstName",descending:true}],
70 onComplete: function(items, request){
71 console.log("items first",items);
72 finished = true;
73 t.is(1, items.length); // make sure we get the correct number of items
74 d.callback(true);
75 }
76 });
77 console.log("sent seconds");
78 t.f(finished); // this should finish synchronously, because we should have it in the cache
79 return d; //Object
80 },
81 function cachedResults(t) {
82 var d = new doh.Deferred();
83 var finished;
84 jsonStore.fetch({query:{lastName:"Smith",firstName:"Jack"},sort:[{attribute:"firstName",descending:true}],
85 onComplete: function(items, request){
86 console.log("items",items);
87 finished = true;
88 t.is(1, items.length); // make sure we get the correct number of items
89 d.callback(true);
90 }
91 });
92 t.t(finished); // this should finish synchronously, because we should have it in the cache
93 return d;
94 },
95 function repeatedQueries(t) {
96 var d = new doh.Deferred();
97 var finished;
98 jsonStore.fetch({queryOptions:{cache:true},query:{},
99 onComplete: function(items, request){
100 console.log("items",items);
101 t.is(6, items.length); // make sure we get the correct number of items
102 jsonStore.newItem({firstName:"Jack",lastName:"Jones"});
103 jsonStore.fetch({query:{},
104 onComplete: function(items, request){
105 t.is(7, items.length); // make sure we get the correct number of items
106 }
107 });
108 jsonStore.serverVersion = jsonStore._updates.length;
109 jsonStore.newItem({firstName:"Jack",lastName:"Jones"});
110 jsonStore.fetch({query:{},
111 onComplete: function(items, request){
112 finished = true;
113 t.is(8, items.length); // make sure we get the correct number of items
114 d.callback(true);
115 }
116 });
117 }
118 });
119 return d;
120 },
121
122 function sorting(t) {
123 var d = new doh.Deferred();
124 var finished;
125 // test sorting. Descending order should be John,Jim,Jill,Jerry,Jack
126 jsonStore.fetch({query:{lastName:"Smith",firstName:"*"},sort:[{attribute:"firstName",descending:true}],
127 onComplete: function(items, request){
128 var last = jsonStore.getValue(items[0], "firstName");
129 console.log("last name: ",last, items[0]);
130
131 t.is("John", last); // make sure we get the correct number of items
132
133 jsonStore.fetch({query:{lastName:"Smith",firstName:"*"},sort:[{attribute:"firstName"}],
134 onComplete: function(items, request){
135 var first = jsonStore.getValue(items[0], "firstName");
136 console.log("first name",first, items[0]);
137 finished = true;
138 t.is("Jack", first); // make sure we get the correct number of items
139
140 d.callback(true);
141 }
142 });
143 }
144 });
145 t.t(finished); // this should finish synchronously, because we should have it in the cache
146 return d;
147 }
148
149 ]
150 );