Commit 4937fafe authored by JC Brand's avatar JC Brand

Add tests for new "clear" button.

parent 517e6001
...@@ -209,12 +209,14 @@ ...@@ -209,12 +209,14 @@
'xhr_user_search', 'xhr_user_search',
'xhr_user_search_url' 'xhr_user_search_url'
])); ]));
_.extend( if (settings.visible_toolbar_buttons) {
this.visible_toolbar_buttons, _.extend(
_.pick(settings.visible_toolbar_buttons, [ this.visible_toolbar_buttons,
'emoticons', 'call', 'clear' _.pick(settings.visible_toolbar_buttons, [
] 'emoticons', 'call', 'clear'
)); ]
));
}
$.fx.off = !this.animate; $.fx.off = !this.animate;
// Only allow OTR if we have the capability // Only allow OTR if we have the capability
...@@ -1185,7 +1187,9 @@ ...@@ -1185,7 +1187,9 @@
}, },
clearMessages: function (ev) { clearMessages: function (ev) {
ev.stopPropagation(); if (ev && ev.preventDefault) {
ev.preventDefault();
}
var result = confirm(__("Are you sure you want to clear the messages from this chat box?")); var result = confirm(__("Are you sure you want to clear the messages from this chat box?"));
if (result === true) { if (result === true) {
this.$el.find('.chat-content').empty(); this.$el.find('.chat-content').empty();
...@@ -1332,6 +1336,7 @@ ...@@ -1332,6 +1336,7 @@
} else { } else {
this.model.trigger('hide'); this.model.trigger('hide');
} }
return this;
}, },
saveToggleState: function () { saveToggleState: function () {
......
...@@ -193,16 +193,13 @@ ...@@ -193,16 +193,13 @@
allow_otr: true, allow_otr: true,
auto_list_rooms: false, auto_list_rooms: false,
auto_subscribe: false, auto_subscribe: false,
bosh_service_url: 'http://devbox:5280/http-bind', // Please use this connection manager only for testing purposes bosh_service_url: 'https://bind.conversejs.org', // Please use this connection manager only for testing purposes
debug: true , debug: true ,
hide_muc_server: false, hide_muc_server: false,
i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported
prebind: false, prebind: false,
show_controlbox_by_default: true, show_controlbox_by_default: true,
xhr_user_search: false, xhr_user_search: false,
visible_toolbar_buttons: {
'clear': false
}
}); });
}); });
</script> </script>
......
...@@ -186,7 +186,6 @@ ...@@ -186,7 +186,6 @@
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(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
var chatbox = this.chatboxes.get(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');
var $textarea = view.$el.find('textarea.chat-textarea'); var $textarea = view.$el.find('textarea.chat-textarea');
...@@ -246,7 +245,6 @@ ...@@ -246,7 +245,6 @@
// 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(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
var chatbox = this.chatboxes.get(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');
expect($toolbar.children('li.toggle-otr').length).toBe(1); expect($toolbar.children('li.toggle-otr').length).toBe(1);
...@@ -267,23 +265,58 @@ ...@@ -267,23 +265,58 @@
}, converse)); }, converse));
it("contains a button for starting a call", $.proxy(function () { it("can contain a button for starting a call", $.proxy(function () {
spyOn(converse, 'emit'); var view, callButton, $toolbar;
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost';
spyOn(converse, 'emit');
// First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons"
converse.visible_toolbar_buttons['call'] = false;
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
var chatbox = this.chatboxes.get(contact_jid); view = this.chatboxviews.get(contact_jid);
var view = this.chatboxviews.get(contact_jid); $toolbar = view.$el.find('ul.chat-toolbar');
var $toolbar = view.$el.find('ul.chat-toolbar'); callButton = $toolbar.find('.toggle-call');
var callButton = $toolbar.find('.toggle-call'); expect(callButton.length).toBe(0);
view.closeChat();
// Now check that it's shown if enabled and that it emits
// onCallButtonClicked
converse.visible_toolbar_buttons['call'] = true; // enable the button
utils.openChatBoxFor(contact_jid);
view = this.chatboxviews.get(contact_jid);
$toolbar = view.$el.find('ul.chat-toolbar');
callButton = $toolbar.find('.toggle-call');
expect(callButton.length).toBe(1); expect(callButton.length).toBe(1);
callButton.click();
expect(converse.emit).toHaveBeenCalledWith('onCallButtonClicked', jasmine.any(Object));
}, converse));
runs(function () { it("can contain a button for clearing messages", $.proxy(function () {
callButton.click(); var view, clearButton, $toolbar;
expect(converse.emit).toHaveBeenCalledWith('onCallButtonClicked', jasmine.any(Object)); var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost';
}); // First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons"
converse.visible_toolbar_buttons['clear'] = false;
utils.openChatBoxFor(contact_jid);
view = this.chatboxviews.get(contact_jid);
view = this.chatboxviews.get(contact_jid);
$toolbar = view.$el.find('ul.chat-toolbar');
clearButton = $toolbar.find('.toggle-clear');
expect(clearButton.length).toBe(0);
view.closeChat();
// Now check that it's shown if enabled and that it calls
// clearMessages
converse.visible_toolbar_buttons['clear'] = true; // enable the button
utils.openChatBoxFor(contact_jid);
view = this.chatboxviews.get(contact_jid);
$toolbar = view.$el.find('ul.chat-toolbar');
clearButton = $toolbar.find('.toggle-clear');
expect(clearButton.length).toBe(1);
spyOn(view, 'clearMessages');
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
clearButton.click();
expect(view.clearMessages).toHaveBeenCalled();
}, converse)); }, converse));
}, converse)); }, converse));
describe("A Chat Message", $.proxy(function () { describe("A Chat Message", $.proxy(function () {
...@@ -591,9 +624,15 @@ ...@@ -591,9 +624,15 @@
message = '/clear'; message = '/clear';
var old_length = view.model.messages.length; var old_length = view.model.messages.length;
spyOn(view, 'sendMessage').andCallThrough(); spyOn(view, 'sendMessage').andCallThrough();
spyOn(view, 'clearMessages').andCallThrough();
spyOn(window, 'confirm').andCallFake(function () {
return true;
});
utils.sendMessage(view, message); utils.sendMessage(view, message);
expect(view.sendMessage).toHaveBeenCalled(); expect(view.sendMessage).toHaveBeenCalled();
expect(view.model.messages.length, 0); // The messages must be removed from the modal expect(view.clearMessages).toHaveBeenCalled();
expect(window.confirm).toHaveBeenCalled();
expect(view.model.messages.length, 0); // The messages must be removed from the chatbox
expect(view.model.messages.localStorage.records.length, 0); // And also from localStorage expect(view.model.messages.localStorage.records.length, 0); // And also from localStorage
expect(converse.emit.callCount, 1); expect(converse.emit.callCount, 1);
expect(converse.emit.mostRecentCall.args, ['onMessageSend', message]); expect(converse.emit.mostRecentCall.args, ['onMessageSend', message]);
......
...@@ -44,7 +44,6 @@ require([ ...@@ -44,7 +44,6 @@ require([
xhr_user_search: false, xhr_user_search: false,
auto_subscribe: false, auto_subscribe: false,
animate: false, animate: false,
show_call_button: true,
connection: mock.mock_connection, connection: mock.mock_connection,
testing: true testing: true
}, function (converse) { }, function (converse) {
......
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