cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblot...@apache.org
Subject cordova-plugin-contacts git commit: CB-9579 Fixed failed tests when "DeleteMe" contact already exists
Date Thu, 03 Sep 2015 01:13:35 GMT
Repository: cordova-plugin-contacts
Updated Branches:
  refs/heads/master 426285615 -> d51590c4b


CB-9579 Fixed failed tests when "DeleteMe" contact already exists


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/d51590c4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/d51590c4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/d51590c4

Branch: refs/heads/master
Commit: d51590c4bf873e292adbc4c32f06896967c25059
Parents: 4262856
Author: Alexander Sorokin <alexander.sorokin@akvelon.com>
Authored: Mon Aug 31 17:05:58 2015 +0300
Committer: Alexander Sorokin <alexander.sorokin@akvelon.com>
Committed: Mon Aug 31 17:05:58 2015 +0300

----------------------------------------------------------------------
 tests/tests.js | 80 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 43 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/d51590c4/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 86fc083..b115673 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -138,7 +138,6 @@ exports.defineAutoTests = function () {
                           // Find asserts
                           // ---
                           var findWin = function(object) {
-                                  console.log('in findwin');
                                   expect(object instanceof Array).toBe(true);
                                   expect(object.length >= 1).toBe(true);
                                   expect(foundName(object)).toBe(true);
@@ -385,42 +384,49 @@ exports.defineAutoTests = function () {
               if (isWindows || isWindowsPhone8) {
                   pending();
               }
-
-              gContactObj = new Contact();
-              gContactObj.name = new ContactName();
-              gContactObj.name.familyName = "DeleteMe";
-              gContactObj.save(function(c_obj) {
-                  var findWin = function(cs) {
-                      expect(cs.length).toBe(1);
-                      // update to have proper saved id
-                      gContactObj = cs[0];
-                      gContactObj.remove(function() {
-                          var findWinAgain = function(seas) {
-                              expect(seas.length).toBe(0);
-                              gContactObj.remove(function() {
-                                  throw("success callback called after non-existent Contact
object called remove(). Test failed.");
-                              }, function(e) {
-                                  expect(e.code).toBe(ContactError.UNKNOWN_ERROR);
-                                  done();
-                              });
-                          };
-                          var findFailAgain = function(e) {
-                              throw("find error callback invoked after delete, test failed.");
-                          };
-                          var obj = new ContactFindOptions();
-                          obj.filter="DeleteMe";
-                          obj.multiple=true;
-                          navigator.contacts.find(["displayName", "name", "phoneNumbers",
"emails"], findWinAgain, findFailAgain, obj);
-                      }, function(e) {
-                          throw("Newly created contact's remove function invoked error callback.
Test failed.");
-                      });
-                  };
-                  var findFail = fail;
-                  var obj = new ContactFindOptions();
-                  obj.filter="DeleteMe";
-                  obj.multiple=true;
-                  navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"],
findWin, findFail, obj);
-              }, fail);
+              // First, count already existing 'DeleteMe' contacts, if any
+              var initialCount = 0;
+              var initialSearchOptions = new ContactFindOptions();
+              initialSearchOptions.filter = "DeleteMe";
+              initialSearchOptions.multiple = true;
+              navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"],
function (initialContacts) {
+                  initialCount = initialContacts.length;
+                  gContactObj = new Contact();
+                  gContactObj.name = new ContactName();
+                  gContactObj.name.familyName = "DeleteMe";
+                  gContactObj.save(function(c_obj) {
+                      var findWin = function(cs) {
+                          expect(cs.length).toBe(initialCount + 1);
+                          // update to have proper saved id
+                          gContactObj = cs[0];
+                          gContactObj.remove(function() {
+                              var findWinAgain = function(seas) {
+                                  expect(seas.length).toBe(initialCount);
+                                  gContactObj.remove(function() {
+                                      throw("success callback called after non-existent Contact
object called remove(). Test failed.");
+                                  }, function(e) {
+                                      expect(e.code).toBe(ContactError.UNKNOWN_ERROR);
+                                      done();
+                                  });
+                              };
+                              var findFailAgain = function(e) {
+                                  throw("find error callback invoked after delete, test failed.");
+                              };
+                              var obj = new ContactFindOptions();
+                              obj.filter="DeleteMe";
+                              obj.multiple=true;
+                              navigator.contacts.find(["displayName", "name", "phoneNumbers",
"emails"], findWinAgain, findFailAgain, obj);
+                          }, function(e) {
+                              throw("Newly created contact's remove function invoked error
callback. Test failed.");
+                          });
+                      };
+                      var findFail = fail;
+                      var obj = new ContactFindOptions();
+                      obj.filter="DeleteMe";
+                      obj.multiple=true;
+                      navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"],
findWin, findFail, obj);
+                  }, fail);
+              }, function () {}, initialSearchOptions);
           }, MEDIUM_TIMEOUT);
       });
       describe('ContactError interface', function () {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message