Debian Codegraph @

dojox/data/tests/stores/GoogleSearchStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.GoogleSearchStore");
2 dojo.require("dojox.data.GoogleSearchStore");
3 dojo.require("dojo.data.api.Read");
4
5 dojox.data.tests.stores.GoogleSearchStore.getStore = function(){
6 return new dojox.data.GoogleSearchStore();
7 };
8
9 dojox.data.tests.stores.GoogleSearchStore.error = function(t, d, errData){
10 // summary:
11 // The error callback function to be used for all of the tests.
12
13 //console.trace();
14 d.errback(errData);
15 };
16
17 doh.register("dojox.data.tests.stores.GoogleSearchStore",
18 [
19 {
20 name: "ReadAPI: Fetch_One",
21 timeout: 30000, // 30 seconds
22 runTest: function(t) {
23 // summary:
24 // Simple test of a basic fetch on GoogleSearchStore of a single item.
25 // description:
26 // Simple test of a basic fetch on GoogleSearchStore of a single item.
27
28 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
29
30 var d = new doh.Deferred();
31 function onComplete(items, request){
32 t.is(1, items.length);
33 d.callback(true);
34 }
35 googleStore.fetch({
36 query: {
37 text: "kinsale"
38 },
39 count: 1,
40 onComplete: onComplete,
41 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, doh, d)
42 });
43 return d; //Object
44 }
45 },
46 {
47 name: "ReadAPI: test_Invalid_Query",
48 timeout: 30000, // 30 seconds
49 runTest: function(t) {
50 // summary:
51 // Simple test of a basic fetch on GoogleSearchStore of a single item.
52 // description:
53 // Simple test of a basic fetch on GoogleSearchStore of a single item.
54
55 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
56
57 var d = new doh.Deferred();
58 function doNotCall1(items, request){
59 t.assertTrue(false);
60 d.callback(true);
61 }
62 function doNotCall2(items, request){
63 t.assertTrue(false);
64 d.callback(true);
65 }
66 function doNotCall3(items, request){
67 t.assertTrue(false);
68 d.callback(true);
69 }
70 try {
71 googleStore.fetch({
72 query: {
73
74 },
75 count: 1,
76 onItem:doNotCall2,
77 onBegin: doNotCall1,
78 onComplete: doNotCall3,
79 onError: function(){
80 //Swallow this as it is expected
81 d.callback(true);
82 }
83 });
84 } catch (e) {
85 console.log("exception thrown", e);
86 t.assertTrue(false);
87 d.callback(true);
88 }
89 return d; //Object
90 }
91 },
92 {
93 name: "ReadAPI: Fetch_25_Streaming",
94 timeout: 30000, //20 seconds.
95 runTest: function(t) {
96 // summary:
97 // Simple test of a basic fetch on GoogleSearchStore.
98 // description:
99 // Simple test of a basic fetch on GoogleSearchStore.
100 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
101
102 var d = new doh.Deferred();
103 var count = 0;
104
105 function onItem(item, requestObj){
106 t.assertTrue(googleStore.isItem(item));
107 count++;
108 }
109 function onComplete(items, request){
110 t.is(25, count);
111
112 t.is(null, items);
113 d.callback(true);
114 }
115 //Get everything...
116 googleStore.fetch({
117 query: {
118 text: "kinsale"
119 },
120 onBegin: null,
121 count: 25,
122 onItem: onItem,
123 onComplete: onComplete,
124 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
125 });
126 return d; //Object
127 }
128 },
129 {
130 name: "ReadAPI: Fetch_Paging",
131 timeout: 30000, // 30 seconds.
132 runTest: function(t) {
133 // summary:
134 // Test of multiple fetches on a single result. Paging, if you will.
135 // description:
136 // Test of multiple fetches on a single result. Paging, if you will.
137
138 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
139 var d = new doh.Deferred();
140
141 function dumpSixthFetch(items, request){
142 t.is(16, items.length);
143 d.callback(true);
144 }
145
146 function dumpFifthFetch(items, request){
147 t.is(11, items.length);
148 request.start = 4;
149 request.count = 16;
150 request.onComplete = dumpSixthFetch;
151 googleStore.fetch(request);
152 }
153
154 function dumpFourthFetch(items, request){
155 t.is(18, items.length);
156 request.start = 5;
157 request.count = 11;
158 request.onComplete = dumpFifthFetch;
159 googleStore.fetch(request);
160 }
161
162 function dumpThirdFetch(items, request){
163 t.is(5, items.length);
164 request.start = 2;
165 request.count = 18;
166 request.onComplete = dumpFourthFetch;
167 googleStore.fetch(request);
168 }
169
170 function dumpSecondFetch(items, request){
171 t.is(1, items.length);
172 request.start = 0;
173 request.count = 5;
174 request.onComplete = dumpThirdFetch;
175 googleStore.fetch(request);
176 }
177
178 function dumpFirstFetch(items, request){
179 t.is(5, items.length);
180 request.start = 3;
181 request.count = 1;
182 request.onComplete = dumpSecondFetch;
183 googleStore.fetch(request);
184 }
185
186 function completed(items, request){
187 t.is(7, items.length);
188 d.callback(true);
189 }
190 googleStore.fetch({
191 query: {
192 text: "kinsale"
193 },
194 count: 7,
195 onComplete: completed,
196 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
197 });
198 return d; //Object
199 }
200 },
201 {
202 name: "ReadAPI: getLabel",
203 timeout: 30000, // 30 seconds.
204 runTest: function(t) {
205 // summary:
206 // Simple test of the getLabel function against a store set that has a label defined.
207 // description:
208 // Simple test of the getLabel function against a store set that has a label defined.
209
210 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
211
212 var d = new doh.Deferred();
213 function onComplete(items, request){
214 t.assertEqual(items.length, 1);
215 var label = googleStore.getLabel(items[0]);
216 t.assertTrue(label !== null);
217 d.callback(true);
218 }
219 googleStore.fetch({
220 query: {
221 text: "kinsale"
222 },
223 count: 1,
224 onComplete: onComplete,
225 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
226 });
227 return d;
228 }
229 },
230 {
231 name: "ReadAPI: getLabelAttributes",
232 timeout: 30000, // 30 seconds
233 runTest: function(t) {
234 // summary:
235 // Simple test of the getLabelAttributes function against a store set that has a label defined.
236 // description:
237 // Simple test of the getLabelAttributes function against a store set that has a label defined.
238
239 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
240
241 var d = new doh.Deferred();
242 function onComplete(items, request){
243 t.assertEqual(items.length, 1);
244 var labelList = googleStore.getLabelAttributes(items[0]);
245 t.assertTrue(dojo.isArray(labelList));
246 t.assertEqual("titleNoFormatting", labelList[0]);
247 d.callback(true);
248 }
249 googleStore.fetch({
250 query: {
251 text: "kinsale"
252 },
253 count: 1,
254 onComplete: onComplete,
255 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
256 });
257 return d;
258 }
259 },
260 {
261 name: "ReadAPI: getValue",
262 timeout: 30000, // 30 seconds
263 runTest: function(t) {
264 // summary:
265 // Simple test of the getValue function of the store.
266 // description:
267 // Simple test of the getValue function of the store.
268 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
269
270 var d = new doh.Deferred();
271 function completedAll(items){
272 t.is(1, items.length);
273 t.assertTrue(googleStore.getValue(items[0], "unescapedUrl") !== null);
274 t.assertTrue(googleStore.getValue(items[0], "url") !== null);
275 t.assertTrue(googleStore.getValue(items[0], "visibleUrl") !== null);
276 t.assertTrue(googleStore.getValue(items[0], "cacheUrl") !== null);
277 t.assertTrue(googleStore.getValue(items[0], "title") !== null);
278 t.assertTrue(googleStore.getValue(items[0], "titleNoFormatting") !== null);
279 t.assertTrue(googleStore.getValue(items[0], "content") !== null);
280 d.callback(true);
281 }
282
283 //Get one item and look at it.
284 googleStore.fetch({
285 query: {
286 text: "kinsale"
287 },
288 count: 1,
289 onComplete: completedAll,
290 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)});
291 return d; //Object
292 }
293 },
294 {
295 name: "ReadAPI: getValue_Failure",
296 timeout: 30000, // 30 seconds
297 runTest: function(t) {
298 // summary:
299 // Simple test of the getValue function of the store.
300 // description:
301 // Simple test of the getValue function of the store.
302 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
303 var passed = false;
304 try{
305 var value = googleStore.getValue("NotAnItem", "foo");
306 }catch(e){
307 passed = true;
308 }
309 t.assertTrue(passed);
310 }
311 },
312 {
313 name: "ReadAPI: getValues",
314 timeout: 30000, // 30 seconds
315 runTest: function(t) {
316 // summary:
317 // Simple test of the getValue function of the store.
318 // description:
319 // Simple test of the getValue function of the store.
320 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
321
322 var d = new doh.Deferred();
323 function completedAll(items){
324 t.is(1, items.length);
325 var summary = googleStore.getValues(items[0], "unescapedUrl");
326 t.assertTrue(dojo.isArray(summary));
327
328 var url = googleStore.getValues(items[0], "url");
329 t.assertTrue(dojo.isArray(url));
330
331 var published = googleStore.getValues(items[0], "visibleUrl");
332 t.assertTrue(dojo.isArray(published));
333
334 var updated = googleStore.getValues(items[0], "cacheUrl");
335 t.assertTrue(dojo.isArray(updated));
336
337 var title = googleStore.getValues(items[0], "title");
338 t.assertTrue(dojo.isArray(title));
339
340 var titleNoFormatting = googleStore.getValues(items[0], "titleNoFormatting");
341 t.assertTrue(dojo.isArray(titleNoFormatting));
342
343 var content = googleStore.getValues(items[0], "content");
344 t.assertTrue(dojo.isArray(content));
345
346 d.callback(true);
347 }
348 //Get one item and look at it.
349 googleStore.fetch({
350 query: {
351 text: "kinsale"
352 },
353 count: 1,
354 onComplete: completedAll,
355 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error,
356 t,
357 d)
358 });
359 return d; //Object
360 }
361 },
362 {
363 name: "ReadAPI: getValues_Failure",
364 timeout: 30000, // 30 seconds
365 runTest: function(t) {
366 // summary:
367 // Simple test of the getValue function of the store.
368 // description:
369 // Simple test of the getValue function of the store.
370 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
371 var passed = false;
372 try{
373 var value = googleStore.getValues("NotAnItem", "foo");
374 }catch(e){
375 passed = true;
376 }
377 t.assertTrue(passed);
378 }
379 },
380 {
381 name: "ReadAPI: isItem",
382 timeout: 30000, // 30 seconds
383 runTest: function(t) {
384 // summary:
385 // Simple test of the isItem function of the store
386 // description:
387 // Simple test of the isItem function of the store
388 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
389
390 var d = new doh.Deferred();
391 function completedAll(items){
392 t.is(5, items.length);
393 for(var i=0; i < items.length; i++){
394 t.assertTrue(googleStore.isItem(items[i]));
395 }
396 d.callback(true);
397 }
398
399 //Get everything...
400 googleStore.fetch({
401 query: {
402 text: "kinsale"
403 },
404 count: 5,
405 onComplete: completedAll,
406 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
407 });
408 return d; //Object
409 }
410 },
411 {
412 name: "ReadAPI: hasAttribute",
413 timeout: 30000, // 30 seconds
414 runTest: function(t) {
415 // summary:
416 // Simple test of the hasAttribute function of the store
417 // description:
418 // Simple test of the hasAttribute function of the store
419
420 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
421
422 var d = new doh.Deferred();
423 function onComplete(items){
424 t.is(1, items.length);
425 t.assertTrue(items[0] !== null);
426 var count = 0;
427 t.assertTrue(googleStore.hasAttribute(items[0], "unescapedUrl"));
428 t.assertTrue(googleStore.hasAttribute(items[0], "url"));
429 t.assertTrue(googleStore.hasAttribute(items[0], "visibleUrl"));
430 t.assertTrue(googleStore.hasAttribute(items[0], "cacheUrl"));
431 t.assertTrue(googleStore.hasAttribute(items[0], "title"));
432 t.assertTrue(googleStore.hasAttribute(items[0], "titleNoFormatting"));
433 t.assertTrue(googleStore.hasAttribute(items[0], "content"));
434 t.assertTrue(!googleStore.hasAttribute(items[0], "I dont exist"));
435
436 //Test that null attributes throw an exception
437 try{
438 googleStore.hasAttribute(items[0], null);
439 t.assertTrue(false);
440 }catch (e){
441
442 }
443 d.callback(true);
444 }
445
446 //Get one item...
447 googleStore.fetch({
448 query: {
449 text: "kinsale"
450 },
451 count: 1,
452 onComplete: onComplete,
453 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
454 });
455 return d; //Object
456 }
457 },
458 {
459 name: "ReadAPI: containsValue",
460 timeout: 30000, // 30 seconds
461 runTest: function(t) {
462 // summary:
463 // Simple test of the containsValue function of the store
464 // description:
465 // Simple test of the containsValue function of the store
466
467 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
468
469 var d = new doh.Deferred();
470 function onComplete(items){
471 t.is(1, items.length);
472
473 // This is the only way to test the results, as we cannot depend on the search
474 // result with a hard coded value.
475 t.assertTrue(googleStore.containsValue(items[0], "url", items[0].url));
476
477 d.callback(true);
478 }
479
480 //Get one item...
481 googleStore.fetch({
482 query: {
483 text: "kinsale"
484 },
485 count: 1,
486 onComplete: onComplete,
487 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
488 });
489 return d; //Object
490 }
491 },
492 {
493 name: "ReadAPI: getAttributes",
494 timeout: 30000, // 30 seconds
495 runTest: function(t) {
496 // summary:
497 // Simple test of the getAttributes function of the store
498 // description:
499 // Simple test of the getAttributes function of the store
500
501 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
502
503 var d = new doh.Deferred();
504 function onComplete(items){
505 t.is(1, items.length);
506 t.assertTrue(googleStore.isItem(items[0]));
507
508 var attributes = googleStore.getAttributes(items[0]);
509
510 t.is(8, attributes.length);
511 d.callback(true);
512 }
513
514 //Get everything...
515 googleStore.fetch({
516 query: {
517 text: "kinsale"
518 },
519 count: 1,
520 onComplete: onComplete,
521 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
522 });
523 return d; //Object
524 }
525 },
526 {
527 name: "GoogleSearchStore: DOM Cleanup",
528 timeout: 30000, // 30 seconds
529 runTest: function(t) {
530 // summary:
531 // Simple test of the getAttributes function of the store
532 // description:
533 // Simple test of the getAttributes function of the store
534
535 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
536
537 var d = new doh.Deferred();
538
539 var preScriptCount = dojo.query("head script").length;
540
541 function onComplete(items){
542 var postScriptCount = dojo.query("head script").length;
543 t.is(preScriptCount, postScriptCount);
544 d.callback(true);
545 }
546
547 //Get everything...
548 googleStore.fetch({
549 query: {
550 text: "kinsale"
551 },
552 count: 50,
553 onComplete: onComplete,
554 onError: dojo.partial(dojox.data.tests.stores.GoogleSearchStore.error, t, d)
555 });
556 return d; //Object
557 }
558 },
559 function testReadAPI_getFeatures(t){
560 // summary:
561 // Simple test of the getFeatures function of the store
562 // description:
563 // Simple test of the getFeatures function of the store
564
565 var googleStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
566
567 var features = googleStore.getFeatures();
568 var count = 0;
569 var i;
570 for(i in features){
571 t.assertTrue((i === "dojo.data.api.Read"));
572 count++;
573 }
574 t.assertTrue(count === 1);
575 },
576 function testReadAPI_functionConformance(t){
577 // summary:
578 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
579 // description:
580 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
581
582 var testStore = dojox.data.tests.stores.GoogleSearchStore.getStore();
583 var readApi = new dojo.data.api.Read();
584 var passed = true;
585 var i;
586 for(i in readApi){
587 if(i.toString().charAt(0) !== '_')
588 {
589 var member = readApi[i];
590 //Check that all the 'Read' defined functions exist on the test store.
591 if(typeof member === "function"){
592 var testStoreMember = testStore[i];
593 if(!(typeof testStoreMember === "function")){
594 console.log("Problem with function: [" + i + "]. Got value: " + testStoreMember);
595 passed = false;
596 break;
597 }
598 }
599 }
600 }
601 t.assertTrue(passed);
602 }
603 ]
604 );