Debian Codegraph @

dojox/data/tests/stores/FlickrStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.FlickrStore");
2 dojo.require("dojox.data.FlickrStore");
3 dojo.require("dojo.data.api.Read");
4
5
6 dojox.data.tests.stores.FlickrStore.error = function(t, d, errData){
7 // summary:
8 // The error callback function to be used for all of the tests.
9 d.errback(errData);
10 };
11
12 doh.register("dojox.data.tests.stores.FlickrStore",
13 [
14 {
15 name: "ReadAPI: Fetch_One",
16 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
17 runTest: function(t) {
18 // summary:
19 // Simple test of a basic fetch on FlickrStore of a single item.
20 // description:
21 // Simple test of a basic fetch on FlickrStore of a single item.
22
23 var flickrStore = new dojox.data.FlickrStore();
24
25 var d = new doh.Deferred();
26 function onComplete(items, request){
27 t.is(1, items.length);
28 d.callback(true);
29 }
30 flickrStore.fetch({ query: {tags: "animals"},
31 count: 1,
32 onComplete: onComplete,
33 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, doh, d)
34 });
35 return d; //Object
36 }
37 },
38 {
39 name: "ReadAPI: Fetch_20_Streaming",
40 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
41 runTest: function(t) {
42 // summary:
43 // Simple test of a basic fetch on FlickrStore.
44 // description:
45 // Simple test of a basic fetch on FlickrStore.
46 var flickrStore = new dojox.data.FlickrStore();
47
48 var d = new doh.Deferred();
49 count = 0;
50
51 function onBegin(size, requestObj){
52 t.is(20, size);
53 }
54 function onItem(item, requestObj){
55 t.assertTrue(flickrStore.isItem(item));
56 count++;
57 }
58 function onComplete(items, request){
59 t.is(20, count);
60 t.is(null, items);
61 d.callback(true);
62 }
63
64 //Get everything...
65 flickrStore.fetch({ onBegin: onBegin,
66 count: 20,
67 onItem: onItem,
68 onComplete: onComplete,
69 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
70 });
71 return d; //Object
72 }
73 },
74 {
75 name: "ReadAPI: Fetch_Paging",
76 timeout: 30000, //30 seconds. Flickr can sometimes be slow.
77 runTest: function(t) {
78 // summary:
79 // Test of multiple fetches on a single result. Paging, if you will.
80 // description:
81 // Test of multiple fetches on a single result. Paging, if you will.
82
83 var flickrStore = new dojox.data.FlickrStore();
84
85 var d = new doh.Deferred();
86 function dumpFirstFetch(items, request){
87 t.is(5, items.length);
88 request.start = 3;
89 request.count = 1;
90 request.onComplete = dumpSecondFetch;
91 flickrStore.fetch(request);
92 }
93
94 function dumpSecondFetch(items, request){
95 t.is(1, items.length);
96 request.start = 0;
97 request.count = 5;
98 request.onComplete = dumpThirdFetch;
99 flickrStore.fetch(request);
100 }
101
102 function dumpThirdFetch(items, request){
103 t.is(5, items.length);
104 request.start = 2;
105 request.count = 20;
106 request.onComplete = dumpFourthFetch;
107 flickrStore.fetch(request);
108 }
109
110 function dumpFourthFetch(items, request){
111 t.is(18, items.length);
112 request.start = 9;
113 request.count = 100;
114 request.onComplete = dumpFifthFetch;
115 flickrStore.fetch(request);
116 }
117
118 function dumpFifthFetch(items, request){
119 t.is(11, items.length);
120 request.start = 2;
121 request.count = 20;
122 request.onComplete = dumpSixthFetch;
123 flickrStore.fetch(request);
124 }
125
126 function dumpSixthFetch(items, request){
127 t.is(18, items.length);
128 d.callback(true);
129 }
130
131 function completed(items, request){
132 t.is(7, items.length);
133 request.start = 1;
134 request.count = 5;
135 request.onComplete = dumpFirstFetch;
136 flickrStore.fetch(request);
137 }
138 flickrStore.fetch({count: 7, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
139 return d; //Object
140 }
141 },
142 {
143 name: "ReadAPI: getLabel",
144 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
145 runTest: function(t) {
146 // summary:
147 // Simple test of the getLabel function against a store set that has a label defined.
148 // description:
149 // Simple test of the getLabel function against a store set that has a label defined.
150
151 var flickrStore = new dojox.data.FlickrStore();
152
153 var d = new doh.Deferred();
154 function onComplete(items, request){
155 t.assertEqual(items.length, 1);
156 var label = flickrStore.getLabel(items[0]);
157 t.assertTrue(label !== null);
158 d.callback(true);
159 }
160 flickrStore.fetch({ query: {tags: "animals"},
161 count: 1,
162 onComplete: onComplete,
163 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
164 });
165 return d;
166 }
167 },
168 {
169 name: "ReadAPI: getLabelAttributes",
170 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
171 runTest: function(t) {
172 // summary:
173 // Simple test of the getLabelAttributes function against a store set that has a label defined.
174 // description:
175 // Simple test of the getLabelAttributes function against a store set that has a label defined.
176
177 var flickrStore = new dojox.data.FlickrStore();
178
179 var d = new doh.Deferred();
180 function onComplete(items, request){
181 t.assertEqual(items.length, 1);
182 var labelList = flickrStore.getLabelAttributes(items[0]);
183 t.assertTrue(dojo.isArray(labelList));
184 t.assertEqual("title", labelList[0]);
185 d.callback(true);
186 }
187 flickrStore.fetch({ query: {tags: "animals"},
188 count: 1,
189 onComplete: onComplete,
190 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
191 });
192 return d;
193 }
194 },
195 {
196 name: "ReadAPI: getValue",
197 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
198 runTest: function(t) {
199 // summary:
200 // Simple test of the getValue function of the store.
201 // description:
202 // Simple test of the getValue function of the store.
203 var flickrStore = new dojox.data.FlickrStore();
204
205 var d = new doh.Deferred();
206 function completedAll(items){
207 t.is(1, items.length);
208 t.assertTrue(flickrStore.getValue(items[0], "title") !== null);
209 t.assertTrue(flickrStore.getValue(items[0], "imageUrl") !== null);
210 t.assertTrue(flickrStore.getValue(items[0], "imageUrlSmall") !== null);
211 t.assertTrue(flickrStore.getValue(items[0], "imageUrlMedium") !== null);
212 d.callback(true);
213 }
214
215 //Get one item and look at it.
216 flickrStore.fetch({ count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
217 return d; //Object
218 }
219 },
220 {
221 name: "ReadAPI: getValues",
222 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
223 runTest: function(t) {
224 // summary:
225 // Simple test of the getValue function of the store.
226 // description:
227 // Simple test of the getValue function of the store.
228 var flickrStore = new dojox.data.FlickrStore();
229
230 var d = new doh.Deferred();
231 function completedAll(items){
232 t.is(1, items.length);
233 t.assertTrue(flickrStore.getValues(items[0], "title") instanceof Array);
234 t.assertTrue(flickrStore.getValues(items[0], "description") instanceof Array);
235 t.assertTrue(flickrStore.getValues(items[0], "imageUrl") instanceof Array);
236 t.assertTrue(flickrStore.getValues(items[0], "imageUrlSmall") instanceof Array);
237 t.assertTrue(flickrStore.getValues(items[0], "imageUrlMedium") instanceof Array);
238 d.callback(true);
239 }
240 //Get one item and look at it.
241 flickrStore.fetch({ count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
242 return d; //Object
243 }
244 },
245 {
246 name: "ReadAPI: isItem",
247 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
248 runTest: function(t) {
249 // summary:
250 // Simple test of the isItem function of the store
251 // description:
252 // Simple test of the isItem function of the store
253 var flickrStore = new dojox.data.FlickrStore();
254
255 var d = new doh.Deferred();
256 function completedAll(items){
257 t.is(5, items.length);
258 for(var i=0; i < items.length; i++){
259 t.assertTrue(flickrStore.isItem(items[i]));
260 }
261 d.callback(true);
262 }
263
264 //Get everything...
265 flickrStore.fetch({ count: 5, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
266 return d; //Object
267 }
268 },
269 {
270 name: "ReadAPI: hasAttribute",
271 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
272 runTest: function(t) {
273 // summary:
274 // Simple test of the hasAttribute function of the store
275 // description:
276 // Simple test of the hasAttribute function of the store
277
278 var flickrStore = new dojox.data.FlickrStore();
279
280 var d = new doh.Deferred();
281 function onComplete(items){
282 t.is(1, items.length);
283 t.assertTrue(items[0] !== null);
284 t.assertTrue(flickrStore.hasAttribute(items[0], "title"));
285 t.assertTrue(flickrStore.hasAttribute(items[0], "description"));
286 t.assertTrue(flickrStore.hasAttribute(items[0], "author"));
287 t.assertTrue(!flickrStore.hasAttribute(items[0], "Nothing"));
288 t.assertTrue(!flickrStore.hasAttribute(items[0], "Text"));
289
290 //Test that null attributes throw an exception
291 var passed = false;
292 try{
293 flickrStore.hasAttribute(items[0], null);
294 }catch (e){
295 passed = true;
296 }
297 t.assertTrue(passed);
298 d.callback(true);
299 }
300
301 //Get one item...
302 flickrStore.fetch({ query: {tags: "animals"},
303 count: 1,
304 onComplete: onComplete,
305 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
306 });
307 return d; //Object
308 }
309 },
310 {
311 name: "ReadAPI: containsValue",
312 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
313 runTest: function(t) {
314 // summary:
315 // Simple test of the containsValue function of the store
316 // description:
317 // Simple test of the containsValue function of the store
318
319 var flickrStore = new dojox.data.FlickrStore();
320
321 var d = new doh.Deferred();
322 function onComplete(items){
323 t.is(1, items.length);
324 d.callback(true);
325 }
326
327 //Get one item...
328 flickrStore.fetch({ query: {tags: "animals"},
329 count: 1,
330 onComplete: onComplete,
331 onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
332 });
333 return d; //Object
334 }
335 },
336 {
337 name: "ReadAPI: getAttributes",
338 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
339 runTest: function(t) {
340 // summary:
341 // Simple test of the getAttributes function of the store
342 // description:
343 // Simple test of the getAttributes function of the store
344
345 var flickrStore = new dojox.data.FlickrStore();
346
347 var d = new doh.Deferred();
348 function onComplete(items){
349 t.is(1, items.length);
350 t.assertTrue(flickrStore.isItem(items[0]));
351
352 var attributes = flickrStore.getAttributes(items[0]);
353 t.is(10, attributes.length);
354 d.callback(true);
355 }
356
357 //Get everything...
358 flickrStore.fetch({ count: 1, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
359 return d; //Object
360 }
361 },
362 function testReadAPI_getFeatures(t){
363 // summary:
364 // Simple test of the getFeatures function of the store
365 // description:
366 // Simple test of the getFeatures function of the store
367
368 var flickrStore = new dojox.data.FlickrStore();
369
370 var features = flickrStore.getFeatures();
371 var count = 0;
372 for(i in features){
373 t.assertTrue((i === "dojo.data.api.Read"));
374 count++;
375 }
376 t.assertTrue(count === 1);
377 },
378 function testReadAPI_functionConformance(t){
379 // summary:
380 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
381 // description:
382 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
383
384 var testStore = new dojox.data.FlickrStore();
385 var readApi = new dojo.data.api.Read();
386 var passed = true;
387
388 for(i in readApi){
389 if(i.toString().charAt(0) !== '_')
390 {
391 var member = readApi[i];
392 //Check that all the 'Read' defined functions exist on the test store.
393 if(typeof member === "function"){
394 var testStoreMember = testStore[i];
395 if(!(typeof testStoreMember === "function")){
396 passed = false;
397 break;
398 }
399 }
400 }
401 }
402 t.assertTrue(passed);
403 }
404 ]
405 );
406