Work on getting proper separation between tests.

This commit is contained in:
JC Brand 2014-06-30 20:26:45 +02:00
parent 718f75a464
commit 5034ae33f2
5 changed files with 80 additions and 45 deletions

View File

@ -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 @@
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();

View File

@ -32,7 +32,7 @@
var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact').find('a.open-chat'); var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact').find('a.open-chat');
for (i=0; i<online_contacts.length; i++) { for (i=0; i<online_contacts.length; i++) {
$el = $(online_contacts[i]); $el = $(online_contacts[i]);
jid = $el.text().replace(' ','.').toLowerCase() + '@localhost'; jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
spyOn(view, 'openChat').andCallThrough(); spyOn(view, 'openChat').andCallThrough();
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
@ -63,7 +63,7 @@
var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact').find('a.open-chat'); var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact').find('a.open-chat');
for (i=0; i<online_contacts.length; i++) { for (i=0; i<online_contacts.length; i++) {
$el = $(online_contacts[i]); $el = $(online_contacts[i]);
jid = $el.text().replace(' ','.').toLowerCase() + '@localhost'; jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
$el.click(); $el.click();
expect(this.chatboxviews.trimChats).toHaveBeenCalled(); expect(this.chatboxviews.trimChats).toHaveBeenCalled();
@ -96,7 +96,7 @@
}, converse)); }, converse));
it("is focused if its already open and you click on its corresponding roster item", $.proxy(function () { it("is focused if its already open and you click on its corresponding roster item", $.proxy(function () {
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
var i, $el, click, jid, view, chatboxview, chatbox; var i, $el, click, jid, view, chatboxview, chatbox;
// openControlBox was called earlier, so the controlbox is // openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created. // visible, but no other chat boxes have been created.
@ -105,7 +105,7 @@
chatboxview = this.chatboxviews.get(contact_jid); chatboxview = this.chatboxviews.get(contact_jid);
spyOn(chatboxview, 'focus'); spyOn(chatboxview, 'focus');
$el = this.rosterview.$el.find('a.open-chat:contains("'+chatbox.get('fullname')+'")'); $el = this.rosterview.$el.find('a.open-chat:contains("'+chatbox.get('fullname')+'")');
jid = $el.text().replace(' ','.').toLowerCase() + '@localhost'; jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid); view = this.rosterview.get(jid);
spyOn(view, 'openChat').andCallThrough(); spyOn(view, 'openChat').andCallThrough();
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
@ -246,7 +246,7 @@
describe("A chat toolbar", $.proxy(function () { describe("A chat toolbar", $.proxy(function () {
it("can be found on each chat box", $.proxy(function () { it("can be found on each chat box", $.proxy(function () {
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
var chatbox = this.chatboxes.get(contact_jid); var chatbox = this.chatboxes.get(contact_jid);
var view = this.chatboxviews.get(contact_jid); var view = this.chatboxviews.get(contact_jid);
@ -258,7 +258,7 @@
}, converse)); }, converse));
it("contains a button for inserting emoticons", $.proxy(function () { it("contains a button for inserting emoticons", $.proxy(function () {
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
var view = this.chatboxviews.get(contact_jid); var view = this.chatboxviews.get(contact_jid);
var $toolbar = view.$el.find('ul.chat-toolbar'); var $toolbar = view.$el.find('ul.chat-toolbar');
@ -317,7 +317,7 @@
it("contains a button for starting an encrypted chat session", $.proxy(function () { it("contains a button for starting an encrypted chat session", $.proxy(function () {
// TODO: More tests can be added here... // TODO: More tests can be added here...
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
var view = this.chatboxviews.get(contact_jid); var view = this.chatboxviews.get(contact_jid);
var $toolbar = view.$el.find('ul.chat-toolbar'); var $toolbar = view.$el.find('ul.chat-toolbar');
@ -341,7 +341,7 @@
it("can contain a button for starting a call", $.proxy(function () { it("can contain a button for starting a call", $.proxy(function () {
var view, callButton, $toolbar; var view, callButton, $toolbar;
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
spyOn(converse, 'emit'); spyOn(converse, 'emit');
// First check that the button doesn't show if it's not enabled // First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons" // via "visible_toolbar_buttons"
@ -366,7 +366,7 @@
it("can contain a button for clearing messages", $.proxy(function () { it("can contain a button for clearing messages", $.proxy(function () {
var view, clearButton, $toolbar; var view, clearButton, $toolbar;
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
// First check that the button doesn't show if it's not enabled // First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons" // via "visible_toolbar_buttons"
converse.visible_toolbar_buttons.clear = false; converse.visible_toolbar_buttons.clear = false;
@ -406,7 +406,7 @@
it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () { it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var message = 'This is a received message'; var message = 'This is a received message';
var sender_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
msg = $msg({ msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
@ -452,7 +452,7 @@
it("received for a minimized chat box will increment a counter on its header", $.proxy(function () { it("received for a minimized chat box will increment a counter on its header", $.proxy(function () {
var contact_name = mock.cur_names[0]; var contact_name = mock.cur_names[0];
var contact_jid = contact_name.replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
spyOn(this, 'emit'); spyOn(this, 'emit');
runs(function () { runs(function () {
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
@ -465,7 +465,7 @@
var chatview = this.chatboxviews.get(contact_jid); var chatview = this.chatboxviews.get(contact_jid);
expect(chatview.model.get('minimized')).toBeTruthy(); expect(chatview.model.get('minimized')).toBeTruthy();
var message = 'This message is sent to a minimized chatbox'; var message = 'This message is sent to a minimized chatbox';
var sender_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
msg = $msg({ msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
@ -486,7 +486,7 @@
expect($count.html()).toBe('1'); expect($count.html()).toBe('1');
this.chatboxes.onMessage( this.chatboxes.onMessage(
$msg({ $msg({
from: mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost', from: mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
to: this.connection.jid, to: this.connection.jid,
type: 'chat', type: 'chat',
id: (new Date()).getTime() id: (new Date()).getTime()
@ -514,7 +514,7 @@
it("will indicate when it has a time difference of more than a day between it and its predecessor", $.proxy(function () { it("will indicate when it has a time difference of more than a day between it and its predecessor", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var contact_name = mock.cur_names[1]; var contact_name = mock.cur_names[1];
var contact_jid = contact_name.replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
utils.clearChatBoxMessages(contact_jid); utils.clearChatBoxMessages(contact_jid);
var one_day_ago = moment(); var one_day_ago = moment();
@ -582,7 +582,7 @@
it("can be sent from a chatbox, and will appear inside it", $.proxy(function () { it("can be sent from a chatbox, and will appear inside it", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
runs(function () { runs(function () {
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
}); });
@ -601,7 +601,7 @@
}, converse)); }, converse));
it("is sanitized to prevent Javascript injection attacks", $.proxy(function () { it("is sanitized to prevent Javascript injection attacks", $.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 view = this.chatboxviews.get(contact_jid); var view = this.chatboxviews.get(contact_jid);
var message = '<p>This message contains <em>some</em> <b>markup</b></p>'; var message = '<p>This message contains <em>some</em> <b>markup</b></p>';
@ -614,7 +614,7 @@
}, converse)); }, converse));
it("can contain hyperlinks, which will be clickable", $.proxy(function () { it("can contain hyperlinks, which will be clickable", $.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 view = this.chatboxviews.get(contact_jid); var view = this.chatboxviews.get(contact_jid);
var message = 'This message contains a hyperlink: www.opkode.com'; var message = 'This message contains a hyperlink: www.opkode.com';
@ -627,7 +627,7 @@
}, converse)); }, converse));
it("should display emoticons correctly", $.proxy(function () { it("should display emoticons correctly", $.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 view = this.chatboxviews.get(contact_jid); var view = this.chatboxviews.get(contact_jid);
var messages = [':)', ';)', ':D', ':P', '8)', '>:)', ':S', ':\\', '>:(', ':(', ':O', '(^.^)b', '<3']; var messages = [':)', ';)', ':D', ':P', '8)', '>:)', ':S', ':\\', '>:(', ':(', ':O', '(^.^)b', '<3'];
@ -651,7 +651,7 @@
}, converse)); }, converse));
it("will have properly escaped URLs", $.proxy(function () { it("will have properly escaped URLs", $.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 view = this.chatboxviews.get(contact_jid); var view = this.chatboxviews.get(contact_jid);
spyOn(view, 'sendMessage').andCallThrough(); spyOn(view, 'sendMessage').andCallThrough();
@ -741,7 +741,7 @@
spyOn(converse, 'incrementMsgCounter').andCallThrough(); spyOn(converse, 'incrementMsgCounter').andCallThrough();
$(window).trigger('blur'); $(window).trigger('blur');
var message = 'This message will increment the message counter'; var message = 'This message will increment the message counter';
var sender_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
msg = $msg({ msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,
@ -772,7 +772,7 @@
spyOn(converse, 'incrementMsgCounter').andCallThrough(); spyOn(converse, 'incrementMsgCounter').andCallThrough();
$(window).trigger('focus'); $(window).trigger('focus');
var message = 'This message will not increment the message counter'; var message = 'This message will not increment the message counter';
var sender_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
msg = $msg({ msg = $msg({
from: sender_jid, from: sender_jid,
to: this.connection.jid, to: this.connection.jid,

View File

@ -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 @@
}, 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
// 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');
} }

View File

@ -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 @@
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 @@
}, 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 @@
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});

View File

@ -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 @@
// 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],