From b84d4519a9f3615d59b6169a3d67f7f939804478 Mon Sep 17 00:00:00 2001 From: witek Date: Wed, 8 May 2013 17:42:19 +0200 Subject: [PATCH] add tests for message counter functionality --- spec/MainSpec.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/spec/MainSpec.js b/spec/MainSpec.js index 62604547c..9d2d05f01 100644 --- a/spec/MainSpec.js +++ b/spec/MainSpec.js @@ -551,6 +551,50 @@ }, converse)); }, converse)); + describe("A Message Counter", $.proxy(function () { + it("is incremented when the message is received and the window is not focused", $.proxy(function () { + expect(this.msg_counter).toBe(0); + spyOn(converse, 'incrementMsgCounter').andCallThrough(); + $(window).trigger('blur'); + var message = 'This message will increment the message counter'; + var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; + msg = $msg({ + from: sender_jid, + to: this.connection.jid, + type: 'chat', + id: (new Date()).getTime() + }).c('body').t(message).up() + .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); + this.chatboxes.messageReceived(msg); + expect(converse.incrementMsgCounter).toHaveBeenCalled(); + expect(this.msg_counter).toBe(1); + }, converse)); + + it("is cleared when the window is focused", $.proxy(function () { + spyOn(converse, 'clearMsgCounter').andCallThrough(); + $(window).trigger('focus'); + expect(converse.clearMsgCounter).toHaveBeenCalled(); + }, converse)); + + it("is not incremented when the message is received and the window is focused", $.proxy(function () { + expect(this.msg_counter).toBe(0); + spyOn(converse, 'incrementMsgCounter').andCallThrough(); + $(window).trigger('focus'); + var message = 'This message will not increment the message counter'; + var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; + msg = $msg({ + from: sender_jid, + to: this.connection.jid, + type: 'chat', + id: (new Date()).getTime() + }).c('body').t(message).up() + .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); + this.chatboxes.messageReceived(msg); + expect(converse.incrementMsgCounter).not.toHaveBeenCalled(); + expect(this.msg_counter).toBe(0); + }, converse)); + }, converse)); + xdescribe("The Controlbox Tabs", $.proxy(function () { // XXX: Disabled for now, these tests don't pass due to service // discovery changes.