(hoofbeats) Add support for pluggable resolvers.
[profile/ivi/cowhide.git] / examples / hoofbeats / tests / unit / library.js
1 /* vi: set et sw=4 ts=4 si: */
2 $(function() {
3     module("hoofbeats-library", {
4         setup: function() {
5             window._tizen = window.tizen;
6         },
7         teardown: function() {
8             window.tizen = window._tizen;
9         }
10     });
11
12     test("scan when browser doesn't support Tizen web api",
13     function() {
14         var lib = new HoofbeatsLibrary();
15         window.tizen = undefined;
16         raises(function() {
17             lib.scan({resolveBackend: DummyResolver});
18         }, Error, "scan throws Error");
19     });
20
21     test("successful scan", function() {
22         var lib = new HoofbeatsLibrary();
23         stop();
24         lib.scan({resolveBackend: DummyResolver}).then(function() {
25             ok(lib.getSize() > 0, "there are items in the library");
26             start();
27         });
28     });
29
30     test("successful scan without resolving", function() {
31         var lib = new HoofbeatsLibrary();
32         stop();
33         lib.scan({resolveBackend: undefined}).then(function() {
34             ok(lib.getResolve() == false, "lib.getResolve() is false");
35             start();
36         });
37     });
38
39     test("scan with count", function() {
40         var lib = new HoofbeatsLibrary();
41         stop();
42         lib.scan({count: 1, resolveBackend: DummyResolver}).then(function() {
43             ok(lib.getSize() == 1, "there is one item in the library");
44             start();
45         });
46     });
47
48     test("get one item", function() {
49         var lib = new HoofbeatsLibrary(),
50             item_id = 'e7e7023b-54b3-41d5-b4a1-aa24498e0572';
51
52         stop();
53         lib.scan({count: 1, resolveBackend: DummyResolver}).then(function() {
54             var item = lib.item(item_id);
55             ok(item !== undefined, "item was found");
56             ok(item.id == item_id, "correct item was found");
57             start();
58         });
59     });
60 });