Selaa lähdekoodia

Work to make the individual tests independent

JC Brand 12 vuotta sitten
vanhempi
commit
d568d90a3a
1 muutettua tiedostoa jossa 30 lisäystä ja 10 poistoa
  1. 30 10
      spec/MainSpec.js

+ 30 - 10
spec/MainSpec.js

@@ -23,6 +23,21 @@
         var num_contacts = req_names.length + pend_names.length + cur_names.length;
         var num_contacts = req_names.length + pend_names.length + cur_names.length;
         var open_controlbox;
         var open_controlbox;
 
 
+        closeAllChatBoxes = function () {
+            var i, chatbox, num_chatboxes = converse.chatboxes.models.length;
+            for (i=num_chatboxes-1; i>-1; i--) {
+                chatbox = converse.chatboxes.models[i];
+                converse.chatboxesview.views[chatbox.get('id')].closeChat();
+            }
+        };
+
+        openControlBox = function () {
+            // Make sure the controlbox is open
+            if (!$("div#controlbox").is(':visible')) {
+                $('.toggle-online-users').click();
+            }
+        };
+
         describe("The Control Box", $.proxy(function () {
         describe("The Control Box", $.proxy(function () {
             it("is not shown by default", $.proxy(function () {
             it("is not shown by default", $.proxy(function () {
                 expect(this.rosterview.$el.is(':visible')).toEqual(false);
                 expect(this.rosterview.$el.is(':visible')).toEqual(false);
@@ -93,6 +108,12 @@
 
 
         describe("The Contacts Roster", $.proxy(function () {
         describe("The Contacts Roster", $.proxy(function () {
             describe("Pending Contacts", $.proxy(function () {
             describe("Pending Contacts", $.proxy(function () {
+                beforeEach(function () {
+                    if (!$("div#controlbox").is(':visible')) {
+                        $('.toggle-online-users').click();
+                    }
+                });
+
                 it("do not have a heading if there aren't any", $.proxy(function () {
                 it("do not have a heading if there aren't any", $.proxy(function () {
                     expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
                     expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
                 }, converse));
                 }, converse));
@@ -560,14 +581,8 @@
 
 
         describe("The Controlbox Tabs", $.proxy(function () {
         describe("The Controlbox Tabs", $.proxy(function () {
             beforeEach($.proxy(function () {
             beforeEach($.proxy(function () {
-                // Close any remaining open chatboxes
-                var i, chatbox, num_chatboxes = this.chatboxes.models.length;
-                for (i=0; i<num_chatboxes; i++) {
-                    chatbox = this.chatboxes.models[i];
-                    if (chatbox.get('id') != 'controlbox') {
-                        this.chatboxesview.views[chatbox.get('id')].closeChat();
-                    }
-                }
+                closeAllChatBoxes();
+                openControlBox();
             }, converse));
             }, converse));
 
 
             it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
             it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
@@ -581,6 +596,11 @@
             }, converse));
             }, converse));
 
 
             describe("The Chatrooms Panel", $.proxy(function () {
             describe("The Chatrooms Panel", $.proxy(function () {
+                beforeEach($.proxy(function () {
+                    closeAllChatBoxes();
+                    openControlBox();
+                }, converse));
+
                 it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {
                 it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {
                     var cbview = this.chatboxesview.views.controlbox;
                     var cbview = this.chatboxesview.views.controlbox;
                     var $tabs = cbview.$el.find('#controlbox-tabs');
                     var $tabs = cbview.$el.find('#controlbox-tabs');
@@ -606,7 +626,7 @@
                     var $server = roomspanel.$el.find('input.new-chatroom-server');
                     var $server = roomspanel.$el.find('input.new-chatroom-server');
                     expect($input.length).toBe(1);
                     expect($input.length).toBe(1);
                     expect($server.length).toBe(1);
                     expect($server.length).toBe(1);
-                    expect($('.chatroom').length).toBe(0); // There shouldn't be any chatrooms open currently
+                    expect($('.chatroom:visible').length).toBe(0); // There shouldn't be any chatrooms open currently
                     spyOn(roomspanel, 'createChatRoom').andCallThrough();
                     spyOn(roomspanel, 'createChatRoom').andCallThrough();
                     roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
                     roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
                     runs(function () {
                     runs(function () {
@@ -620,7 +640,7 @@
                     });
                     });
                     waits('250');
                     waits('250');
                     runs($.proxy(function () {
                     runs($.proxy(function () {
-                        expect($('.chatroom').length).toBe(1); // There should now be an open chatroom
+                        expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
                     }, converse));
                     }, converse));
                 }, converse));
                 }, converse));
             }, converse));
             }, converse));