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

Add tests for new "clear" button.

parent 517e6001
......@@ -209,12 +209,14 @@
'xhr_user_search',
'xhr_user_search_url'
]));
if (settings.visible_toolbar_buttons) {
_.extend(
this.visible_toolbar_buttons,
_.pick(settings.visible_toolbar_buttons, [
'emoticons', 'call', 'clear'
]
));
}
$.fx.off = !this.animate;
// Only allow OTR if we have the capability
......@@ -1185,7 +1187,9 @@
},
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?"));
if (result === true) {
this.$el.find('.chat-content').empty();
......@@ -1332,6 +1336,7 @@
} else {
this.model.trigger('hide');
}
return this;
},
saveToggleState: function () {
......
......@@ -193,16 +193,13 @@
allow_otr: true,
auto_list_rooms: 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 ,
hide_muc_server: false,
i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported
prebind: false,
show_controlbox_by_default: true,
xhr_user_search: false,
visible_toolbar_buttons: {
'clear': false
}
});
});
</script>
......
......@@ -186,7 +186,6 @@
it("contains a button for inserting emoticons", $.proxy(function () {
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid);
var chatbox = this.chatboxes.get(contact_jid);
var view = this.chatboxviews.get(contact_jid);
var $toolbar = view.$el.find('ul.chat-toolbar');
var $textarea = view.$el.find('textarea.chat-textarea');
......@@ -246,7 +245,6 @@
// TODO: More tests can be added here...
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid);
var chatbox = this.chatboxes.get(contact_jid);
var view = this.chatboxviews.get(contact_jid);
var $toolbar = view.$el.find('ul.chat-toolbar');
expect($toolbar.children('li.toggle-otr').length).toBe(1);
......@@ -267,23 +265,58 @@
}, converse));
it("contains a button for starting a call", $.proxy(function () {
spyOn(converse, 'emit');
it("can contain a button for starting a call", $.proxy(function () {
var view, callButton, $toolbar;
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);
var chatbox = this.chatboxes.get(contact_jid);
var view = this.chatboxviews.get(contact_jid);
var $toolbar = view.$el.find('ul.chat-toolbar');
var callButton = $toolbar.find('.toggle-call');
view = this.chatboxviews.get(contact_jid);
$toolbar = view.$el.find('ul.chat-toolbar');
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);
runs(function () {
callButton.click();
expect(converse.emit).toHaveBeenCalledWith('onCallButtonClicked', jasmine.any(Object));
});
}, converse));
it("can contain a button for clearing messages", $.proxy(function () {
var view, clearButton, $toolbar;
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));
describe("A Chat Message", $.proxy(function () {
......@@ -591,9 +624,15 @@
message = '/clear';
var old_length = view.model.messages.length;
spyOn(view, 'sendMessage').andCallThrough();
spyOn(view, 'clearMessages').andCallThrough();
spyOn(window, 'confirm').andCallFake(function () {
return true;
});
utils.sendMessage(view, message);
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(converse.emit.callCount, 1);
expect(converse.emit.mostRecentCall.args, ['onMessageSend', message]);
......
......@@ -44,7 +44,6 @@ require([
xhr_user_search: false,
auto_subscribe: false,
animate: false,
show_call_button: true,
connection: mock.mock_connection,
testing: true
}, 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