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 #10902 from wanderview/contacts-favorites
Browse files Browse the repository at this point in the history
Bug 891984: Properly render contacts in favorites.  r=crdlc
  • Loading branch information
Ben Kelly committed Jul 11, 2013
2 parents 84c53c0 + 1f71971 commit 7d73558
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/communications/contacts/js/contacts_list.js
Expand Up @@ -350,10 +350,10 @@ contacts.List = (function() {
// visibile DOM elements will be rendered later via the visibility monitor.
// This function ensures that necessary meta data is defined in the node
// dataset.
var createPlaceholder = function createPlaceholder(contact) {
var createPlaceholder = function createPlaceholder(contact, group) {
var ph = document.createElement('li');
ph.dataset.uuid = contact.id;
var group = getFastGroupName(contact);
var group = group || getFastGroupName(contact);
var order = null;
if (!group) {
order = getStringToBeOrdered(contact);
Expand Down Expand Up @@ -531,7 +531,7 @@ contacts.List = (function() {

//Adds each contact to its group container
function appendToList(contact, group, ph) {
ph = ph || createPlaceholder(contact);
ph = ph || createPlaceholder(contact, group);
var list = headers[group];

// If above the fold for list, render immediately
Expand Down Expand Up @@ -858,7 +858,9 @@ contacts.List = (function() {
// If is favorite add as well to the favorite group
if (isFavorite(contact)) {
list = headers['favorites'];
addToGroup(renderedNode.cloneNode(), list);
var cloned = renderedNode.cloneNode();
cloned.dataset.group = 'favorites';
addToGroup(cloned, list);
}
toggleNoContactsScreen(false);
FixedHeader.refresh();
Expand Down
33 changes: 33 additions & 0 deletions apps/communications/contacts/test/unit/contacts_list_test.js
Expand Up @@ -768,6 +768,39 @@ suite('Render contacts list', function() {
done();
});

// This test verifies that we properly render contact list elements
// for both its main group and favorites group. This requires the
// visibility monitor to fire an onscreen event for each group element
// separately. See bug 891984 for a previous error in this logic.
test('load and render many favorites', function(done) {
var names = ['AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI'];
var list = [];
for (var i = 0; i < names.length; ++i) {
var name = names[i];
var c = new MockContactAllFields();
c.id = 'mock-' + i;
c.familyName = [name];
c.category = ['favorite'];
list.push(c);
}
doLoad(subject, list, function() {
var favList = assertGroup(groupFav, containerFav, names.length);
var lastFav = favList[favList.length - 1];
doOnscreen(subject, lastFav, function() {
assert.equal(lastFav.dataset.rendered, 'true',
'contact should be rendered in "favorites" list');

var aList = assertGroup(groupA, containerA, names.length);
var lastA = aList[aList.length - 1];
doOnscreen(subject, lastA, function() {
assert.equal(lastA.dataset.rendered, 'true',
'contact should be rendered in "A" list');
done();
});
});
});
});

test('reseting the dom of the contacts list', function(done) {
var newList = new MockContactsList();
doLoad(subject, newList, function() {
Expand Down

0 comments on commit 7d73558

Please sign in to comment.