From 2f46bb8ce7dba0a8fc9391650a7cc5d5ad50ab22 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 14 Mar 2018 19:01:33 +0000 Subject: [PATCH] Fix failing tests --- spec/chatbox.js | 49 +++++++++++++++--------------- spec/converse.js | 37 +++++++++++----------- spec/roomslist.js | 13 ++++---- src/converse-chatview.js | 1 + src/converse-roomslist.js | 2 +- src/templates/rooms_list_item.html | 2 +- 6 files changed, 51 insertions(+), 53 deletions(-) diff --git a/spec/chatbox.js b/spec/chatbox.js index 26a32837f..45463004e 100644 --- a/spec/chatbox.js +++ b/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'); diff --git a/spec/converse.js b/spec/converse.js index e1342a696..6739f9a03 100644 --- a/spec/converse.js +++ b/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); diff --git a/spec/roomslist.js b/spec/roomslist.js index ee717350c..50a970a9c 100644 --- a/spec/roomslist.js +++ b/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); diff --git a/src/converse-chatview.js b/src/converse-chatview.js index 37a62c066..9a17699c4 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -1091,6 +1091,7 @@ this.setChatState(_converse.ACTIVE); this.renderEmojiPicker(); this.scrollDown(); + this.focus(); }, _show (f) { diff --git a/src/converse-roomslist.js b/src/converse-roomslist.js index eb017b297..1cf724724 100644 --- a/src/converse-roomslist.js +++ b/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(); } }, diff --git a/src/templates/rooms_list_item.html b/src/templates/rooms_list_item.html index 927033c6c..3af69a49d 100644 --- a/src/templates/rooms_list_item.html +++ b/src/templates/rooms_list_item.html @@ -9,7 +9,7 @@   {[ if (o.allow_bookmarks) { ]}