Commit b91f4884 authored by JC Brand's avatar JC Brand

Use async/await

parent 54652f74
This diff is collapsed.
......@@ -652,7 +652,7 @@
it("received for a minimized chat box will increment a counter on its header",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) {
async function (done, _converse) {
if (_converse.view_mode === 'fullscreen') {
return done();
......@@ -661,14 +661,12 @@
_converse.emit('rosterContactsFetched');
const contact_name = mock.cur_names[0];
const contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
let chatview, trimmedview, $count, trimmed_chatboxes;
test_utils.openControlBox();
spyOn(_converse, 'emit').and.callThrough();
test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length)
.then(() => test_utils.openChatBoxFor(_converse, contact_jid))
.then(() => {
chatview = _converse.chatboxviews.get(contact_jid);
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
await test_utils.openChatBoxFor(_converse, contact_jid);
const chatview = await _converse.api.chatviews.get(contact_jid);
expect(u.isVisible(chatview.el)).toBeTruthy();
expect(chatview.model.get('minimized')).toBeFalsy();
chatview.el.querySelector('.toggle-chatbox-button').click();
......@@ -683,16 +681,16 @@
}).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
_converse.chatboxes.onMessage(msg);
return test_utils.waitUntil(() => chatview.model.messages.length);
}).then(() => {
await test_utils.waitUntil(() => chatview.model.messages.length);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
trimmed_chatboxes = _converse.minimized_chats;
trimmedview = trimmed_chatboxes.get(contact_jid);
$count = $(trimmedview.el).find('.message-count');
const trimmed_chatboxes = _converse.minimized_chats;
const trimmedview = trimmed_chatboxes.get(contact_jid);
let count = trimmedview.el.querySelector('.message-count');
expect(u.isVisible(chatview.el)).toBeFalsy();
expect(trimmedview.model.get('minimized')).toBeTruthy();
expect(u.isVisible($count[0])).toBeTruthy();
expect($count.html()).toBe('1');
expect(u.isVisible(count)).toBeTruthy();
expect(count.textContent).toBe('1');
_converse.chatboxes.onMessage(
$msg({
from: mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
......@@ -702,17 +700,16 @@
}).c('body').t('This message is also sent to a minimized chatbox').up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()
);
return test_utils.waitUntil(() => chatview.model.messages.length);
}).then(() => {
await test_utils.waitUntil(() => (chatview.model.messages.length > 1));
expect(u.isVisible(chatview.el)).toBeFalsy();
expect(trimmedview.model.get('minimized')).toBeTruthy();
$count = $(trimmedview.el).find('.message-count');
expect(u.isVisible($count[0])).toBeTruthy();
expect($count.html()).toBe('2');
count = trimmedview.el.querySelector('.message-count');
expect(u.isVisible(count)).toBeTruthy();
expect(count.textContent).toBe('2');
trimmedview.el.querySelector('.restore-chat').click();
expect(trimmed_chatboxes.keys().length).toBe(0);
done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
}));
it("will indicate when it has a time difference of more than a day between it and its predecessor",
......@@ -1918,16 +1915,14 @@
it("will render images from oob URLs",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) {
async function (done, _converse) {
const base_url = 'https://conversejs.org';
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
let view;
test_utils.openChatBoxFor(_converse, contact_jid)
.then(() => {
view = _converse.chatboxviews.get(contact_jid);
await test_utils.openChatBoxFor(_converse, contact_jid)
const view = await _converse.api.chatviews.get(contact_jid);
spyOn(view.model, 'sendMessage').and.callThrough();
const url = base_url+"/logo/conversejs-filled.svg";
......@@ -1939,8 +1934,8 @@
" <x xmlns='jabber:x:oob'><url>"+url+"</url></x>"+
"</message>").firstChild;
_converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-msg img').length, 2000);
}).then(function () {
await test_utils.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-msg img').length, 2000);
const msg = view.el.querySelector('.chat-msg .chat-msg__text');
expect(msg.outerHTML).toEqual('<div class="chat-msg__text">Have you seen this funny image?</div>');
const media = view.el.querySelector('.chat-msg .chat-msg__media');
......@@ -1950,7 +1945,6 @@
`<img class="chat-image img-thumbnail" src="${base_url}/logo/conversejs-filled.svg">`+
`</a>`);
done();
}).catch(_.partial(console.error, _));
}));
});
});
......
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