Commit 3984aadb authored by JC Brand's avatar JC Brand

More work (with tests) on showing roster items under groups.

updates #83
parent be761562
...@@ -280,6 +280,9 @@ ...@@ -280,6 +280,9 @@
'xa': __('This contact is away for an extended period'), 'xa': __('This contact is away for an extended period'),
'away': __('This contact is away') 'away': __('This contact is away')
}; };
var DESC_GROUP_TOGGLE = __('Click to hide these contacts');
var HEADER_CURRENT_CONTACTS = __('My contacts');
var HEADER_UNGROUPED = __('Ungrouped');
// Module-level variables // Module-level variables
// ---------------------- // ----------------------
...@@ -2806,6 +2809,7 @@ ...@@ -2806,6 +2809,7 @@
'id': jid, 'id': jid,
'user_id': Strophe.getNodeFromJid(jid), 'user_id': Strophe.getNodeFromJid(jid),
'resources': [], 'resources': [],
'groups': [],
'status': '' 'status': ''
}, attributes); }, attributes);
attrs.sorted = false; attrs.sorted = false;
...@@ -3252,22 +3256,22 @@ ...@@ -3252,22 +3256,22 @@
}, },
render: function () { render: function () {
var desc_group_toggle = __('Click to hide these contacts'), var toggle_state = 'opened', // TODO: remember state...
toggle_state = 'opened',
roster_markup = converse.templates.group_header({ roster_markup = converse.templates.group_header({
label_group: this.roster_groups ? __('Ungrouped') : __('My contacts'), label_group: converse.roster_groups ? HEADER_UNGROUPED : HEADER_CURRENT_CONTACTS,
desc_group_toggle: desc_group_toggle, desc_group_toggle: DESC_GROUP_TOGGLE,
toggle_state: toggle_state toggle_state: toggle_state
}); });
if (converse.allow_contact_requests) { if (converse.allow_contact_requests) {
roster_markup += converse.templates.requesting_contacts({ roster_markup += converse.templates.requesting_contacts({
label_contact_requests: __('Contact requests'), label_contact_requests: __('Contact requests'),
desc_group_toggle: desc_group_toggle, desc_group_toggle: DESC_GROUP_TOGGLE,
toggle_state: toggle_state toggle_state: toggle_state
}) + }) +
converse.templates.pending_contacts({ converse.templates.pending_contacts({
label_pending_contacts: __('Pending contacts'), label_pending_contacts: __('Pending contacts'),
desc_group_toggle: desc_group_toggle, desc_group_toggle: DESC_GROUP_TOGGLE,
toggle_state: toggle_state toggle_state: toggle_state
}); });
} }
...@@ -3275,10 +3279,18 @@ ...@@ -3275,10 +3279,18 @@
this.$fragment.append($(roster_markup)); this.$fragment.append($(roster_markup));
}, },
insertRosterFragment: function () {
if (this.$fragment) {
this.$el.html(this.$fragment)
delete this.$fragment;
}
return this;
},
onAdd: function (item) { onAdd: function (item) {
this.addRosterItem(item).updateRoster(); this.addRosterItem(item);
if (item.get('is_last')) { if (item.get('is_last')) {
this.sortRoster().showRoster(); this.toggleHeaders().sortRoster().insertRosterFragment().updateCount();
} }
if (!item.get('vcard_updated')) { if (!item.get('vcard_updated')) {
// This will update the vcard, which triggers a change // This will update the vcard, which triggers a change
...@@ -3287,19 +3299,11 @@ ...@@ -3287,19 +3299,11 @@
} }
}, },
showRoster: function () {
if (this.$fragment) {
this.$el.html(this.$fragment)
delete this.$fragment;
}
return this;
},
onChange: function (item) { onChange: function (item) {
if ((_.size(item.changed) === 1) && _.contains(_.keys(item.changed), 'sorted')) { if ((_.size(item.changed) === 1) && _.contains(_.keys(item.changed), 'sorted')) {
return; return;
} }
this.updateChatBox(item).renderRosterItem(item).updateRoster(); this.updateChatBox(item).renderRosterItem(item).toggleHeaders().updateCount();
if (item.changed.chat_status) { // A changed chat status implies a new sort order if (item.changed.chat_status) { // A changed chat status implies a new sort order
this.sortRoster(); this.sortRoster();
} }
...@@ -3323,14 +3327,14 @@ ...@@ -3323,14 +3327,14 @@
removeAllRosterItemViews: function () { removeAllRosterItemViews: function () {
this.removeAll(); this.removeAll();
this.updateRoster(); this.updateCount().toggleHeaders();
return this; return this;
}, },
removeRosterItemView: function (item) { removeRosterItemView: function (item) {
if (this.get(item.id)) { if (this.get(item.id)) {
this.get(item.id).remove(); this.get(item.id).remove();
this.updateRoster(); this.updateCount().toggleHeaders();
} }
return this; return this;
}, },
...@@ -3361,6 +3365,32 @@ ...@@ -3361,6 +3365,32 @@
} }
}, },
addCurrentContact: function (view) {
var $el = this.getRosterElement(),
item = view.model;
if (converse.roster_groups) {
if (item.get('groups').length === 0) {
$el.find('.roster-group[data-group="'+HEADER_UNGROUPED+'"]').after(view.el);
} else {
_.each(item.get('groups'), $.proxy(function (group) {
var $group = $el.find('.roster-group[data-group="'+group+'"]');
if ($group.length > 0) {
$group.after(view.el);
} else {
$group = $(converse.templates.group_header({
label_group: group,
desc_group_toggle: DESC_GROUP_TOGGLE,
toggle_state: 'opened' // TODO: remember state...
})).after(view.el);
this.getRosterElement().append($group);
}
},this));
}
} else {
$el.find('.roster-group[data-group="'+HEADER_CURRENT_CONTACTS+'"]').after(view.el);
}
},
addRosterItem: function (item) { addRosterItem: function (item) {
var view = new converse.RosterItemView({model: item}); var view = new converse.RosterItemView({model: item});
this.add(item.id, view); this.add(item.id, view);
...@@ -3368,24 +3398,16 @@ ...@@ -3368,24 +3398,16 @@
return this; return this;
} }
view.render() view.render()
var $el = this.getRosterElement();
if (view.$el.hasClass('current-xmpp-contact')) { if (view.$el.hasClass('current-xmpp-contact')) {
// TODO: need to add group support this.addCurrentContact(view);
$el.find('.roster-group').after(view.el);
} else if (view.$el.hasClass('pending-xmpp-contact')) { } else if (view.$el.hasClass('pending-xmpp-contact')) {
$el.find('#pending-xmpp-contacts').after(view.el); this.getRosterElement().find('#pending-xmpp-contacts').after(view.el);
} else if (view.$el.hasClass('requesting-xmpp-contact')) { } else if (view.$el.hasClass('requesting-xmpp-contact')) {
$el.find('#xmpp-contact-requests').after(view.render().el); this.getRosterElement().find('#xmpp-contact-requests').after(view.render().el);
} }
return this; return this;
}, },
updateRoster: function (item) {
this.updateCount().toggleHeaders();
converse.emit('rosterViewUpdated');
return this;
},
updateCount: function () { updateCount: function () {
var $count = $('#online-count'); var $count = $('#online-count');
$count.text('('+this.model.getNumOnlineContacts()+')'); $count.text('('+this.model.getNumOnlineContacts()+')');
......
...@@ -784,8 +784,6 @@ Here are the different events that are emitted: ...@@ -784,8 +784,6 @@ Here are the different events that are emitted:
+----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+ +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
| **roster** | When the roster is updated. | ``converse.on('roster', function (items) { ... });`` | | **roster** | When the roster is updated. | ``converse.on('roster', function (items) { ... });`` |
+----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+ +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
| **rosterViewUpdated** | Whenever the roster view (i.e. the rendered HTML) has changed. | ``converse.on('rosterViewUpdated', function (items) { ... });`` |
+----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
| **callButtonClicked** | When a call button (i.e. with class .toggle-call) on a chat box has been clicked. | ``converse.on('callButtonClicked', function (connection, model) { ... });`` | | **callButtonClicked** | When a call button (i.e. with class .toggle-call) on a chat box has been clicked. | ``converse.on('callButtonClicked', function (connection, model) { ... });`` |
+----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+ +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
| **chatBoxOpened** | When a chat box has been opened. | ``converse.on('chatBoxOpened', function (chatbox) { ... });`` | | **chatBoxOpened** | When a chat box has been opened. | ``converse.on('chatBoxOpened', function (chatbox) { ... });`` |
......
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
</dl> </dl>
<dl id="converse-roster" style="display: block;"> <dl id="converse-roster" style="display: block;">
<dt class="roster-group" style="display: block;"> <dt class="roster-group" style="display: block;">
<a href="#" class="group-toggle icon-opened" title="Click to hide these contacts">Colleagues</a> <a href="#" data-group="Colleagues" class="group-toggle icon-opened" title="Click to hide these contacts">Colleagues</a>
</dt> </dt>
<dd class="online current-xmpp-contact"> <dd class="online current-xmpp-contact">
<a class="open-chat" title="Click to chat with this contact" href="#"> <a class="open-chat" title="Click to chat with this contact" href="#">
...@@ -141,7 +141,7 @@ ...@@ -141,7 +141,7 @@
</dd> </dd>
<dt class="roster-group" style="display: block;"> <dt class="roster-group" style="display: block;">
<a href="#" class="group-toggle icon-opened" title="Click to hide these contacts">Family</a> <a href="#" data-group="Family" class="group-toggle icon-opened" title="Click to hide these contacts">Family</a>
</dt> </dt>
<dd class="away current-xmpp-contact"> <dd class="away current-xmpp-contact">
<a class="open-chat" title="Click to chat with this contact" href="#"> <a class="open-chat" title="Click to chat with this contact" href="#">
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
</dd> </dd>
<dt class="roster-group" style="display: block;"> <dt class="roster-group" style="display: block;">
<a href="#" class="group-toggle icon-opened" title="Click to hide these contacts">Friends</a> <a href="#" data-group="Friends" class="group-toggle icon-opened" title="Click to hide these contacts">Friends</a>
</dt> </dt>
<dd class="online current-xmpp-contact"> <dd class="online current-xmpp-contact">
<a class="open-chat" title="Click to chat with this contact" href="#"> <a class="open-chat" title="Click to chat with this contact" href="#">
......
...@@ -138,8 +138,7 @@ ...@@ -138,8 +138,7 @@
function _addContacts () { function _addContacts () {
_clearContacts(); _clearContacts();
// Must be initialized, so that render is called and documentFragment set up. // Must be initialized, so that render is called and documentFragment set up.
utils.createContacts('pending').openControlBox(); utils.createContacts('pending').openControlBox().openContactsPanel();
utils.openContactsPanel();
}; };
it("do not have a header if there aren't any", $.proxy(function () { it("do not have a header if there aren't any", $.proxy(function () {
...@@ -156,7 +155,7 @@ ...@@ -156,7 +155,7 @@
it("can be added to the roster", $.proxy(function () { it("can be added to the roster", $.proxy(function () {
_clearContacts(); _clearContacts();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
runs($.proxy(function () { runs($.proxy(function () {
this.roster.create({ this.roster.create({
jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost', jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
...@@ -168,9 +167,8 @@ ...@@ -168,9 +167,8 @@
}, converse)); }, converse));
waits(300); waits(300);
runs($.proxy(function () { runs($.proxy(function () {
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
expect(this.rosterview.$el.is(':visible')).toEqual(true); expect(this.rosterview.$el.is(':visible')).toEqual(true);
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
}, converse)); }, converse));
}, converse)); }, converse));
...@@ -191,7 +189,6 @@ ...@@ -191,7 +189,6 @@
expect(this.rosterview.model.remove).toHaveBeenCalled(); expect(this.rosterview.model.remove).toHaveBeenCalled();
// The element must now be detached from the DOM. // The element must now be detached from the DOM.
expect(view.$el.closest('html').length).toBeFalsy(); expect(view.$el.closest('html').length).toBeFalsy();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
}, converse)); }, converse));
it("will lose their own header once the last one has been removed", $.proxy(function () { it("will lose their own header once the last one has been removed", $.proxy(function () {
...@@ -209,7 +206,7 @@ ...@@ -209,7 +206,7 @@
_clearContacts(); _clearContacts();
var i, t, is_last; var i, t, is_last;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
for (i=0; i<mock.pend_names.length; i++) { for (i=0; i<mock.pend_names.length; i++) {
is_last = i===(mock.pend_names.length-1); is_last = i===(mock.pend_names.length-1);
this.roster.create({ this.roster.create({
...@@ -219,8 +216,7 @@ ...@@ -219,8 +216,7 @@
fullname: mock.pend_names[i], fullname: mock.pend_names[i],
is_last: is_last is_last: is_last
}); });
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
} }
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').find('span').text(); t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').find('span').text();
...@@ -230,31 +226,34 @@ ...@@ -230,31 +226,34 @@
}, converse)); }, converse));
describe("Existing Contacts", $.proxy(function () { describe("Existing Contacts", $.proxy(function () {
beforeEach($.proxy(function () { function _clearContacts () {
runs(function () { utils.clearBrowserStorage();
converse.rosterview.model.reset(); converse.rosterview.model.reset();
utils.createContacts().openControlBox(); converse.rosterview.initialize(); // Register new listeners and document fragment
}); };
waits(50);
runs(function () { var _addContacts = function () {
utils.openContactsPanel(); _clearContacts();
}); utils.createContacts().openControlBox().openContactsPanel();
}, converse)); };
it("do not have a header if there aren't any", $.proxy(function () { it("do not have a header if there aren't any", $.proxy(function () {
converse.rosterview.model.reset(); // To properly tests, we add contacts and then remove them all again.
_addContacts();
this.rosterview.model.reset();
expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('none'); expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('none');
}, converse)); }, converse));
it("can be collapsed under their own header", $.proxy(function () { it("can be collapsed under their own header", $.proxy(function () {
_addContacts();
checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]); checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]);
}, converse)); }, converse));
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () { it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
_clearContacts();
var i, t; var i, t;
converse.rosterview.model.reset();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
this.roster.create({ this.roster.create({
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost', jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
...@@ -263,8 +262,7 @@ ...@@ -263,8 +262,7 @@
fullname: mock.cur_names[i], fullname: mock.cur_names[i],
is_last: i===(mock.cur_names.length-1) is_last: i===(mock.cur_names.length-1)
}); });
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
} }
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text(); t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
...@@ -272,10 +270,10 @@ ...@@ -272,10 +270,10 @@
}, converse)); }, converse));
it("can be assigned to groups inside the roster", $.proxy(function () { it("can be assigned to groups inside the roster", $.proxy(function () {
_clearContacts();
var i=0, j=0, t; var i=0, j=0, t;
converse.rosterview.model.reset();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
converse.roster_groups = true; converse.roster_groups = true;
converse.rosterview.render(); converse.rosterview.render();
var groups = { var groups = {
...@@ -299,9 +297,10 @@ ...@@ -299,9 +297,10 @@
}, converse)); }, converse));
it("can change their status to online and be sorted alphabetically", $.proxy(function () { it("can change their status to online and be sorted alphabetically", $.proxy(function () {
_addContacts();
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
...@@ -309,8 +308,7 @@ ...@@ -309,8 +308,7 @@
item = view.model; item = view.model;
item.set('chat_status', 'online'); item.set('chat_status', 'online');
expect(view.render).toHaveBeenCalled(); expect(view.render).toHaveBeenCalled();
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text(); t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
...@@ -318,9 +316,10 @@ ...@@ -318,9 +316,10 @@
}, converse)); }, converse));
it("can change their status to busy and be sorted alphabetically", $.proxy(function () { it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
_addContacts();
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
...@@ -328,8 +327,7 @@ ...@@ -328,8 +327,7 @@
item = view.model; item = view.model;
item.set('chat_status', 'dnd'); item.set('chat_status', 'dnd');
expect(view.render).toHaveBeenCalled(); expect(view.render).toHaveBeenCalled();
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text(); t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
...@@ -337,9 +335,10 @@ ...@@ -337,9 +335,10 @@
}, converse)); }, converse));
it("can change their status to away and be sorted alphabetically", $.proxy(function () { it("can change their status to away and be sorted alphabetically", $.proxy(function () {
_addContacts();
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
...@@ -347,8 +346,7 @@ ...@@ -347,8 +346,7 @@
item = view.model; item = view.model;
item.set('chat_status', 'away'); item.set('chat_status', 'away');
expect(view.render).toHaveBeenCalled(); expect(view.render).toHaveBeenCalled();
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text(); t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
...@@ -356,9 +354,10 @@ ...@@ -356,9 +354,10 @@
}, converse)); }, converse));
it("can change their status to xa and be sorted alphabetically", $.proxy(function () { it("can change their status to xa and be sorted alphabetically", $.proxy(function () {
_addContacts();
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
...@@ -366,8 +365,7 @@ ...@@ -366,8 +365,7 @@
item = view.model; item = view.model;
item.set('chat_status', 'xa'); item.set('chat_status', 'xa');
expect(view.render).toHaveBeenCalled(); expect(view.render).toHaveBeenCalled();
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text(); t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
...@@ -375,9 +373,10 @@ ...@@ -375,9 +373,10 @@
}, converse)); }, converse));
it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () { it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
_addContacts();
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
for (i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
...@@ -385,8 +384,7 @@ ...@@ -385,8 +384,7 @@
item = view.model; item = view.model;
item.set('chat_status', 'unavailable'); item.set('chat_status', 'unavailable');
expect(view.render).toHaveBeenCalled(); expect(view.render).toHaveBeenCalled();
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text(); t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(0, i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0, i+1).sort().join(''));
...@@ -394,6 +392,7 @@ ...@@ -394,6 +392,7 @@
}, converse)); }, converse));
it("are ordered according to status: online, busy, away, xa, unavailable, offline", $.proxy(function () { it("are ordered according to status: online, busy, away, xa, unavailable, offline", $.proxy(function () {
_addContacts();
var i; var i;
for (i=0; i<3; i++) { for (i=0; i<3; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
...@@ -468,7 +467,7 @@ ...@@ -468,7 +467,7 @@
var i, children; var i, children;
var names = []; var names = [];
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough(); spyOn(this.rosterview, 'updateCount').andCallThrough();
spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough(); spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
var addName = function (idx, item) { var addName = function (idx, item) {
if (!$(item).hasClass('request-actions')) { if (!$(item).hasClass('request-actions')) {
...@@ -484,11 +483,10 @@ ...@@ -484,11 +483,10 @@
fullname: mock.req_names[i], fullname: mock.req_names[i],
is_last: i===(mock.req_names.length-1) is_last: i===(mock.req_names.length-1)
}); });
expect(this.rosterview.updateRoster).toHaveBeenCalled(); expect(this.rosterview.updateCount).toHaveBeenCalled();
// When a requesting contact is added, the controlbox must // When a requesting contact is added, the controlbox must
// be opened. // be opened.
expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled(); expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
} }
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
children = this.rosterview.$el.find('dt#xmpp-contact-requests').siblings('dd.requesting-xmpp-contact').children('span'); children = this.rosterview.$el.find('dt#xmpp-contact-requests').siblings('dd.requesting-xmpp-contact').children('span');
...@@ -536,7 +534,6 @@ ...@@ -536,7 +534,6 @@
expect(window.confirm).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled();
expect(this.rosterview.removeRosterItemView).toHaveBeenCalled(); expect(this.rosterview.removeRosterItemView).toHaveBeenCalled();
expect(this.connection.roster.unauthorize).toHaveBeenCalled(); expect(this.connection.roster.unauthorize).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
// There should now be one less contact // There should now be one less contact
expect(this.roster.length).toEqual(mock.req_names.length-1); expect(this.roster.length).toEqual(mock.req_names.length-1);
}, converse)); }, converse));
...@@ -579,7 +576,7 @@ ...@@ -579,7 +576,7 @@
// comparison // comparison
expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true); expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
} }
this.rosterview.updateRoster(); // XXX: this.rosterview.updateCount();
}, converse)); }, converse));
afterEach($.proxy(function () { afterEach($.proxy(function () {
......
<dt class="roster-group"><a href="#" class="group-toggle icon-{{toggle_state}}" title="{{desc_group_toggle}}">{{label_group}}</a></dt> <dt class="roster-group" data-group="{{label_group}}">
<a href="#" class="group-toggle icon-{{toggle_state}}" title="{{desc_group_toggle}}">{{label_group}}</a>
</dt>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment