Commit 2857293a authored by JC Brand's avatar JC Brand

Fix failing tests by waiting and slightly improve code

parent 5f009875
......@@ -53105,16 +53105,8 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_1__["default"].plugins
},
updateUnreadMessagesCounter() {
const ls = this.model.pluck('num_unread');
let count = 0,
i;
for (i = 0; i < ls.length; i++) {
count += ls[i];
}
this.toggleview.model.save({
'num_unread': count
'num_unread': _.sum(this.model.pluck('num_unread'))
});
this.render();
}
......@@ -1056,18 +1056,19 @@
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
test_utils.openControlBox();
spyOn(_converse, 'emit');
expect(_converse.msg_counter).toBe(0);
spyOn(_converse, 'incrementMsgCounter').and.callThrough();
spyOn(_converse, 'clearMsgCounter').and.callThrough();
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
const view = await test_utils.openChatBoxFor(_converse, sender_jid)
const previous_state = _converse.windowState;
const message = 'This message will increment the message counter';
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
msg = $msg({
const msg = $msg({
from: sender_jid,
to: _converse.connection.jid,
type: 'chat',
......@@ -1075,8 +1076,13 @@
}).c('body').t(message).up()
.c('active', {'xmlns': Strophe.NS.CHATSTATES}).tree();
_converse.windowState = 'hidden';
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse, 'incrementMsgCounter').and.callThrough();
spyOn(_converse, 'clearMsgCounter').and.callThrough();
_converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => _converse.api.chats.get().length)
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(_converse.incrementMsgCounter).toHaveBeenCalled();
expect(_converse.clearMsgCounter).not.toHaveBeenCalled();
expect(_converse.msg_counter).toBe(1);
......@@ -1321,7 +1327,7 @@
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread too');
_converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => chatbox.messages.length);
await test_utils.waitUntil(() => chatbox.messages.length > 1);
indicator_el = sizzle(selector, _converse.rosterview.el).pop();
expect(indicator_el.textContent).toBe('2');
done();
......@@ -1352,7 +1358,7 @@
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread too');
_converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => chatbox.messages.length);
await test_utils.waitUntil(() => chatbox.messages.length > 1);
indicator_el = sizzle(selector, _converse.rosterview.el).pop();
expect(indicator_el.textContent).toBe('2');
done();
......@@ -1378,7 +1384,7 @@
await test_utils.waitUntil(() => chatbox.messages.length);
expect(select_msgs_indicator().text()).toBe('1');
_converse.chatboxes.onMessage(msgFactory());
await test_utils.waitUntil(() => chatbox.messages.length);
await test_utils.waitUntil(() => chatbox.messages.length > 1);
expect(select_msgs_indicator().text()).toBe('2');
view.maximize();
expect(select_msgs_indicator().length).toBe(0);
......
......@@ -87,7 +87,7 @@
}).c('body').t('hello').up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
_converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll(".msgs-indicator"));
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll(".msgs-indicator").length);
spyOn(chatview.model, 'incrementUnreadMsgCounter').and.callThrough();
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('1');
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('1');
......
......@@ -1571,7 +1571,7 @@
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
.t('Server-to-server connection failed: Connecting failed: connection timeout');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => view.model.messages.length);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(chat_content.querySelector('.chat-error').textContent).toEqual(error_txt);
stanza = $msg({
'to': _converse.connection.jid,
......@@ -1584,7 +1584,7 @@
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
.t('Server-to-server connection failed: Connecting failed: connection timeout');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => view.model.messages.length > 1);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(chat_content.querySelectorAll('.chat-error').length).toEqual(2);
// We don't render duplicates
......@@ -1599,7 +1599,6 @@
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
.t('Server-to-server connection failed: Connecting failed: connection timeout');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => view.model.messages.length > 2);
expect(chat_content.querySelectorAll('.chat-error').length).toEqual(2);
// We send another message, for which an error will
......@@ -1630,7 +1629,7 @@
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
.t('Something else went wrong as well');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => view.model.messages.length > 3);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(chat_content.querySelectorAll('.chat-error').length).toEqual(3);
done();
}));
......
......@@ -467,10 +467,7 @@ converse.plugins.add('converse-minimize', {
},
updateUnreadMessagesCounter () {
const ls = this.model.pluck('num_unread');
let count = 0, i;
for (i=0; i<ls.length; i++) { count += ls[i]; }
this.toggleview.model.save({'num_unread': count});
this.toggleview.model.save({'num_unread': _.sum(this.model.pluck('num_unread'))});
this.render();
}
});
......
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