|
1 Tests.prototype.ContactsTests = function() { |
|
2 module("Contacts model"); |
|
3 test("should be able to define a Contacts object with name, emails, and phones attributes.", function() { |
|
4 expect(5); |
|
5 var con = new Contact(); |
|
6 ok(con != null, "new Contact() should not be null."); |
|
7 ok(con.name != null, "new Contact() should include a 'name' property."); |
|
8 ok(con.name.formatted != null, "new Contact()'s 'name' property should, at the very least, contain a 'formatted' property."); |
|
9 ok(con.emails != null, "new Contact() should include an 'emails' array."); |
|
10 ok(con.phones != null, "new Contact() should include a 'phones' array."); |
|
11 }); |
|
12 module('Contacts (navigator.contacts)'); |
|
13 test("should exist", function() { |
|
14 expect(1); |
|
15 ok(navigator.contacts != null, "navigator.contacts should not be null."); |
|
16 }); |
|
17 test("should contain a find function", function() { |
|
18 expect(2); |
|
19 ok(typeof navigator.contacts.find != 'undefined' && navigator.contacts.find != null, "navigator.contacts.find should not be null."); |
|
20 ok(typeof navigator.contacts.find == 'function', "navigator.contacts.find should be a function."); |
|
21 }); |
|
22 // TODO: Need to add tests for the find function. Need to be able to include test data, but how? How do we add a contact |
|
23 // to the phone before running the test? |
|
24 // TODO: Need to include tests that check error-handling, doubt there is any in the framework code. |
|
25 test("contacts.find success callback should be called with an array", function() { |
|
26 expect(2); |
|
27 stop(tests.TEST_TIMEOUT); |
|
28 var win = function(result) { |
|
29 ok(typeof result == 'object', "Object returned in contacts.find success callback is of type 'object' (actually array)."); |
|
30 ok(typeof result.length == 'number', "Object returned in contacts.find success callback has a length property which is numerical."); |
|
31 start(); |
|
32 }; |
|
33 var fail = function() { start(); }; |
|
34 var filter = new Contact(); |
|
35 filter.name.formatted = ''; |
|
36 navigator.contacts.find(filter,win, fail); |
|
37 }); |
|
38 }; |