Add Intel copyright header.
[profile/ivi/cowhide.git] / examples / hoofbeats / tests / unit / library.js
1 /* vi: set et sw=4 ts=4 si: */
2 /*
3  * Copyright (c) 2012, Intel Corporation.
4  *
5  * This program is licensed under the terms and conditions of the
6  * Apache License, version 2.0.  The full text of the Apache License is at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  */
10
11 $(function() {
12     module("hoofbeats-library", {
13         setup: function() {
14             window._tizen = window.tizen;
15         },
16         teardown: function() {
17             window.tizen = window._tizen;
18         }
19     });
20
21     test("scan when browser doesn't support Tizen web api",
22     function() {
23         var lib = new HoofbeatsLibrary();
24         window.tizen = undefined;
25         raises(function() {
26             lib.scan({resolveBackend: DummyResolver});
27         }, Error, "scan throws Error");
28     });
29
30     test("successful scan", function() {
31         var lib = new HoofbeatsLibrary();
32         stop();
33         lib.scan({resolveBackend: DummyResolver}).then(function() {
34             ok(lib.getSize() > 0, "there are items in the library");
35             start();
36         });
37     });
38
39     test("successful scan without resolving", function() {
40         var lib = new HoofbeatsLibrary();
41         stop();
42         lib.scan({resolveBackend: undefined}).then(function() {
43             ok(lib.getResolve() == false, "lib.getResolve() is false");
44             start();
45         });
46     });
47
48     test("scan with count", function() {
49         var lib = new HoofbeatsLibrary();
50         stop();
51         lib.scan({count: 1, resolveBackend: DummyResolver}).then(function() {
52             ok(lib.getSize() == 1, "there is one item in the library");
53             start();
54         });
55     });
56
57     test("get one item", function() {
58         var lib = new HoofbeatsLibrary(),
59             item_id = 'e7e7023b-54b3-41d5-b4a1-aa24498e0572';
60
61         stop();
62         lib.scan({count: 1, resolveBackend: DummyResolver}).then(function() {
63             var item = lib.item(item_id);
64             ok(item !== undefined, "item was found");
65             ok(item.id == item_id, "correct item was found");
66             start();
67         });
68     });
69 });