[
https://issues.apache.org/jira/browse/CB-5308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15029008#comment-15029008
]
ASF GitHub Bot commented on CB-5308:
------------------------------------
Github user daserge commented on a diff in the pull request:
https://github.com/apache/cordova-plugin-contacts/pull/87#discussion_r45990446
--- Diff: tests/tests.js ---
@@ -358,44 +380,68 @@ exports.defineAutoTests = function() {
pending();
}
- expect(gContactObj).toBeDefined();
-
- var bDay = new Date(1975, 5, 4);
+ var aDay = new Date(1976, 6, 4);
+ var bDay;
var noteText = "an UPDATED note";
- var win = function(obj) {
- expect(obj).toBeDefined();
- expect(obj.id).toBe(gContactObj.id);
- expect(obj.note).toBe(noteText);
-
expect(obj.birthday.toDateString()).toBe(bDay.toDateString());
- expect(obj.emails.length).toBe(1);
- expect(obj.emails[0].value).toBe('[email protected]');
- removeContact(); // Clean up contact object
- done();
+ var obj = {
+ "gender": "male",
+ "note": "my note",
+ "name": {
+ "familyName": "Delete",
+ "givenName": "Test"
},
- fail = function() {
- removeContact();
- fail(done);
- };
+ "emails": [{
+ "value": "[email protected]"
+ }, {
+ "value": "[email protected]"
+ }],
+ "birthday": aDay
+ };
+
+ var saveFail = fail.bind(null, done);
+
+ var saveSuccess = function(obj) {
+ // must store returned object in order to have id for
update test below
+ gContactObj = obj;
+ gContactObj.emails[1].value = "";
+ bDay = new Date(1975, 5, 4);
+ gContactObj.birthday = bDay;
+ gContactObj.note = noteText;
+ gContactObj.save(updateSuccess, saveFail);
+ };
+
+ var updateSuccess = function(obj) {
+ expect(obj).toBeDefined();
+ expect(obj.id).toBe(gContactObj.id);
+ expect(obj.note).toBe(noteText);
+
expect(obj.birthday.toDateString()).toBe(bDay.toDateString());
+ expect(obj.emails.length).toBe(1);
+ expect(obj.emails[0].value).toBe('[email protected]');
+ done();
+ };
+
+ navigator.contacts
+ .create(obj)
+ .save(saveSuccess, saveFail);
- // remove an email
- gContactObj.emails[1].value = "";
- // change birthday
- gContactObj.birthday = bDay;
- // update note
- gContactObj.note = noteText;
- gContactObj.save(win, fail);
}, MEDIUM_TIMEOUT);
});
+
describe('Contact.remove method', function(done) {
- afterEach(removeContact);
+ afterEach(function (done) {
+ removeContact(done);
+ });
it("contacts.spec.22 calling remove on a contact has an id of
null should return ContactError.UNKNOWN_ERROR", function(done) {
- var win = function() {};
+ var win = function() {
+ expect(false).toBe(true);
--- End diff --
IMO this might be rewritten to use the global `fail` function as in spec.23
and others, i.e. use `fail.bind` as it does the same thing.
> Contact.save() calls failure callback even though contact data is
> successfully saved on device
> ----------------------------------------------------------------------------------------------
>
> Key: CB-5308
> URL: https://issues.apache.org/jira/browse/CB-5308
> Project: Apache Cordova
> Issue Type: Bug
> Components: Plugin Contacts
> Environment: Android 4.1.2, 4.4.3 physical device. 4.4.3 device is
> Nexus 7.
> Cordova 3.1.0, 3.6.3
> Reporter: Shingo Toda
> Assignee: Vladimir Kotikov
> Labels: Android, reproduced, triaged
>
> When I run contact mobile-spec, following specs sometimes fail.
> - contacts.spec.6
> - contacts.spec.20
> - contacts.spec.21
> - contacts.spec.24
> In Java side, it looks that {{ContactAccessorSdk5.save()}} returns contact id
> but {{ContactAccessorSdk5.getContactById()}} returns {{null}} instead of
> contact data associated with the id. Actually some of contact data such as
> "Test Delete" are found on my device so the save operation is actually done.
> This save() returns "newId" in the following code.
> {code:title=ContactAccessorSdk5.java|borderStyle=solid}
> //Add contact
> try {
> ContentProviderResult[] cpResults =
> mApp.getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY,
> ops);
> if (cpResults.length >= 0) {
> newId = cpResults[0].uri.getLastPathSegment();
> }
> } catch (RemoteException e) {
> Log.e(LOG_TAG, e.getMessage(), e);
> } catch (OperationApplicationException e) {
> Log.e(LOG_TAG, e.getMessage(), e);
> }
> return newId;
> {code}
> When I debug it, {{cpResults\[0\].uri}} is
> {{content://com.android.contacts/raw_contacts/xxxx}} so, this is just my
> assumption, I think {{save()}} returns raw contact id.
> But at {{getContactById()}}, query filter uses {{CONTACT_ID}} column as a
> projection.
> {code:title=ContactAccessorSdk5.java|borderStyle=solid}
> Cursor c =
> mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
> null,
> ContactsContract.Data.CONTACT_ID + " = ? ",
> new String[] { id },
> ContactsContract.Data.CONTACT_ID + " ASC");
> {code}
> So if contact id and raw contact id is different then fetching contact data
> might fail. Actually in my case, if I fail the specs, they are always
> different.
> I try modifying {{getContactById()}} to process following code if contact
> JSONObject doesn't have id property, then I didn't get failure for those
> specs even if I run them some times.
> {code:title=ContactAccessorSdk5.java|borderStyle=solid}
> Cursor c =
> mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
> null,
> ContactsContract.Data.RAW_CONTACT_ID + " = ? ",
> new String[] { rawid },
> ContactsContract.Data.RAW_CONTACT_ID + " ASC");
> {code}
> I am just learning how contact data is managed on Android so I might be wrong
> for some use cases, but it works fine for mobile-spec.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]