Commit ce617f1f authored by JC Brand's avatar JC Brand

Some refactoring of RosterView and skeleton for groups test

parent 0f6d1f9e
...@@ -3221,7 +3221,7 @@ ...@@ -3221,7 +3221,7 @@
initialize: function () { initialize: function () {
this.model.on("add", function (item) { this.model.on("add", function (item) {
this.addRosterItemView(item).render(item); this.addRosterItemView(item).updateRoster(item);
if (item.get('is_last')) { if (item.get('is_last')) {
this.sortRoster().showRoster(); this.sortRoster().showRoster();
} }
...@@ -3235,19 +3235,19 @@ ...@@ -3235,19 +3235,19 @@
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).render(item); this.updateChatBox(item).updateRoster(item);
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();
} }
}, this); }, this);
this.model.on("remove", function (item) { this.removeRosterItemView(item); }, this); this.model.on("remove", function (item) { this.removeRosterItemView(item); }, this);
this.model.on("destroy", function (item) { this.removeRosterItemView(item); }, this); this.model.on("destroy", function (item) { this.removeRosterItemView(item); }, this);
this.model.on("reset", function () { this.removeAllRosterItemViewss(); }, this); this.model.on("reset", function () { this.removeAllRosterItemViews(); }, this);
this.initRender(); this.render();
this.model.fetch({add: true}); // Get the cached roster items from localstorage this.model.fetch({add: true}); // Get the cached roster items from localstorage
}, },
initRender: function () { render: function () {
var desc_group_toggle = __('Click to hide these contacts'), var desc_group_toggle = __('Click to hide these contacts'),
toggle_state = 'opened', toggle_state = 'opened',
roster_markup = converse.templates.group_header({ roster_markup = converse.templates.group_header({
...@@ -3292,16 +3292,16 @@ ...@@ -3292,16 +3292,16 @@
return this; return this;
}, },
removeAllRosterItemViewss: function () { removeAllRosterItemViews: function () {
var views = this.removeAll(); var views = this.removeAll();
this.render(); this.updateRoster();
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.render(); this.updateRoster();
} }
return this; return this;
}, },
...@@ -3320,7 +3320,7 @@ ...@@ -3320,7 +3320,7 @@
} }
}, },
render: function (item) { updateRoster: function (item) {
var $contact_requests = this.$el.find('#xmpp-contact-requests'), var $contact_requests = this.$el.find('#xmpp-contact-requests'),
$pending_contacts = this.$el.find('#pending-xmpp-contacts'); $pending_contacts = this.$el.find('#pending-xmpp-contacts');
if (item) { if (item) {
......
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
it("can be added to the roster", $.proxy(function () { it("can be added to the roster", $.proxy(function () {
converse.rosterview.model.reset(); // We want to manually create users so that we can spy converse.rosterview.model.reset(); // We want to manually create users so that we can spy
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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',
...@@ -166,7 +166,7 @@ ...@@ -166,7 +166,7 @@
runs($.proxy(function () { runs($.proxy(function () {
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
expect(this.rosterview.$el.is(':visible')).toEqual(true); expect(this.rosterview.$el.is(':visible')).toEqual(true);
expect(this.rosterview.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
}, converse)); }, converse));
}, converse)); }, converse));
...@@ -203,7 +203,7 @@ ...@@ -203,7 +203,7 @@
converse.rosterview.model.reset(); // We want to manually create users so that we can spy converse.rosterview.model.reset(); // We want to manually create users so that we can spy
var i, t, is_last; var i, t, is_last;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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({
...@@ -213,7 +213,7 @@ ...@@ -213,7 +213,7 @@
fullname: mock.pend_names[i], fullname: mock.pend_names[i],
is_last: is_last is_last: is_last
}); });
expect(this.rosterview.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); 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();
...@@ -240,11 +240,15 @@ ...@@ -240,11 +240,15 @@
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 () {
checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]);
}, 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 () {
var i, t; var i, t;
converse.rosterview.model.reset(); converse.rosterview.model.reset();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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',
...@@ -253,7 +257,7 @@ ...@@ -253,7 +257,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.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
} }
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
...@@ -261,14 +265,37 @@ ...@@ -261,14 +265,37 @@
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
}, converse)); }, converse));
it("can be collapsed under their own header", $.proxy(function () { it("can be assigned to groups inside the roster", $.proxy(function () {
checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]); var i=0, j=0, t;
converse.rosterview.model.reset();
spyOn(converse, 'emit');
spyOn(this.rosterview, 'updateRoster').andCallThrough();
converse.roster_groups = true;
converse.rosterview.render();
var groups = {
colleagues: 3,
friends: 8,
family: 4
};
_.each(_.keys(groups), $.proxy(function (name) {
j = i;
for (i=j; i<j+groups[name]; i++) {
this.roster.create({
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
subscription: 'both',
ask: null,
groups: [name],
fullname: mock.cur_names[i],
is_last: i===(mock.cur_names.length-1)
});
}
}, converse));
}, 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 () {
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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);
...@@ -276,7 +303,7 @@ ...@@ -276,7 +303,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.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); 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();
...@@ -287,7 +314,7 @@ ...@@ -287,7 +314,7 @@
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 () {
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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);
...@@ -295,7 +322,7 @@ ...@@ -295,7 +322,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.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); 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();
...@@ -306,7 +333,7 @@ ...@@ -306,7 +333,7 @@
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 () {
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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);
...@@ -314,7 +341,7 @@ ...@@ -314,7 +341,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.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); 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();
...@@ -325,7 +352,7 @@ ...@@ -325,7 +352,7 @@
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 () {
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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);
...@@ -333,7 +360,7 @@ ...@@ -333,7 +360,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.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); 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();
...@@ -344,7 +371,7 @@ ...@@ -344,7 +371,7 @@
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 () {
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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);
...@@ -352,7 +379,7 @@ ...@@ -352,7 +379,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.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); 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();
...@@ -434,7 +461,7 @@ ...@@ -434,7 +461,7 @@
var i, children; var i, children;
var names = []; var names = [];
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'updateRoster').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')) {
...@@ -450,7 +477,7 @@ ...@@ -450,7 +477,7 @@
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.render).toHaveBeenCalled(); expect(this.rosterview.updateRoster).toHaveBeenCalled();
// 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');
names = []; names = [];
...@@ -540,7 +567,7 @@ ...@@ -540,7 +567,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.render(); this.rosterview.updateRoster();
}, converse)); }, converse));
afterEach($.proxy(function () { afterEach($.proxy(function () {
......
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