Commit e07bb52d authored by JC Brand's avatar JC Brand

Use async/await

parent c46d937e
...@@ -68,53 +68,48 @@ ...@@ -68,53 +68,48 @@
it("shows the number of unread mentions received", it("shows the number of unread mentions received",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'all').openControlBox(); test_utils.createContacts(_converse, 'all').openControlBox();
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
let chatview;
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, sender_jid);
test_utils.openChatBoxFor(_converse, sender_jid); await test_utils.waitUntil(() => _converse.chatboxes.length);
return test_utils.waitUntil(() => _converse.chatboxes.length).then(() => { const chatview = _converse.chatboxviews.get(sender_jid);
chatview = _converse.chatboxviews.get(sender_jid); chatview.model.set({'minimized': true});
chatview.model.set({'minimized': true});
expect(_.isNull(_converse.chatboxviews.el.querySelector('.restore-chat .message-count'))).toBeTruthy();
expect(_.isNull(_converse.chatboxviews.el.querySelector('.restore-chat .message-count'))).toBeTruthy(); expect(_.isNull(_converse.rosterview.el.querySelector('.msgs-indicator'))).toBeTruthy();
expect(_.isNull(_converse.rosterview.el.querySelector('.msgs-indicator'))).toBeTruthy();
let msg = $msg({
const msg = $msg({ from: sender_jid,
from: sender_jid, to: _converse.connection.jid,
to: _converse.connection.jid, type: 'chat',
type: 'chat', id: (new Date()).getTime()
id: (new Date()).getTime() }).c('body').t('hello').up()
}).c('body').t('hello').up() .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); _converse.chatboxes.onMessage(msg);
_converse.chatboxes.onMessage(msg); await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll(".msgs-indicator"));
return test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll(".msgs-indicator")); spyOn(chatview.model, 'incrementUnreadMsgCounter').and.callThrough();
}).then(() => { expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('1');
spyOn(chatview.model, 'incrementUnreadMsgCounter').and.callThrough(); expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('1');
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('1');
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('1'); msg = $msg({
from: sender_jid,
const msg = $msg({ to: _converse.connection.jid,
from: sender_jid, type: 'chat',
to: _converse.connection.jid, id: (new Date()).getTime()
type: 'chat', }).c('body').t('hello again').up()
id: (new Date()).getTime() .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
}).c('body').t('hello again').up() _converse.chatboxes.onMessage(msg);
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); await test_utils.waitUntil(() => chatview.model.incrementUnreadMsgCounter.calls.count());
_converse.chatboxes.onMessage(msg); expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('2');
return test_utils.waitUntil(() => chatview.model.incrementUnreadMsgCounter.calls.count()); expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('2');
}).then(() => { chatview.model.set({'minimized': false});
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('2'); expect(_.isNull(_converse.chatboxviews.el.querySelector('.restore-chat .message-count'))).toBeTruthy();
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('2'); expect(_.isNull(_converse.rosterview.el.querySelector('.msgs-indicator'))).toBeTruthy();
chatview.model.set({'minimized': false}); done();
expect(_.isNull(_converse.chatboxviews.el.querySelector('.restore-chat .message-count'))).toBeTruthy();
expect(_.isNull(_converse.rosterview.el.querySelector('.msgs-indicator'))).toBeTruthy();
done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
}); });
......
...@@ -961,51 +961,45 @@ ...@@ -961,51 +961,45 @@
})); }));
it("will render images from their URLs", it("will render images from their URLs",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
const base_url = document.URL.split(window.location.pathname)[0]; const base_url = document.URL.split(window.location.pathname)[0];
let message = base_url+"/logo/conversejs-filled.svg"; let message = base_url+"/logo/conversejs-filled.svg";
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
let view; await test_utils.openChatBoxFor(_converse, contact_jid);
test_utils.openChatBoxFor(_converse, contact_jid) const view = _converse.chatboxviews.get(contact_jid);
.then(() => { spyOn(view.model, 'sendMessage').and.callThrough();
view = _converse.chatboxviews.get(contact_jid); test_utils.sendMessage(view, message);
spyOn(view.model, 'sendMessage').and.callThrough(); await test_utils.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length, 1000)
test_utils.sendMessage(view, message); expect(view.model.sendMessage).toHaveBeenCalled();
return test_utils.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length, 1000) let msg = $(view.el).find('.chat-content .chat-msg').last().find('.chat-msg__text');
}).then(() => { expect(msg.html().trim()).toEqual(
expect(view.model.sendMessage).toHaveBeenCalled(); '<!-- src/templates/image.html -->\n'+
const msg = $(view.el).find('.chat-content .chat-msg').last().find('.chat-msg__text'); '<a href="'+base_url+'/logo/conversejs-filled.svg" target="_blank" rel="noopener"><img class="chat-image img-thumbnail"'+
expect(msg.html().trim()).toEqual( ' src="' + message + '"></a>');
'<!-- src/templates/image.html -->\n'+ message += "?param1=val1&param2=val2";
'<a href="'+base_url+'/logo/conversejs-filled.svg" target="_blank" rel="noopener"><img class="chat-image img-thumbnail"'+ test_utils.sendMessage(view, message);
' src="' + message + '"></a>'); await test_utils.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length === 2, 1000);
message += "?param1=val1&param2=val2"; expect(view.model.sendMessage).toHaveBeenCalled();
test_utils.sendMessage(view, message); msg = $(view.el).find('.chat-content').find('.chat-msg').last().find('.chat-msg__text');
return test_utils.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length === 2, 1000); expect(msg.html().trim()).toEqual(
}).then(() => { '<!-- src/templates/image.html -->\n'+
expect(view.model.sendMessage).toHaveBeenCalled(); '<a href="'+base_url+'/logo/conversejs-filled.svg?param1=val1&amp;param2=val2" target="_blank" rel="noopener"><img'+
const msg = $(view.el).find('.chat-content').find('.chat-msg').last().find('.chat-msg__text'); ' class="chat-image img-thumbnail" src="'+message.replace(/&/g, '&amp;')+'"></a>')
expect(msg.html().trim()).toEqual(
'<!-- src/templates/image.html -->\n'+ // Test now with two images in one message
'<a href="'+base_url+'/logo/conversejs-filled.svg?param1=val1&amp;param2=val2" target="_blank" rel="noopener"><img'+ message += ' hello world '+base_url+"/logo/conversejs-filled.svg";
' class="chat-image img-thumbnail" src="'+message.replace(/&/g, '&amp;')+'"></a>') test_utils.sendMessage(view, message);
await test_utils.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length === 4, 1000);
// Test now with two images in one message expect(view.model.sendMessage).toHaveBeenCalled();
message += ' hello world '+base_url+"/logo/conversejs-filled.svg"; msg = $(view.el).find('.chat-content').find('.chat-msg').last().find('.chat-msg__text');
test_utils.sendMessage(view, message); expect(msg[0].textContent.trim()).toEqual('hello world');
return test_utils.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length === 4, 1000); expect(msg[0].querySelectorAll('img').length).toEqual(2);
}).then(function () { done();
expect(view.model.sendMessage).toHaveBeenCalled();
const msg = $(view.el).find('.chat-content').find('.chat-msg').last().find('.chat-msg__text');
expect(msg[0].textContent.trim()).toEqual('hello world');
expect(msg[0].querySelectorAll('img').length).toEqual(2);
done();
});
})); }));
it("will render the message time as configured", it("will render the message time as configured",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment