Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6164 from crdlc/info-fb-disabled
Browse files Browse the repository at this point in the history
Bug 808518 - Address info should be disabled when it is provided by Face...
  • Loading branch information
jmcanterafonseca committed Nov 6, 2012
2 parents 51a1383 + 3b05323 commit 2ba223a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
8 changes: 6 additions & 2 deletions apps/communications/contacts/js/contacts_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,20 @@ contacts.Form = (function() {

var default_type = tags[0].value || '';
var currField = {};
var infoFromFB = false;
for (var j = 0; j < fields.length; j++) {
var currentElem = fields[j];
var def = (currentElem === 'type') ? default_type : '';
var defObj = (typeof(obj) === 'string') ? obj : obj[currentElem];
currField[currentElem] = defObj || def;
var value = currField[currentElem] = defObj || def;
if (!infoFromFB && value && nonEditableValues[value]) {
infoFromFB = true;
}
}
currField['i'] = counters[type];
var rendered = utils.templates.render(template, currField);

if (currField.value && nonEditableValues[currField.value]) {
if (infoFromFB) {
var nodeClass = rendered.classList;
nodeClass.add(REMOVED_CLASS);
nodeClass.add(FB_CLASS);
Expand Down
41 changes: 41 additions & 0 deletions apps/communications/contacts/test/unit/contacts_form_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,35 @@ suite('Render contact form', function() {
}
});

test('FB Contact. home address from Facebook', function() {
window.fb.setIsFbContact(true);

var fbContact = new MockFb.Contact(mockContact);
fbContact.getDataAndValues().onsuccess = function() {
subject.render(mockContact, null, this.result);

var content = document.body.innerHTML;
var toCheck = ['address'];
for (var i = 0; i < toCheck.length; i++) {
var element = 'add-' + toCheck[i];
assert.isTrue(content.indexOf(element + '-0') > -1);
assert.isTrue(content.indexOf(element + '-1') === -1);

var domElement0 = document.querySelector('#' + element + '-' + '0');
assert.isTrue(domElement0.classList.contains('removed') &&
domElement0.classList.contains('facebook'),
'Class Removed and Facebook present');
assert.isTrue(domElement0.querySelector('.icon-delete') === null,
'Icon delete not present');
}

assertAddressData(0);

assert.isFalse(footer.classList.contains('hide'));
}
});


test('FB Linked. e-mail and phone both from FB and device', function() {
window.fb.setIsFbContact(true);
window.fb.setIsFbLinked(true);
Expand Down Expand Up @@ -261,4 +290,16 @@ suite('Render contact form', function() {
assert.isTrue(typeEmail === mockContact.email[c].type);
}

function assertAddressData(c) {
var valueType = document.querySelector('#address_type_' + c).textContent;
assert.isTrue(valueType === mockContact.adr[c].type[0],
'Type Value as Expected');
valueType = document.querySelector('#locality_' + c).value;
assert.isTrue(valueType === mockContact.adr[c].locality,
'Type Value as Expected');
valueType = document.querySelector('#countryName_' + c).value;
assert.isTrue(valueType === mockContact.adr[c].countryName,
'Type Value as Expected');
}

});
11 changes: 9 additions & 2 deletions apps/communications/contacts/test/unit/mock_fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ MockFb.Contact = function(devContact, mozCid) {
// Fetch FB data, that is returning a contact info
this.result = deviceContact;
this.result.org[0] = 'FB';
this.result.adr[0] = MockFb.getAddress();

callback.call(this);
},
Expand Down Expand Up @@ -134,9 +135,13 @@ MockFb.Contact = function(devContact, mozCid) {
// Fetch FB data, that is returning a contact info
this.result = [];
this.result[0] = deviceContact;
this.result[0].adr[0] = MockFb.getAddress();
this.result[1] = {
'+346578888888': 'p',
'test@test.com': 'p'
'+346578888888': true,
'test@test.com': true,
'Palencia': true,
'Castilla y Le—n': true,
'Espa–a': true
};

callback.call(this);
Expand Down Expand Up @@ -182,4 +187,6 @@ MockFb.getAddress = function(fbData) {
out.locality = 'Palencia';
out.region = 'Castilla y Le—n';
out.countryName = 'Espa–a';

return out;
};

0 comments on commit 2ba223a

Please sign in to comment.