Browse Source

Add a test and changelog entry for #359

updates #359
JC Brand 10 years ago
parent
commit
5a488333ec
2 changed files with 28 additions and 2 deletions
  1. 1 0
      docs/CHANGES.rst
  2. 27 2
      spec/chatbox.js

+ 1 - 0
docs/CHANGES.rst

@@ -10,6 +10,7 @@ Changelog
 * #356 Fix the plugin extend function. [floriancargoet]
 * #356 Fix the plugin extend function. [floriancargoet]
 * #357 Fix the known bug where a state notification reopens a chat box. [floriancargoet]
 * #357 Fix the known bug where a state notification reopens a chat box. [floriancargoet]
 * #358 Bugfix. Chat rooms show the same occupants bug. [floriancargoet]
 * #358 Bugfix. Chat rooms show the same occupants bug. [floriancargoet]
+* #359 Fix a timeout bug in chat state notifications. [floriancargoet]
 
 
 0.9.1 (2015-03-26)
 0.9.1 (2015-03-26)
 ------------------
 ------------------

+ 27 - 2
spec/chatbox.js

@@ -781,6 +781,8 @@
                         var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
                         var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
                         test_utils.openChatBoxFor(contact_jid);
                         test_utils.openChatBoxFor(contact_jid);
                         var view = this.chatboxviews.get(contact_jid);
                         var view = this.chatboxviews.get(contact_jid);
+                        spyOn(converse.connection, 'send');
+                        spyOn(view, 'setChatState').andCallThrough();
                         runs(function () {
                         runs(function () {
                             expect(view.model.get('chat_state')).toBe('active');
                             expect(view.model.get('chat_state')).toBe('active');
                             view.keyPressed({
                             view.keyPressed({
@@ -788,16 +790,39 @@
                                 keyCode: 1
                                 keyCode: 1
                             });
                             });
                             expect(view.model.get('chat_state')).toBe('composing');
                             expect(view.model.get('chat_state')).toBe('composing');
-                            spyOn(converse.connection, 'send');
+                            expect(converse.connection.send).toHaveBeenCalled();
+                            var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
+                            expect($stanza.children().prop('tagName')).toBe('composing');
                         });
                         });
                         waits(250);
                         waits(250);
                         runs(function () {
                         runs(function () {
                             expect(view.model.get('chat_state')).toBe('paused');
                             expect(view.model.get('chat_state')).toBe('paused');
                             expect(converse.connection.send).toHaveBeenCalled();
                             expect(converse.connection.send).toHaveBeenCalled();
-                            var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
+                            var $stanza = $(converse.connection.send.argsForCall[1][0].tree());
                             expect($stanza.attr('to')).toBe(contact_jid);
                             expect($stanza.attr('to')).toBe(contact_jid);
                             expect($stanza.children().length).toBe(1);
                             expect($stanza.children().length).toBe(1);
                             expect($stanza.children().prop('tagName')).toBe('paused');
                             expect($stanza.children().prop('tagName')).toBe('paused');
+                            // Test #359. A paused notification should not be sent
+                            // out if the user simply types longer than the
+                            // timeout.
+                            view.keyPressed({
+                                target: view.$el.find('textarea.chat-textarea'),
+                                keyCode: 1
+                            });
+                            expect(view.setChatState).toHaveBeenCalled();
+                            expect(view.model.get('chat_state')).toBe('composing');
+                        });
+                        waits(100);
+                        runs(function () {
+                            view.keyPressed({
+                                target: view.$el.find('textarea.chat-textarea'),
+                                keyCode: 1
+                            });
+                            expect(view.model.get('chat_state')).toBe('composing');
+                        });
+                        waits(150);
+                        runs(function () {
+                            expect(view.model.get('chat_state')).toBe('composing');
                         });
                         });
                     }, converse));
                     }, converse));