incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [21/35] git commit: added rest of contact tests and fixed bug in Contact.clone
Date Thu, 23 Feb 2012 17:53:19 GMT
added rest of contact tests and fixed bug in Contact.clone


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/287a2b85
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/287a2b85
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/287a2b85

Branch: refs/heads/ios
Commit: 287a2b855455560320be0f96b90c9e22bba4ca45
Parents: 70b5664
Author: Gord Tanner <gtanner@gmail.com>
Authored: Fri Feb 17 11:16:37 2012 -0500
Committer: Gord Tanner <gtanner@gmail.com>
Committed: Fri Feb 17 11:16:37 2012 -0500

----------------------------------------------------------------------
 lib/plugin/Contact.js |    6 +-
 test/test.contact.js  |   89 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/287a2b85/lib/plugin/Contact.js
----------------------------------------------------------------------
diff --git a/lib/plugin/Contact.js b/lib/plugin/Contact.js
index 3d74352..1aa70d4 100644
--- a/lib/plugin/Contact.js
+++ b/lib/plugin/Contact.js
@@ -90,9 +90,9 @@ Contact.prototype.clone = function() {
             clonedContact.organizations[i].id = null;
         }
     }
-    if (clonedContact.tags) {
-        for (i = 0; i < clonedContact.tags.length; i++) {
-            clonedContact.tags[i].id = null;
+    if (clonedContact.categories) {
+        for (i = 0; i < clonedContact.categories.length; i++) {
+            clonedContact.categories[i].id = null;
         }
     }
     if (clonedContact.photos) {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/287a2b85/test/test.contact.js
----------------------------------------------------------------------
diff --git a/test/test.contact.js b/test/test.contact.js
index 95e498c..3ece349 100644
--- a/test/test.contact.js
+++ b/test/test.contact.js
@@ -2,6 +2,95 @@ describe("Contact", function () {
     var Contact = require('cordova/plugin/Contact'),
         exec = require('cordova/exec');
 
+
+    describe("ctor", function () {
+        it("sets the default values", function () {
+            var c = new Contact();
+
+            expect(c.id).toBe(null);
+            expect(c.rawId).toBe(null);
+            expect(c.displayName).toBe(null);
+            expect(c.name).toBe(null);
+            expect(c.nickname).toBe(null);
+            expect(c.phoneNumbers).toEqual([]);
+            expect(c.emails).toEqual([]);
+            expect(c.addresses).toEqual([]);
+            expect(c.ims).toEqual([]);
+            expect(c.organizations).toEqual([]);
+            expect(c.birthday).toBe(null);
+            expect(c.note).toBe(null);
+            expect(c.photos).toEqual([]);
+            expect(c.categories).toEqual([]);
+            expect(c.urls).toEqual([]);
+        });
+
+        it("overrides default values with the arguments", function () {
+            var c = new Contact(
+                1,
+                "Bart",
+                "Bartholomew JoJo Simpson",
+                "Bart",
+                ["KL5-3223"],
+                ["bart@but.com"],
+                ["742 Evergreen Terrace, Springfield USA"],
+                ["1234567"],
+                ["Springfield Elementary"],
+                new Date("April 1, 1979"),
+                "Everybody in the house do the Bartman",
+                ["http://upload.wikimedia.org/wikipedia/en/thumb/e/ed/Bart_Simpson.svg/200px-Bart_Simpson.svg.png"],
+                ["simpson", "child"],
+                ["www.thesimpsons.com"]
+            );
+
+            expect(c.id).toBe(1);
+            expect(c.rawId).toBe(null);
+            expect(c.displayName).toBe("Bart");
+            expect(c.name).toBe("Bartholomew JoJo Simpson");
+            expect(c.nickname).toBe("Bart");
+            expect(c.phoneNumbers).toEqual(["KL5-3223"]);
+            expect(c.emails).toEqual(["bart@but.com"]);
+            expect(c.addresses).toEqual(["742 Evergreen Terrace, Springfield USA"]);
+            expect(c.ims).toEqual(["1234567"]);
+            expect(c.organizations).toEqual(["Springfield Elementary"]);
+            expect(c.birthday).toEqual(new Date("April 1, 1979")),
+            expect(c.note).toBe("Everybody in the house do the Bartman");
+            expect(c.photos).toEqual(["http://upload.wikimedia.org/wikipedia/en/thumb/e/ed/Bart_Simpson.svg/200px-Bart_Simpson.svg.png"]);
+            expect(c.categories).toEqual(["simpson", "child"]);
+            expect(c.urls).toEqual(["www.thesimpsons.com"]);
+        });
+    });
+
+    describe("clone", function () {
+        it("clears the id's on the cloned contact", function () {
+
+            var c = new Contact();
+            c.id = 1;
+            c.rawId = 1;
+
+            c.phoneNumbers.push({id: 1});
+            c.emails.push({id: 1});
+            c.addresses.push({id: 1});
+            c.ims.push({id: 1});
+            c.organizations.push({id: 1});
+            c.categories.push({id: 1});
+            c.photos.push({id: 1});
+            c.urls.push({id: 1});
+
+            var clone = c.clone();
+
+            expect(clone.id).toBeNull();
+            expect(clone.rawId).toBeNull();
+            expect(clone.phoneNumbers[0].id).toBeNull();
+            expect(clone.emails[0].id).toBeNull();
+            expect(clone.addresses[0].id).toBeNull();
+            expect(clone.ims[0].id).toBeNull();
+            expect(clone.organizations[0].id).toBeNull();
+            expect(clone.categories[0].id).toBeNull();
+            expect(clone.photos[0].id).toBeNull();
+            expect(clone.urls[0].id).toBeNull();
+        });
+    });
+
     describe("save", function () {
         it("calls exec when saving", function () {
             var c = new Contact(),


Mime
View raw message