Browse Source

Fix failing tests

JC Brand 7 years ago
parent
commit
2f46bb8ce7
6 changed files with 51 additions and 53 deletions
  1. 24 25
      spec/chatbox.js
  2. 18 19
      spec/converse.js
  3. 6 7
      spec/roomslist.js
  4. 1 0
      src/converse-chatview.js
  5. 1 1
      src/converse-roomslist.js
  6. 1 1
      src/templates/rooms_list_item.html

+ 24 - 25
spec/chatbox.js

@@ -350,8 +350,8 @@
                         return $(chatview.el).find('.chat-body').is(':visible');
                     }, 500);
                 }).then(function () {
-                    expect($(chatview.el).find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy();
-                    expect($(chatview.el).find('.toggle-chatbox-button').hasClass('icon-plus')).toBeFalsy();
+                    expect($(chatview.el).find('.toggle-chatbox-button').hasClass('fa-minus')).toBeTruthy();
+                    expect($(chatview.el).find('.toggle-chatbox-button').hasClass('fa-plus')).toBeFalsy();
                     expect(chatview.model.get('minimized')).toBeFalsy();
                     done();
                 });
@@ -678,11 +678,11 @@
                             var chatboxview = _converse.chatboxviews.get(sender_jid);
                             expect(chatbox).toBeDefined();
                             expect(chatboxview).toBeDefined();
-                            // XXX: I don't really like the convention of
-                            // setting "fullname" to the JID if there's
-                            // no fullname. Should ideally be null if
-                            // there's no fullname.
+
+                            var author_el = chatboxview.el.querySelector('.chat-msg-author');
                             expect(chatbox.get('fullname') === sender_jid);
+                            expect( _.includes(author_el.textContent, 'max.frankfurter@localhost')).toBeTruthy();
+
                             test_utils.waitUntil(function () { return vcard_fetched; }, 100)
                             .then(function () {
                                 expect(_converse.api.vcard.get).toHaveBeenCalled();
@@ -718,13 +718,13 @@
                             // We don't already have an open chatbox for this user
                             expect(_converse.chatboxes.get(sender_jid)).not.toBeDefined();
 
+                            var chatbox = _converse.chatboxes.get(sender_jid);
+                            expect(chatbox).not.toBeDefined();
+
                             // onMessage is a handler for received XMPP messages
                             _converse.chatboxes.onMessage(msg);
                             expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
 
-                            var chatbox = _converse.chatboxes.get(sender_jid);
-                            expect(chatbox).not.toBeDefined();
-
                             // onMessage is a handler for received XMPP messages
                             _converse.allow_non_roster_messaging =true;
                             _converse.chatboxes.onMessage(msg);
@@ -744,7 +744,7 @@
                             expect(msg_obj.get('delayed')).toEqual(false);
                             // Now check that the message appears inside the chatbox in the DOM
                             var $chat_content = $(chatboxview.el).find('.chat-content');
-                            var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
+                            var msg_txt = $chat_content.find('.chat-message .chat-msg-content').text();
                             expect(msg_txt).toEqual(message);
                             var sender_txt = $chat_content.find('span.chat-msg-them').text();
                             expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
@@ -1331,10 +1331,9 @@
                 }));
 
                 it("received for a minimized chat box will increment a counter on its header",
-
-                mock.initConverseWithPromises(
-                    null, ['rosterGroupsFetched'], {},
-                    function (done, _converse) {
+                    mock.initConverseWithPromises(
+                        null, ['rosterGroupsFetched'], {},
+                        function (done, _converse) {
 
                     test_utils.createContacts(_converse, 'current');
                     test_utils.openControlBox();
@@ -1439,7 +1438,7 @@
 
                         var $time = $chat_content.find('time');
                         expect($time.length).toEqual(1);
-                        expect($time.attr('class')).toEqual('message chat-info chat-date');
+                        expect($time.attr('class')).toEqual('message chat-info chat-date badge badge-info');
                         expect($time.data('isodate')).toEqual(moment(one_day_ago.startOf('day')).format());
                         expect($time.text()).toEqual(moment(one_day_ago.startOf('day')).format("dddd MMM Do YYYY"));
 
@@ -1459,7 +1458,7 @@
                         expect($time.length).toEqual(2); // There are now two time elements
                         $time = $chat_content.find('time:last'); // We check the last one
                         var message_date = new Date();
-                        expect($time.attr('class')).toEqual('message chat-info chat-date');
+                        expect($time.attr('class')).toEqual('message chat-info chat-date badge badge-info');
                         expect($time.data('isodate')).toEqual(moment(message_date).startOf('day').format());
                         expect($time.text()).toEqual(moment(message_date).startOf('day').format("dddd MMM Do YYYY"));
 
@@ -1502,9 +1501,9 @@
                 }));
 
                 it("is sanitized to prevent Javascript injection attacks",
-                mock.initConverseWithPromises(
-                    null, ['rosterGroupsFetched'], {},
-                    function (done, _converse) {
+                    mock.initConverseWithPromises(
+                        null, ['rosterGroupsFetched'], {},
+                        function (done, _converse) {
 
                     test_utils.createContacts(_converse, 'current');
                     test_utils.openControlBox();
@@ -1544,9 +1543,9 @@
                 }));
 
                 it("will have properly escaped URLs",
-                mock.initConverseWithPromises(
-                    null, ['rosterGroupsFetched'], {},
-                    function (done, _converse) {
+                    mock.initConverseWithPromises(
+                        null, ['rosterGroupsFetched'], {},
+                        function (done, _converse) {
 
                     test_utils.createContacts(_converse, 'current');
                     test_utils.openControlBox();
@@ -1644,9 +1643,9 @@
                 }));
 
                 it("will render the message time as configured",
-                mock.initConverseWithPromises(
-                    null, ['rosterGroupsFetched'], {},
-                    function (done, _converse) {
+                    mock.initConverseWithPromises(
+                        null, ['rosterGroupsFetched'], {},
+                        function (done, _converse) {
 
                     test_utils.createContacts(_converse, 'current');
 

+ 18 - 19
spec/converse.js

@@ -102,26 +102,26 @@
                 _converse.auto_away = 3;
                 _converse.auto_xa = 6;
 
-                expect(_converse.xmppstatus.getStatus()).toBe('online');
+                expect(_converse.api.user.status.get()).toBe('online');
                 while (i <= _converse.auto_away) {
                     _converse.onEverySecond(); i++;
                 }
                 expect(_converse.auto_changed_status).toBe(true);
 
                 while (i <= _converse.auto_xa) {
-                    expect(_converse.xmppstatus.getStatus()).toBe('away');
+                    expect(_converse.api.user.status.get()).toBe('away');
                     _converse.onEverySecond();
                     i++;
                 }
-                expect(_converse.xmppstatus.getStatus()).toBe('xa');
+                expect(_converse.api.user.status.get()).toBe('xa');
                 expect(_converse.auto_changed_status).toBe(true);
 
                 _converse.onUserActivity();
-                expect(_converse.xmppstatus.getStatus()).toBe('online');
+                expect(_converse.api.user.status.get()).toBe('online');
                 expect(_converse.auto_changed_status).toBe(false);
 
                 // Check that it also works for the chat feature
-                _converse.xmppstatus.setStatus('chat');
+                _converse.api.user.status.set('chat')
                 i = 0;
                 while (i <= _converse.auto_away) {
                     _converse.onEverySecond();
@@ -129,36 +129,36 @@
                 }
                 expect(_converse.auto_changed_status).toBe(true);
                 while (i <= _converse.auto_xa) {
-                    expect(_converse.xmppstatus.getStatus()).toBe('away');
+                    expect(_converse.api.user.status.get()).toBe('away');
                     _converse.onEverySecond();
                     i++;
                 }
-                expect(_converse.xmppstatus.getStatus()).toBe('xa');
+                expect(_converse.api.user.status.get()).toBe('xa');
                 expect(_converse.auto_changed_status).toBe(true);
 
                 _converse.onUserActivity();
-                expect(_converse.xmppstatus.getStatus()).toBe('online');
+                expect(_converse.api.user.status.get()).toBe('online');
                 expect(_converse.auto_changed_status).toBe(false);
 
                 // Check that it doesn't work for 'dnd'
-                _converse.xmppstatus.setStatus('dnd');
+                _converse.api.user.status.set('dnd');
                 i = 0;
                 while (i <= _converse.auto_away) {
                     _converse.onEverySecond();
                     i++;
                 }
-                expect(_converse.xmppstatus.getStatus()).toBe('dnd');
+                expect(_converse.api.user.status.get()).toBe('dnd');
                 expect(_converse.auto_changed_status).toBe(false);
                 while (i <= _converse.auto_xa) {
-                    expect(_converse.xmppstatus.getStatus()).toBe('dnd');
+                    expect(_converse.api.user.status.get()).toBe('dnd');
                     _converse.onEverySecond();
                     i++;
                 }
-                expect(_converse.xmppstatus.getStatus()).toBe('dnd');
+                expect(_converse.api.user.status.get()).toBe('dnd');
                 expect(_converse.auto_changed_status).toBe(false);
 
                 _converse.onUserActivity();
-                expect(_converse.xmppstatus.getStatus()).toBe('dnd');
+                expect(_converse.api.user.status.get()).toBe('dnd');
                 expect(_converse.auto_changed_status).toBe(false);
             }));
         });
@@ -248,16 +248,15 @@
                 expect(_converse.api.contacts.get('non-existing@jabber.org')).toBeFalsy();
                 // Check when a single jid is given
                 var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
-                var attrs = _converse.api.contacts.get(jid);
-                expect(typeof attrs).toBe('object');
-                expect(attrs.fullname).toBe(mock.cur_names[0]);
-                expect(attrs.jid).toBe(jid);
+                var contact = _converse.api.contacts.get(jid);
+                expect(contact.get('fullname')).toBe(mock.cur_names[0]);
+                expect(contact.get('jid')).toBe(jid);
                 // You can retrieve multiple contacts by passing in an array
                 var jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
                 var list = _converse.api.contacts.get([jid, jid2]);
                 expect(_.isArray(list)).toBeTruthy();
-                expect(list[0].fullname).toBe(mock.cur_names[0]);
-                expect(list[1].fullname).toBe(mock.cur_names[1]);
+                expect(list[0].get('fullname')).toBe(mock.cur_names[0]);
+                expect(list[1].get('fullname')).toBe(mock.cur_names[1]);
                 // Check that all JIDs are returned if you call without any parameters
                 list = _converse.api.contacts.get();
                 expect(list.length).toBe(mock.cur_names.length);

+ 6 - 7
spec/roomslist.js

@@ -9,23 +9,22 @@
 
         it("is shown under a list of open rooms in the \"Rooms\" panel", mock.initConverseWithPromises(
             null, ['rosterGroupsFetched'],
-            { whitelisted_plugins: ['converse-roomslist'],
-              allow_bookmarks: false // Makes testing easier, otherwise we
+            { allow_bookmarks: false // Makes testing easier, otherwise we
                                      // have to mock stanza traffic.
             },
             function (done, _converse) {
+                test_utils.openControlBox();
                 var controlbox = _converse.chatboxviews.get('controlbox');
 
                 var list = controlbox.el.querySelector('div.rooms-list-container');
                 expect(_.includes(list.classList, 'hidden')).toBeTruthy();
 
-                test_utils.openChatRoom(
-                    _converse, 'room', 'conference.shakespeare.lit', 'JC');
+                test_utils.openChatRoom(_converse, 'room', 'conference.shakespeare.lit', 'JC');
 
                 expect(_.isUndefined(_converse.rooms_list_view)).toBeFalsy();
                 var room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
                 expect(room_els.length).toBe(1);
-                expect(room_els[0].innerText).toBe('room');
+                expect(room_els[0].innerText).toBe('room@conference.shakespeare.lit');
 
                 test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
                 room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
@@ -35,7 +34,7 @@
                 view.close();
                 room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
                 expect(room_els.length).toBe(1);
-                expect(room_els[0].innerText).toBe('lounge');
+                expect(room_els[0].innerText).toBe('lounge@localhost');
                 list = controlbox.el.querySelector('div.rooms-list-container');
                 expect(_.includes(list.classList, 'hidden')).toBeFalsy();
 
@@ -73,7 +72,7 @@
             var close_el = _converse.rooms_list_view.el.querySelector(".close-room");
             close_el.click();
             expect(window.confirm).toHaveBeenCalledWith(
-                'Are you sure you want to leave the room "lounge"?');
+                'Are you sure you want to leave the room lounge@conference.shakespeare.lit?');
             room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
             expect(room_els.length).toBe(0);
             expect(_converse.chatboxes.length).toBe(1);

+ 1 - 0
src/converse-chatview.js

@@ -1091,6 +1091,7 @@
                     this.setChatState(_converse.ACTIVE);
                     this.renderEmojiPicker();
                     this.scrollDown();
+                    this.focus();
                 },
 
                 _show (f) {

+ 1 - 1
src/converse-roomslist.js

@@ -211,7 +211,7 @@
                     ev.preventDefault();
                     const name = ev.target.getAttribute('data-room-name');
                     const jid = ev.target.getAttribute('data-room-jid');
-                    if (confirm(__("Are you sure you want to leave the room \"%1$s\"?", name))) {
+                    if (confirm(__("Are you sure you want to leave the room %1$s?", name))) {
                         _converse.chatboxviews.get(jid).leave();
                     }
                 },

+ 1 - 1
src/templates/rooms_list_item.html

@@ -9,7 +9,7 @@
 
 <a class="right close-room icon-leave"
    data-room-jid="{{{o.jid}}}"
-   data-room-name="{{{o.name}}}"
+   data-room-name="{{{o.name || o.jid}}}"
    title="{{{o.info_leave_room}}}" href="#">&nbsp;</a>
 
 {[ if (o.allow_bookmarks) { ]}