ソースを参照

Add more tests around minimized chats.

JC Brand 11 年 前
コミット
4b8196cd7e
4 ファイル変更94 行追加19 行削除
  1. 4 8
      converse.js
  2. 1 10
      spec/chatbox.js
  3. 87 0
      spec/minchats.js
  4. 2 1
      tests/main.js

+ 4 - 8
converse.js

@@ -2690,11 +2690,7 @@
 
 
             initialize: function () {
             initialize: function () {
                 this.initToggle();
                 this.initToggle();
-                this.model.on("add", function (item) {
-                    if (item.get('minimized')) {
-                        this.addChat(item);
-                    }
-                }, this);
+                this.model.on("add", this.onChanged, this);
                 this.model.on("destroy", this.removeChat, this);
                 this.model.on("destroy", this.removeChat, this);
                 this.model.on("change:minimized", this.onChanged, this);
                 this.model.on("change:minimized", this.onChanged, this);
             },
             },
@@ -2722,14 +2718,14 @@
                 if (ev && ev.preventDefault) {
                 if (ev && ev.preventDefault) {
                     ev.preventDefault();
                     ev.preventDefault();
                 }
                 }
-                this.toggleview.model.save({'collapsed': !this.toggleview.model.get('collapsed')})
+                this.toggleview.model.save({'collapsed': !this.toggleview.model.get('collapsed')});
                 this.$('.minimized-chats-flyout').toggle();
                 this.$('.minimized-chats-flyout').toggle();
             },
             },
 
 
             onChanged: function (item) {
             onChanged: function (item) {
-                if (item.get('minimized')) {
+                if (item.get('id') !== 'controlbox' && item.get('minimized')) {
                     this.addChat(item);
                     this.addChat(item);
-                } else {
+                } else if (this.get(item.get('id'))) {
                     this.removeChat(item);
                     this.removeChat(item);
                 }
                 }
             },
             },

+ 1 - 10
spec/chatbox.js

@@ -13,16 +13,10 @@
                 runs(function () {
                 runs(function () {
                     utils.closeAllChatBoxes();
                     utils.closeAllChatBoxes();
                     utils.removeControlBox();
                     utils.removeControlBox();
-                });
-                waits(250);
-                runs(function () {
                     converse.roster.localStorage._clear();
                     converse.roster.localStorage._clear();
                     utils.initConverse();
                     utils.initConverse();
                     utils.createCurrentContacts();
                     utils.createCurrentContacts();
                     utils.openControlBox();
                     utils.openControlBox();
-                });
-                waits(250);
-                runs(function () {
                     utils.openContactsPanel();
                     utils.openContactsPanel();
                 });
                 });
             });
             });
@@ -462,9 +456,6 @@
                     spyOn(this, 'emit');
                     spyOn(this, 'emit');
                     runs(function () {
                     runs(function () {
                         utils.openChatBoxFor(contact_jid);
                         utils.openChatBoxFor(contact_jid);
-                    });
-                    waits(50);
-                    runs(function () {
                         var chatview = converse.chatboxviews.get(contact_jid);
                         var chatview = converse.chatboxviews.get(contact_jid);
                         expect(chatview.model.get('minimized')).toBeFalsy();
                         expect(chatview.model.get('minimized')).toBeFalsy();
                         chatview.$el.find('.toggle-chatbox-button').click();
                         chatview.$el.find('.toggle-chatbox-button').click();
@@ -521,7 +512,7 @@
                         expect(trimmed_chatboxes.keys().length).toBe(0);
                         expect(trimmed_chatboxes.keys().length).toBe(0);
                     }, converse));
                     }, converse));
                 }, converse));
                 }, converse));
-
+ 
                 it("will indicate when it has a time difference of more than a day between it and its predecessor", $.proxy(function () {
                 it("will indicate when it has a time difference of more than a day between it and its predecessor", $.proxy(function () {
                     spyOn(converse, 'emit');
                     spyOn(converse, 'emit');
                     var contact_name = mock.cur_names[1];
                     var contact_name = mock.cur_names[1];

+ 87 - 0
spec/minchats.js

@@ -0,0 +1,87 @@
+(function (root, factory) {
+    define([
+        "mock",
+        "utils"
+        ], function (mock, utils) {
+            return factory(mock, utils);
+        }
+    );
+} (this, function (mock, utils) {
+    return describe("The Minimized Chats Widget", $.proxy(function(mock, utils) {
+
+        beforeEach(function () {
+            runs(function () {
+                utils.closeAllChatBoxes();
+                utils.removeControlBox();
+                converse.roster.localStorage._clear();
+                utils.initConverse();
+                utils.createCurrentContacts();
+                utils.openControlBox();
+                utils.openContactsPanel();
+                converse.minimized_chats.toggleview.model.localStorage._clear();
+                converse.minimized_chats.initToggle();
+            });
+        });
+
+        it("shows chats that have been minimized",  $.proxy(function () {
+            var contact_jid, chatview;
+            contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
+            utils.openChatBoxFor(contact_jid);
+            chatview = converse.chatboxviews.get(contact_jid);
+            expect(chatview.model.get('minimized')).toBeFalsy();
+            expect(this.minimized_chats.$el.is(':visible')).toBeFalsy();
+            chatview.$el.find('.toggle-chatbox-button').click();
+            expect(chatview.model.get('minimized')).toBeTruthy();
+            expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
+            expect(this.minimized_chats.keys().length).toBe(1);
+            expect(this.minimized_chats.keys()[0]).toBe(contact_jid);
+
+            contact_jid = mock.cur_names[1].replace(' ','.').toLowerCase() + '@localhost';
+            utils.openChatBoxFor(contact_jid);
+            chatview = converse.chatboxviews.get(contact_jid);
+            expect(chatview.model.get('minimized')).toBeFalsy();
+            chatview.$el.find('.toggle-chatbox-button').click();
+            expect(chatview.model.get('minimized')).toBeTruthy();
+            expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
+            expect(this.minimized_chats.keys().length).toBe(2);
+            expect(_.contains(this.minimized_chats.keys(), contact_jid)).toBeTruthy();
+        }, converse));
+
+        it("can be toggled to hide or show minimized chats",  $.proxy(function () {
+            var contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
+            utils.openChatBoxFor(contact_jid);
+            var chatview = converse.chatboxviews.get(contact_jid);
+            expect(this.minimized_chats.$el.is(':visible')).toBeFalsy();
+            chatview.model.set({'minimized': true});
+            expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
+            expect(this.minimized_chats.keys().length).toBe(1);
+            expect(this.minimized_chats.keys()[0]).toBe(contact_jid);
+            expect(this.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeTruthy();
+            expect(this.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
+            this.minimized_chats.$('#toggle-minimized-chats').click();
+            expect(this.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeFalsy();
+            expect(this.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
+        }, converse));
+
+        it("shows the number messages received to minimized chats",  $.proxy(function () {
+            var i, contact_jid, chatview, msg;
+            var sender_jid = mock.cur_names[4].replace(' ','.').toLowerCase() + '@localhost';
+            this.minimized_chats.toggleview.model.set({'collapsed': true});
+            for (i=0; i<3; i++) {
+                contact_jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
+                utils.openChatBoxFor(contact_jid);
+                chatview = converse.chatboxviews.get(contact_jid);
+                chatview.model.set({'minimized': true});
+                msg = $msg({
+                    from: contact_jid,
+                    to: this.connection.jid,
+                    type: 'chat',
+                    id: (new Date()).getTime()
+                }).c('body').t('This message is sent to a minimized chatbox').up()
+                .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
+                this.chatboxes.onMessage(msg);
+            }
+        }, converse));
+
+    }, converse, mock, utils));
+}));

+ 2 - 1
tests/main.js

@@ -63,7 +63,8 @@ require([
                 "spec/eventemitter",
                 "spec/eventemitter",
                 "spec/controlbox",
                 "spec/controlbox",
                 "spec/chatbox",
                 "spec/chatbox",
-                "spec/chatroom"
+                "spec/chatroom",
+                "spec/minchats"
             ], function () {
             ], function () {
                 // Make sure this callback is only called once.
                 // Make sure this callback is only called once.
                 delete converse.callback;
                 delete converse.callback;