Procházet zdrojové kódy

Add new test for trimmed chats

JC Brand před 11 roky
rodič
revize
c594e5a1e9
2 změnil soubory, kde provedl 46 přidání a 10 odebrání
  1. 14 10
      converse.js
  2. 32 0
      spec/chatbox.js

+ 14 - 10
converse.js

@@ -2666,15 +2666,7 @@
 
             initialize: function () {
                 this.model.on("change:trimmed", function (item) {
-                    var view;
-                    if (item.get('trimmed')) {
-                        view = new converse.TrimmedChatBoxView({model: item});
-                        this.$('.box-flyout').append(view.render());
-                        this.add(item.get('id'), view);
-                    } else {
-                        view = this.get(item.get('id'));
-                        view.restore();
-                    }
+                    this.onChanged(item);
                 }, this);
             },
 
@@ -2682,7 +2674,7 @@
                 return this.$el;
             },
 
-            _ensureElement: function() {
+            _ensureElement: function () {
                 /* Override method from backbone.js
                 * Make sure that the el and $el attributes point to a DOM snippet
                 * from src/templates/trimmed_chats.html
@@ -2694,6 +2686,18 @@
                     this.setElement(_.result(this, 'el'), false);
                 }
             },
+
+            onChanged: function (item) {
+                var view;
+                if (item.get('trimmed')) {
+                    view = new converse.TrimmedChatBoxView({model: item});
+                    this.$('.box-flyout').append(view.render());
+                    this.add(item.get('id'), view);
+                } else {
+                    view = this.get(item.get('id'));
+                    view.restore();
+                }
+            }
         });
 
         this.RosterItem = Backbone.Model.extend({

+ 32 - 0
spec/chatbox.js

@@ -56,6 +56,38 @@
                 }
             }, converse));
 
+            it("can be trimmed to conserve space", $.proxy(function () {
+                var i, $el, click, jid, view, chatboxview;
+                // openControlBox was called earlier, so the controlbox is
+                // visible, but no other chat boxes have been created.
+                var trimmed_chatboxes = converse.chatboxviews.trimmed_chatboxes_view;
+                expect(this.chatboxes.length).toEqual(1);
+                spyOn(this.chatboxviews, 'trimChats');
+                spyOn(trimmed_chatboxes, 'onChanged').andCallThrough();
+
+                expect($("#conversejs .chatbox").length).toBe(1); // Controlbox is open
+
+                var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact').find('a.open-chat');
+                for (i=0; i<online_contacts.length; i++) {
+                    $el = $(online_contacts[i]);
+                    jid = $el.text().replace(' ','.').toLowerCase() + '@localhost';
+                    view = this.rosterview.get(jid);
+                    view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
+                    $el.click();
+                    expect(this.chatboxviews.trimChats).toHaveBeenCalled();
+
+                    chatboxview = this.chatboxviews.get(jid);
+                    spyOn(chatboxview, 'trim').andCallThrough();
+                    chatboxview.model.set({'trimmed': true});
+
+                    expect(trimmed_chatboxes.onChanged).toHaveBeenCalled();
+                    expect(chatboxview.trim).toHaveBeenCalled();
+
+                    trimmedview = trimmed_chatboxes.get(jid);
+                    expect(trimmedview.$el.is(":visible")).toBeTruthy();
+                }
+            }, converse));
+
             it("is focused if its already open and you click on its corresponding roster item", $.proxy(function () {
                 var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost';
                 var i, $el, click, jid, view, chatboxview, chatbox;