Permalink
Browse files

Updating Contact tests to match June 16th W3C spec

  • Loading branch information...
1 parent 1f18193 commit 47774eac998ca77a41da11acd745179cbf167b96 @macdonst committed Jun 30, 2011
Showing with 74 additions and 35 deletions.
  1. +74 −35 tests/contacts.tests.js
View
@@ -1,37 +1,65 @@
Tests.prototype.ContactsTests = function() {
- module("Contacts (navigator.service.contacts)");
+ module("Contacts (navigator.contacts)");
test("should exist", function() {
expect(1);
- ok(navigator.service.contacts != null, "navigator.service.contacts should not be null.");
+ ok(navigator.contacts != null, "navigator.contacts should not be null.");
});
test("should contain a find function", function() {
expect(2);
- ok(typeof navigator.service.contacts.find != 'undefined' && navigator.service.contacts.find != null, "navigator.service.contacts.find should not be null.");
- ok(typeof navigator.service.contacts.find == 'function', "navigator.service.contacts.find should be a function.");
+ ok(typeof navigator.contacts.find != 'undefined' && navigator.contacts.find != null, "navigator.contacts.find should not be null.");
+ ok(typeof navigator.contacts.find == 'function', "navigator.contacts.find should be a function.");
});
- test("contacts.find success callback should be called with an array", function() {
- expect(2);
- QUnit.stop(Tests.TEST_TIMEOUT);
- var win = function(result) {
- ok(typeof result == 'object', "Object returned in contacts.find success callback is of type 'object' (actually array).");
- ok(typeof result.length == 'number', "Object returned in contacts.find success callback has a length property which is numerical.");
- QUnit.start();
- };
- var fail = function() { QUnit.start(); };
- var obj = new ContactFindOptions();
- obj.filter="";
- obj.multiple=true;
- navigator.service.contacts.find(["displayName", "name", "phoneNumbers", "emails"], win, fail, obj);
- });
+ test("contacts.find success callback should be called with an array", function() {
+ expect(2);
+ QUnit.stop(Tests.TEST_TIMEOUT);
+ var win = function(result) {
+ ok(typeof result == 'object', "Object returned in contacts.find success callback is of type 'object' (actually array).");
+ ok(typeof result.length == 'number', "Object returned in contacts.find success callback has a length property which is numerical.");
+ QUnit.start();
+ };
+ var fail = function() { QUnit.start(); };
+ var obj = new ContactFindOptions();
+ obj.filter="";
+ obj.multiple=true;
+ navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], win, fail, obj);
+ });
+ test("contacts.find success callback should not be null", function() {
+ expect(1);
+ var fail = function() {};
+ var obj = new ContactFindOptions();
+ obj.filter="";
+ obj.multiple=true;
+ try {
+ navigator.contacts.find(["displayName", "name", "emails", "phoneNumbers"], null, fail, obj);
+ } catch(e) {
+ ok(true, "Trying to find with a null success call back should throw TypeError.");
+ }
+ });
+ test("contacts.find error callback should be called when no fields are specified", function() {
+ expect(2);
+ QUnit.stop(Tests.TEST_TIMEOUT);
+ var win = function(result) {
+ QUnit.start();
+ };
+ var fail = function(result) {
+ ok(typeof result == 'object', "Object returned in contact.find failure callback is of type 'object' (actually ContactError).");
+ ok(result.code == ContactError.INVALID_ARGUMENT_ERROR, "Object returned in contacts.find failure callback has a code property which equal to ContactError.INVALID_ARGUMENT_ERROR.");
+ QUnit.start();
+ };
+ var obj = new ContactFindOptions();
+ obj.filter="";
+ obj.multiple=true;
+ navigator.contacts.find([], win, fail, obj);
+ });
test("should contain a create function", function() {
expect(2);
- ok(typeof navigator.service.contacts.create != 'undefined' && navigator.service.contacts.create != null, "navigator.service.contacts.create should not be null.");
- ok(typeof navigator.service.contacts.create == 'function', "navigator.service.contacts.create should be a function.");
+ ok(typeof navigator.contacts.create != 'undefined' && navigator.contacts.create != null, "navigator.contacts.create should not be null.");
+ ok(typeof navigator.contacts.create == 'function', "navigator.contacts.create should be a function.");
});
test("contacts.create should return a Contact object", function() {
expect(9);
- var obj = navigator.service.contacts.create({"displayName": "test name", "gender": "male", "note": "my note", "name": {"formatted": "Mr. Test Name"}, "emails": [{"value": "here@there.com"}, {"value": "there@here.com"}]});
- ok(obj != 'undefined' && obj != null, "navigator.service.contacts.create should return a Contact object.");
+ var obj = navigator.contacts.create({"displayName": "test name", "gender": "male", "note": "my note", "name": {"formatted": "Mr. Test Name"}, "emails": [{"value": "here@there.com"}, {"value": "there@here.com"}]});
+ ok(obj != 'undefined' && obj != null, "navigator.contacts.create should return a Contact object.");
ok(obj.displayName == 'test name', "Contact should contain a displayName property.");
ok(obj.gender == 'male', "Contact should contain a gender property.");
ok(obj.note == 'my note', "Contact should contain a note property.");
@@ -43,9 +71,9 @@ Tests.prototype.ContactsTests = function() {
});
module("Contact model");
test("should be able to define a Contact object", function() {
- expect(18);
- var contact = new Contact("a", "b", new ContactName("a", "b", "c", "d", "e", "f"), "c", [], [], [], [], [], "d", "f", "h", "i",
- [], [], [], "l");
+ expect(15);
+ var contact = new Contact("a", "b", new ContactName("a", "b", "c", "d", "e", "f"), "c", [], [], [], [], [], "f", "i",
+ [], [], []);
ok(contact != null, "new Contact() should not be null.");
ok(typeof contact.id != 'undefined' && contact.id != null && contact.id == "a", "new Contact() should include a 'id' property.");
ok(typeof contact.displayName != 'undefined' && contact.displayName != null && contact.displayName == "b", "new Contact() should include a 'displayName' property.");
@@ -56,14 +84,11 @@ Tests.prototype.ContactsTests = function() {
ok(typeof contact.addresses != 'undefined' && contact.addresses != null, "new Contact() should include a 'addresses' property.");
ok(typeof contact.ims != 'undefined' && contact.ims != null, "new Contact() should include a 'ims' property.");
ok(typeof contact.organizations != 'undefined' && contact.organizations != null, "new Contact() should include a 'organizations' property.");
- ok(typeof contact.revision != 'undefined' && contact.revision != null && contact.revision == "d", "new Contact() should include a 'revision' property.");
ok(typeof contact.birthday != 'undefined' && contact.birthday != null && contact.birthday == "f", "new Contact() should include a 'birthday' property.");
- ok(typeof contact.gender != 'undefined' && contact.gender != null && contact.gender == "h", "new Contact() should include a 'gender' property.");
ok(typeof contact.note != 'undefined' && contact.note != null && contact.note == "i", "new Contact() should include a 'note' property.");
ok(typeof contact.photos != 'undefined' && contact.photos != null, "new Contact() should include a 'photos' property.");
ok(typeof contact.categories != 'undefined' && contact.categories != null, "new Contact() should include a 'categories' property.");
ok(typeof contact.urls != 'undefined' && contact.urls != null, "new Contact() should include a 'urls' property.");
- ok(typeof contact.timezone != 'undefined' && contact.timezone != null && contact.timezone == "l", "new Contact() should include a 'timezone' property.");
});
test("should be able to define a ContactName object", function() {
expect(7);
@@ -85,9 +110,11 @@ Tests.prototype.ContactsTests = function() {
ok(typeof contactField.pref != 'undefined' && contactField.pref != null && contactField.pref == true, "new ContactField() should include a 'pref' property.");
});
test("should be able to define a ContactAddress object", function() {
- expect(7);
- var contactAddress = new ContactAddress("a","b","c","d","e","f");
+ expect(9);
+ var contactAddress = new ContactAddress(true, "home", "a","b","c","d","e","f");
ok(contactAddress != null, "new ContactAddress() should not be null.");
+ ok(typeof contactAddress.pref != 'undefined' && contactAddress.pref != null && contactAddress.pref == true, "new ContactAddress() should include a 'pref' property.");
+ ok(typeof contactAddress.type != 'undefined' && contactAddress.type != null && contactAddress.type == "home", "new ContactAddress() should include a 'type' property.");
ok(typeof contactAddress.formatted != 'undefined' && contactAddress.formatted != null && contactAddress.formatted == "a", "new ContactAddress() should include a 'formatted' property.");
ok(typeof contactAddress.streetAddress != 'undefined' && contactAddress.streetAddress != null && contactAddress.streetAddress == "b", "new ContactAddress() should include a 'streetAddress' property.");
ok(typeof contactAddress.locality != 'undefined' && contactAddress.locality != null && contactAddress.locality == "c", "new ContactAddress() should include a 'locality' property.");
@@ -96,20 +123,21 @@ Tests.prototype.ContactsTests = function() {
ok(typeof contactAddress.country != 'undefined' && contactAddress.country != null && contactAddress.country == "f", "new ContactAddress() should include a 'country' property.");
});
test("should be able to define a ContactOrganization object", function() {
- expect(4);
- var contactOrg = new ContactOrganization("a","b","c","d","e","f","g");
+ expect(6);
+ var contactOrg = new ContactOrganization(true, "home", "a","b","c","d","e","f","g");
ok(contactOrg != null, "new ContactOrganization() should not be null.");
+ ok(typeof contactOrg.pref != 'undefined' && contactOrg.pref != null && contactOrg.pref == true, "new ContactOrganization() should include a 'pref' property.");
+ ok(typeof contactOrg.type != 'undefined' && contactOrg.type != null && contactOrg.type == "home", "new ContactOrganization() should include a 'type' property.");
ok(typeof contactOrg.name != 'undefined' && contactOrg.name != null && contactOrg.name == "a", "new ContactOrganization() should include a 'name' property.");
ok(typeof contactOrg.department != 'undefined' && contactOrg.department != null && contactOrg.department == "b", "new ContactOrganization() should include a 'department' property.");
ok(typeof contactOrg.title != 'undefined' && contactOrg.title != null && contactOrg.title == "c", "new ContactOrganization() should include a 'title' property.");
});
test("should be able to define a ContactFindOptions object", function() {
- expect(4);
+ expect(3);
var contactFindOptions = new ContactFindOptions("a", true, "b");
ok(contactFindOptions != null, "new ContactFindOptions() should not be null.");
ok(typeof contactFindOptions.filter != 'undefined' && contactFindOptions.filter != null && contactFindOptions.filter == "a", "new ContactFindOptions() should include a 'filter' property.");
ok(typeof contactFindOptions.multiple != 'undefined' && contactFindOptions.multiple != null && contactFindOptions.multiple == true, "new ContactFindOptions() should include a 'multiple' property.");
- ok(typeof contactFindOptions.updatedSince != 'undefined' && contactFindOptions.updatedSince != null && contactFindOptions.updatedSince == "b", "new ContactFindOptions() should include a 'updatedSince' property.");
});
module("Contact Object");
test("should contain a clone function", function() {
@@ -165,7 +193,7 @@ Tests.prototype.ContactsTests = function() {
};
var fail = function(result) {
ok(typeof result == 'object', "Object returned in contact.remove failure callback is of type 'object' (actually ContactError).");
- ok(result.code == ContactError.NOT_FOUND_ERROR, "Object returned in contacts.remove failure callback has a code property which equal to ContactError.NOT_FOUND_ERROR.");
+ ok(result.code == ContactError.UNKNOWN_ERROR, "Object returned in contacts.remove failure callback has a code property which equal to ContactError.UNKNOWN_ERROR.");
QUnit.start();
};
var contact = new Contact(99);
@@ -177,4 +205,15 @@ Tests.prototype.ContactsTests = function() {
ok(typeof contact.save != 'undefined' && contact.save != null, "contact.save should not be null.");
ok(typeof contact.save == 'function', "contact.save should be a function.");
});
+ module('ContactError interface');
+ test("ContactError constants should be defined", function() {
+ expect(7);
+ equal(ContactError.UNKNOWN_ERROR, 0, "ContactError.UNKNOWN_ERROR should be defined");
+ equal(ContactError.INVALID_ARGUMENT_ERROR, 1, "ContactError.INVALID_ARGUMENT_ERROR should be defined");
+ equal(ContactError.TIMEOUT_ERROR, 2, "ContactError.TIMEOUT_ERROR should be defined");
+ equal(ContactError.PENDING_OPERATION_ERROR, 3, "ContactError.PENDING_OPERATION_ERROR should be defined");
+ equal(ContactError.IO_ERROR, 4, "ContactError.IO_ERROR should be defined");
+ equal(ContactError.NOT_SUPPORTED_ERROR, 5, "ContactError.NOT_SUPPORTED_ERROR should be defined");
+ equal(ContactError.PERMISSION_DENIED_ERROR, 20, "ContactError.PERMISSION_DENIED_ERROR should be defined");
+ });
};

0 comments on commit 47774ea

Please sign in to comment.