Commit be662847 authored by JC Brand's avatar JC Brand

Add a test for /clear functionality

parent cc37d6a1
...@@ -7,6 +7,7 @@ Changelog ...@@ -7,6 +7,7 @@ Changelog
- Add icon for the unavailable chat state. [jcbrand] - Add icon for the unavailable chat state. [jcbrand]
- Chat state descriptions weren't translation aware. [jcbrand] - Chat state descriptions weren't translation aware. [jcbrand]
- Clear messages from localStorage when user types "/clear". [jcbrand] - Clear messages from localStorage when user types "/clear". [jcbrand]
- The 'xa' chat state wasn't being handled properly. [jcbrand]
0.6.3 (2013-09-12) 0.6.3 (2013-09-12)
------------------ ------------------
......
...@@ -580,7 +580,7 @@ ...@@ -580,7 +580,7 @@
var view = this.chatboxesview.views[contact_jid]; var view = this.chatboxesview.views[contact_jid];
var message = 'This message is sent from this chatbox'; var message = 'This message is sent from this chatbox';
spyOn(view, 'sendMessage').andCallThrough(); spyOn(view, 'sendMessage').andCallThrough();
view.$el.find('.chat-textarea').text(message); view.$el.find('.chat-textarea').val(message).text(message);
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13})); view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
expect(view.sendMessage).toHaveBeenCalled(); expect(view.sendMessage).toHaveBeenCalled();
expect(view.model.messages.length, 2); expect(view.model.messages.length, 2);
...@@ -588,8 +588,33 @@ ...@@ -588,8 +588,33 @@
expect(txt).toEqual(message); expect(txt).toEqual(message);
}, converse)); }, converse));
}, converse)); }, converse));
describe("Special Messages", $.proxy(function () {
it("'/clear' can be used to clear messages in a conversation", $.proxy(function () {
var contact_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
var view = this.chatboxesview.views[contact_jid];
var message = 'This message is another sent from this chatbox';
// Lets make sure there is at least one message already
// (e.g for when this test is run on its own).
view.$el.find('.chat-textarea').val(message).text(message);
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
expect(view.model.messages.length > 0).toBeTruthy();
expect(view.model.messages.localStorage.records.length > 0).toBeTruthy();
message = '/clear';
var old_length = view.model.messages.length;
spyOn(view, 'sendMessage').andCallThrough();
view.$el.find('.chat-textarea').val(message).text(message);
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
expect(view.sendMessage).toHaveBeenCalled();
expect(view.model.messages.length, 0); // The messages must be removed from the modal
expect(view.model.messages.localStorage.records.length, 0); // And also from localStorage
}, converse));
}, converse)); }, converse));
}, converse));
describe("A Message Counter", $.proxy(function () { describe("A Message Counter", $.proxy(function () {
beforeEach($.proxy(function () { beforeEach($.proxy(function () {
converse.clearMsgCounter(); converse.clearMsgCounter();
......
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