Commit 6ebf6f6e authored by JC Brand's avatar JC Brand

Fix failing test by making sure notifications are cleared

parent 07154768
...@@ -59465,12 +59465,14 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins ...@@ -59465,12 +59465,14 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
'model': message 'model': message
}); });
await view.render(); await view.render();
this.clearChatStateNotification(message);
if (!view.el.innerHTML) { if (!view.el.innerHTML) {
return _converse.log("showMessage: message's view element is empty", Strophe.LogLevel.ERROR); // An "inactive" CSN message (for example) will have an
// empty body. No need to then continue.
return _converse.log("Not inserting a message with empty element", Strophe.LogLevel.INFO);
} }
this.clearChatStateNotification(message);
this.insertMessage(view); this.insertMessage(view);
this.insertDayIndicator(view.el); this.insertDayIndicator(view.el);
this.setScrollPosition(view.el); this.setScrollPosition(view.el);
...@@ -1020,47 +1020,41 @@ ...@@ -1020,47 +1020,41 @@
it("will clear any other chat status notifications", it("will clear any other chat status notifications",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
test_utils.openControlBox(); test_utils.openControlBox();
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost'; const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
let view;
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions // See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
spyOn(_converse, 'emit'); spyOn(_converse, 'emit');
test_utils.openChatBoxFor(_converse, sender_jid) await test_utils.openChatBoxFor(_converse, sender_jid);
.then(() => { const view = _converse.chatboxviews.get(sender_jid);
view = _converse.chatboxviews.get(sender_jid); expect(view.el.querySelectorAll('.chat-event').length).toBe(0);
expect(view.el.querySelectorAll('.chat-event').length).toBe(0); // Insert <composing> message, to also check that
// Insert <composing> message, to also check that // text messages are inserted correctly with
// text messages are inserted correctly with // temporary chat events in the chat contents.
// temporary chat events in the chat contents. let msg = $msg({
const msg = $msg({ 'to': _converse.bare_jid,
'to': _converse.bare_jid, 'xmlns': 'jabber:client',
'xmlns': 'jabber:client', 'from': sender_jid,
'from': sender_jid, 'type': 'chat'})
'type': 'chat'}) .c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
.c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up() .tree();
.tree(); _converse.chatboxes.onMessage(msg);
_converse.chatboxes.onMessage(msg); await test_utils.waitUntil(() => view.model.messages.length);
return test_utils.waitUntil(() => view.model.messages.length); expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(1);
}).then(() => { msg = $msg({
expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(1); 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').c('inactive', {'xmlns': Strophe.NS.CHATSTATES}).tree();
id: (new Date()).getTime() _converse.chatboxes.onMessage(msg);
}).c('body').c('inactive', {'xmlns': Strophe.NS.CHATSTATES}).tree(); await test_utils.waitUntil(() => (view.model.messages.length > 1));
_converse.chatboxes.onMessage(msg); expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
return test_utils.waitUntil(() => (view.model.messages.length > 1)); expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(0);
}).then(() => { done();
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect($(view.el).find('.chat-state-notification').length).toBe(0);
done();
});
})); }));
}); });
......
...@@ -728,11 +728,15 @@ converse.plugins.add('converse-chatview', { ...@@ -728,11 +728,15 @@ converse.plugins.add('converse-chatview', {
*/ */
const view = new _converse.MessageView({'model': message}); const view = new _converse.MessageView({'model': message});
await view.render(); await view.render();
this.clearChatStateNotification(message);
if (!view.el.innerHTML) { if (!view.el.innerHTML) {
return _converse.log("showMessage: message's view element is empty", Strophe.LogLevel.ERROR); // An "inactive" CSN message (for example) will have an
// empty body. No need to then continue.
return _converse.log(
"Not inserting a message with empty element",
Strophe.LogLevel.INFO
);
} }
this.clearChatStateNotification(message);
this.insertMessage(view); this.insertMessage(view);
this.insertDayIndicator(view.el); this.insertDayIndicator(view.el);
this.setScrollPosition(view.el); this.setScrollPosition(view.el);
......
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