From 35275c8add3e3e0ad19eed46141ac7157385cea9 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 15 Jan 2018 18:40:35 +0100 Subject: [PATCH 1/3] Lazily show spinner at the last moment --- src/converse-mam.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/converse-mam.js b/src/converse-mam.js index fa79179cb..8f6890703 100644 --- a/src/converse-mam.js +++ b/src/converse-mam.js @@ -73,7 +73,6 @@ */ if (this.disable_mam) { return; } const { _converse } = this.__super__; - this.addSpinner(true); _converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid).then( (result) => { // Success if (result.supported) { @@ -92,12 +91,9 @@ }); } } - } else { - this.clearSpinner(); } }, () => { // Error - this.clearSpinner(); _converse.log( "Error or timeout while checking for MAM support", Strophe.LogLevel.ERROR @@ -115,19 +111,14 @@ return; } const { _converse } = this.__super__; - this.addSpinner(); - _converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid).then( (result) => { // Success if (result.supported) { this.fetchArchivedMessages(); - } else { - this.clearSpinner(); } this.model.save({'mam_initialized': true}); }, () => { // Error - this.clearSpinner(); _converse.log( "Error or timeout while checking for MAM support", Strophe.LogLevel.ERROR @@ -253,9 +244,9 @@ * Then, upon receiving them, call onChatRoomMessage * so that they are displayed inside it. */ - this.addSpinner(); const that = this; const { _converse } = this.__super__; + this.addSpinner(); _converse.api.archive.query( _.extend({ 'groupchat': true, From e9bba77b36b7cefa5b05e530dbcd48f73084b791 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 15 Jan 2018 18:41:04 +0100 Subject: [PATCH 2/3] Add test for `/help` command in private chats --- spec/chatbox.js | 23 +++++++++++++++++++++++ src/converse-chatview.js | 6 +++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/spec/chatbox.js b/spec/chatbox.js index d6c195d00..5223ad446 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -20,6 +20,29 @@ return describe("Chatboxes", function() { describe("A Chatbox", function () { + it("has a /help command to show the available commands", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + + test_utils.createContacts(_converse, 'current'); + test_utils.openControlBox(); + test_utils.openContactsPanel(_converse); + + var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; + test_utils.openChatBoxFor(_converse, contact_jid); + var view = _converse.chatboxviews.get(contact_jid); + test_utils.sendMessage(view, '/help'); + + const info_messages = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info:not(.chat-date)'), 0); + expect(info_messages.length).toBe(3); + expect(info_messages.pop().textContent).toBe('/help: Show this menu'); + expect(info_messages.pop().textContent).toBe('/me: Write in the third person'); + expect(info_messages.pop().textContent).toBe('/clear: Remove messages'); + done(); + })); + + it("supports the /me command", mock.initConverseWithPromises( null, ['rosterGroupsFetched'], {}, diff --git a/src/converse-chatview.js b/src/converse-chatview.js index 39bfcd9a6..17e74918a 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -738,9 +738,9 @@ } else if (match[1] === "help") { const msgs = [ - `/help:${__('Show this menu')}`, - `/me:${__('Write in the third person')}`, - `/clear:${__('Remove messages')}` + `/clear: ${__('Remove messages')}`, + `/me: ${__('Write in the third person')}`, + `/help: ${__('Show this menu')}` ]; this.showHelpMessages(msgs); return; From 8c616f0eddbe7b6561ce59b76d53a9da7c7b7e88 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 15 Jan 2018 19:03:08 +0100 Subject: [PATCH 3/3] Test breaks when run in a different timezone --- spec/chatbox.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/spec/chatbox.js b/spec/chatbox.js index 5223ad446..a257817eb 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -961,6 +961,7 @@ null, ['rosterGroupsFetched'], {}, function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -976,17 +977,17 @@ var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; /* - * - * - * - * Call me but love, and I'll be new baptized; Henceforth I never will be Romeo. - * - * - * - */ + * + * + * + * Call me but love, and I'll be new baptized; Henceforth I never will be Romeo. + * + * + * + */ msg = $msg({'id': 'aeb213', 'to': _converse.bare_jid}) .c('forwarded', {'xmlns': 'urn:xmpp:forward:0'}) .c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2018-01-02T13:08:25Z'}).up() @@ -1001,7 +1002,7 @@ msg = $msg({'id': 'aeb214', 'to': _converse.bare_jid}) .c('forwarded', {'xmlns': 'urn:xmpp:forward:0'}) - .c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2017-12-31T23:08:25Z'}).up() + .c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2017-12-31T22:08:25Z'}).up() .c('message', { 'xmlns': 'jabber:client', 'to': _converse.bare_jid, @@ -1049,7 +1050,7 @@ msg = $msg({'id': 'aeb218', 'to': _converse.bare_jid}) .c('forwarded', {'xmlns': 'urn:xmpp:forward:0'}) - .c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2018-01-02T23:28:23Z'}).up() + .c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2018-01-02T22:28:23Z'}).up() .c('message', { 'xmlns': 'jabber:client', 'to': _converse.bare_jid, @@ -1090,14 +1091,16 @@ var $time = $chat_content.find('time'); expect($time.length).toEqual(4); $time = $chat_content.find('time:first'); - expect($time.data('isodate')).toEqual('2017-12-31T00:00:00+00:00'); + expect($time.data('isodate')).toEqual(moment('2017-12-31T00:00:00').format()); + expect($time.text()).toEqual('Sunday Dec 31st 2017') expect($time[0].nextElementSibling.querySelector('.chat-msg-content').textContent).toBe('Older message'); var $el = $chat_content.find('.chat-message:first').find('.chat-msg-content') expect($el.text()).toEqual('Older message'); $time = $chat_content.find('time:eq(1)'); - expect($time.data('isodate')).toEqual('2018-01-01T00:00:00+00:00'); + expect($time.data('isodate')).toEqual(moment('2018-01-01T00:00:00').format()); + expect($time.text()).toEqual("Monday Jan 1st 2018"); expect($time[0].nextElementSibling.querySelector('.chat-msg-content').textContent).toBe('Inbetween message'); $el = $chat_content.find('.chat-message:eq(1)'); expect($el.find('.chat-msg-content').text()).toEqual('Inbetween message'); @@ -1106,7 +1109,8 @@ expect($el.find('.chat-msg-content').text()).toEqual('another inbetween message'); $time = $chat_content.find('time:nth(2)'); - expect($time.data('isodate')).toEqual('2018-01-02T00:00:00+00:00'); + expect($time.data('isodate')).toEqual(moment('2018-01-02T00:00:00').format()); + expect($time.text()).toEqual("Tuesday Jan 2nd 2018"); expect($time[0].nextElementSibling.querySelector('.chat-msg-content').textContent).toBe('An earlier message on the next day'); $el = $chat_content.find('.chat-message:eq(3)'); expect($el.find('.chat-msg-content').text()).toEqual('An earlier message on the next day');