Commit 5034ae33 authored by JC Brand's avatar JC Brand

Work on getting proper separation between tests.

parent 718f75a4
...@@ -3223,6 +3223,7 @@ ...@@ -3223,6 +3223,7 @@
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);
var roster_markup = converse.templates.contacts({ var roster_markup = converse.templates.contacts({
'label_contacts': __('My contacts') 'label_contacts': __('My contacts')
...@@ -3263,6 +3264,12 @@ ...@@ -3263,6 +3264,12 @@
return this; return this;
}, },
removeAllRosterItemViewss: function () {
var views = this.removeAll();
this.render();
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 diff is collapsed.
...@@ -205,7 +205,7 @@ ...@@ -205,7 +205,7 @@
beforeEach($.proxy(function () { beforeEach($.proxy(function () {
runs(function () { runs(function () {
converse.rosterview.model.reset(); converse.rosterview.model.reset();
converse.rosterview.render(); utils.createCurrentContacts();
}); });
waits(50); waits(50);
runs(function () { runs(function () {
...@@ -218,16 +218,18 @@ ...@@ -218,16 +218,18 @@
}, converse)); }, converse));
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
converse.rosterview.model.reset();
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none'); expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none');
}, 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 () {
var i, t; var i, t;
converse.rosterview.model.reset();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').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(' ','.').toLowerCase() + '@localhost', jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
subscription: 'both', subscription: 'both',
ask: null, ask: null,
fullname: mock.cur_names[i], fullname: mock.cur_names[i],
...@@ -249,8 +251,8 @@ ...@@ -249,8 +251,8 @@
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').andCallThrough();
for (i=0; i<3; i++) { for (i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
spyOn(view, 'render').andCallThrough(); spyOn(view, 'render').andCallThrough();
item = view.model; item = view.model;
...@@ -268,8 +270,8 @@ ...@@ -268,8 +270,8 @@
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').andCallThrough();
for (i=3; i<6; i++) { for (i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
spyOn(view, 'render').andCallThrough(); spyOn(view, 'render').andCallThrough();
item = view.model; item = view.model;
...@@ -279,7 +281,7 @@ ...@@ -279,7 +281,7 @@
expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated'); expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(3,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
} }
}, converse)); }, converse));
...@@ -287,8 +289,8 @@ ...@@ -287,8 +289,8 @@
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').andCallThrough();
for (i=6; i<9; i++) { for (i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
spyOn(view, 'render').andCallThrough(); spyOn(view, 'render').andCallThrough();
item = view.model; item = view.model;
...@@ -298,7 +300,7 @@ ...@@ -298,7 +300,7 @@
expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated'); expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(6,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
} }
}, converse)); }, converse));
...@@ -306,7 +308,7 @@ ...@@ -306,7 +308,7 @@
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').andCallThrough();
for (i=9; i<12; 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);
spyOn(view, 'render').andCallThrough(); spyOn(view, 'render').andCallThrough();
...@@ -317,7 +319,7 @@ ...@@ -317,7 +319,7 @@
expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated'); expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(9,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
} }
}, converse)); }, converse));
...@@ -325,7 +327,7 @@ ...@@ -325,7 +327,7 @@
var item, view, jid, t; var item, view, jid, t;
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.rosterview, 'render').andCallThrough(); spyOn(this.rosterview, 'render').andCallThrough();
for (i=12; i<15; 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);
spyOn(view, 'render').andCallThrough(); spyOn(view, 'render').andCallThrough();
...@@ -336,13 +338,39 @@ ...@@ -336,13 +338,39 @@
expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated'); expect(converse.emit).toHaveBeenCalledWith('onRosterViewUpdated');
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
expect(t).toEqual(mock.cur_names.slice(12, i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0, i+1).sort().join(''));
} }
}, 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 () {
var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
var i; var i;
for (i=0; i<3; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid);
view.model.set('chat_status', 'online');
}
for (i=3; i<6; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid);
view.model.set('chat_status', 'dnd');
}
for (i=6; i<9; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid);
view.model.set('chat_status', 'away');
}
for (i=9; i<12; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid);
view.model.set('chat_status', 'xa');
}
for (i=12; i<15; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid);
view.model.set('chat_status', 'unavailable');
}
var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
for (i=0; i<3; i++) { for (i=0; i<3; i++) {
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online'); expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online');
} }
...@@ -404,7 +432,7 @@ ...@@ -404,7 +432,7 @@
// TODO: Testing can be more thorough here, the user is // TODO: Testing can be more thorough here, the user is
// actually not accepted/authorized because of // actually not accepted/authorized because of
// mock_connection. // mock_connection.
var jid = mock.req_names.sort()[0].replace(' ','.').toLowerCase() + '@localhost'; var jid = mock.req_names.sort()[0].replace(/ /g,'.').toLowerCase() + '@localhost';
var view = this.rosterview.get(jid); var view = this.rosterview.get(jid);
spyOn(this.connection.roster, 'authorize'); spyOn(this.connection.roster, 'authorize');
spyOn(view, 'acceptRequest').andCallThrough(); spyOn(view, 'acceptRequest').andCallThrough();
...@@ -467,7 +495,7 @@ ...@@ -467,7 +495,7 @@
// In the next test suite, we need some online contacts, so // In the next test suite, we need some online contacts, so
// we make some online now // we make some online now
for (i=0; i<5; i++) { for (i=0; i<5; i++) {
jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
view.model.set('chat_status', 'online'); view.model.set('chat_status', 'online');
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
it("shows chats that have been minimized", $.proxy(function () { it("shows chats that have been minimized", $.proxy(function () {
var contact_jid, chatview; var contact_jid, chatview;
contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
chatview = converse.chatboxviews.get(contact_jid); chatview = converse.chatboxviews.get(contact_jid);
expect(chatview.model.get('minimized')).toBeFalsy(); expect(chatview.model.get('minimized')).toBeFalsy();
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
expect(this.minimized_chats.keys().length).toBe(1); expect(this.minimized_chats.keys().length).toBe(1);
expect(this.minimized_chats.keys()[0]).toBe(contact_jid); expect(this.minimized_chats.keys()[0]).toBe(contact_jid);
contact_jid = mock.cur_names[1].replace(' ','.').toLowerCase() + '@localhost'; contact_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
chatview = converse.chatboxviews.get(contact_jid); chatview = converse.chatboxviews.get(contact_jid);
expect(chatview.model.get('minimized')).toBeFalsy(); expect(chatview.model.get('minimized')).toBeFalsy();
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
}, converse)); }, converse));
it("can be toggled to hide or show minimized chats", $.proxy(function () { it("can be toggled to hide or show minimized chats", $.proxy(function () {
var contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
var chatview = converse.chatboxviews.get(contact_jid); var chatview = converse.chatboxviews.get(contact_jid);
expect(this.minimized_chats.$el.is(':visible')).toBeFalsy(); expect(this.minimized_chats.$el.is(':visible')).toBeFalsy();
...@@ -65,11 +65,11 @@ ...@@ -65,11 +65,11 @@
it("shows the number messages received to minimized chats", $.proxy(function () { it("shows the number messages received to minimized chats", $.proxy(function () {
var i, contact_jid, chatview, msg; var i, contact_jid, chatview, msg;
var sender_jid = mock.cur_names[4].replace(' ','.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[4].replace(/ /g,'.').toLowerCase() + '@localhost';
this.minimized_chats.toggleview.model.set({'collapsed': true}); this.minimized_chats.toggleview.model.set({'collapsed': true});
expect(this.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy(); expect(this.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy();
for (i=0; i<3; i++) { for (i=0; i<3; i++) {
contact_jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost'; contact_jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
chatview = converse.chatboxviews.get(contact_jid); chatview = converse.chatboxviews.get(contact_jid);
chatview.model.set({'minimized': true}); chatview.model.set({'minimized': true});
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
utils.openChatBoxes = function (amount) { utils.openChatBoxes = function (amount) {
var i = 0, jid, views = []; var i = 0, jid, views = [];
for (i; i<amount; i++) { for (i; i<amount; i++) {
jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
views[i] = converse.rosterview.get(jid).openChat(mock.event); views[i] = converse.rosterview.get(jid).openChat(mock.event);
} }
return views; return views;
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
// for the user's roster. // for the user's roster.
for (i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
converse.roster.create({ converse.roster.create({
jid: mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost', jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
subscription: 'both', subscription: 'both',
ask: null, ask: null,
fullname: mock.cur_names[i], fullname: mock.cur_names[i],
......
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