Commit 603708a9 authored by JC Brand's avatar JC Brand

Update test `openAndEnterChatRoom` to handle re-opening of rooms

in which case a disco query is not sent out again because we still have
it cached.
parent 8806efce
...@@ -61,7 +61,6 @@ ...@@ -61,7 +61,6 @@
function (done, _converse) { function (done, _converse) {
let jid, room, chatroomview; let jid, room, chatroomview;
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group .group-toggle').length, 300) test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group .group-toggle').length, 300)
.then(() => test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy')) .then(() => test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'))
...@@ -103,7 +102,7 @@ ...@@ -103,7 +102,7 @@
room = _converse.api.rooms.get(jid); room = _converse.api.rooms.get(jid);
expect(typeof room === 'undefined').toBeTruthy(); expect(typeof room === 'undefined').toBeTruthy();
done(); done();
}); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
it("has a method 'open' which opens (optionally configures) and returns a wrapped chat box", it("has a method 'open' which opens (optionally configures) and returns a wrapped chat box",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
var $pres = converse.env.$pres; var $pres = converse.env.$pres;
var $iq = converse.env.$iq; var $iq = converse.env.$iq;
var Strophe = converse.env.Strophe; var Strophe = converse.env.Strophe;
var sizzle = converse.env.sizzle;
var u = converse.env.utils; var u = converse.env.utils;
var utils = {}; var utils = {};
...@@ -126,57 +127,58 @@ ...@@ -126,57 +127,58 @@
}; };
utils.openAndEnterChatRoom = function (_converse, room, server, nick) { utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
let last_stanza, view; let view;
const room_jid = `${room}@${server}`.toLowerCase(); const room_jid = `${room}@${server}`.toLowerCase();
const stanzas = _converse.connection.IQ_stanzas;
return _converse.api.rooms.open(room_jid).then(() => { return _converse.api.rooms.open(room_jid).then(() => {
view = _converse.chatboxviews.get(room_jid); view = _converse.chatboxviews.get(room_jid);
if (!_converse.disco_entities.get(room_jid)) {
utils.waitUntil(() => _.get(_.filter(
stanzas,
iq => iq.nodeTree.querySelector(
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).pop(), 'nodeTree'))
.then(stanza => {
const features_stanza = $iq({
'from': room_jid,
'id': stanza.getAttribute('id'),
'to': 'dummy@localhost/desktop',
'type': 'result'
}).c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
.c('identity', {
'category': 'conference',
'name': room[0].toUpperCase() + room.slice(1),
'type': 'text'
}).up()
.c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
.c('feature', {'var': 'jabber:iq:register'}).up()
.c('feature', {'var': 'muc_passwordprotected'}).up()
.c('feature', {'var': 'muc_hidden'}).up()
.c('feature', {'var': 'muc_temporary'}).up()
.c('feature', {'var': 'muc_open'}).up()
.c('feature', {'var': 'muc_unmoderated'}).up()
.c('feature', {'var': 'muc_nonanonymous'})
.c('x', { 'xmlns':'jabber:x:data', 'type':'result'})
.c('field', {'var':'FORM_TYPE', 'type':'hidden'})
.c('value').t('http://jabber.org/protocol/muc#roominfo').up().up()
.c('field', {'type':'text-single', 'var':'muc#roominfo_description', 'label':'Description'})
.c('value').t('This is the description').up().up()
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
.c('value').t(0);
_converse.connection._dataRecv(utils.createRequest(features_stanza));
});
}
return utils.waitUntil(() => _.get(_.filter( return utils.waitUntil(() => _.get(_.filter(
_converse.connection.IQ_stanzas, stanzas,
iq => iq.nodeTree.querySelector( s => sizzle(`iq[to="${room_jid}"] query[node="x-roomuser-item"]`, s.nodeTree).length
`iq[to="coven@chat.shakespeare.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]` ).pop(), 'nodeTree')
) );
).pop(), 'nodeTree')); }).then(last_stanza => {
}).then(stanza => { // We empty the array, otherwise we might get stale stanzas
const features_stanza = $iq({ // returned in our filter above.
'from': room_jid, stanzas.length = 0;
'id': stanza.getAttribute('id'),
'to': 'dummy@localhost/desktop',
'type': 'result'
})
.c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
.c('identity', {
'category': 'conference',
'name': 'A Dark Cave',
'type': 'text'
}).up()
.c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
.c('feature', {'var': 'jabber:iq:register'}).up()
.c('feature', {'var': 'muc_passwordprotected'}).up()
.c('feature', {'var': 'muc_hidden'}).up()
.c('feature', {'var': 'muc_temporary'}).up()
.c('feature', {'var': 'muc_open'}).up()
.c('feature', {'var': 'muc_unmoderated'}).up()
.c('feature', {'var': 'muc_nonanonymous'})
.c('x', { 'xmlns':'jabber:x:data', 'type':'result'})
.c('field', {'var':'FORM_TYPE', 'type':'hidden'})
.c('value').t('http://jabber.org/protocol/muc#roominfo').up().up()
.c('field', {'type':'text-single', 'var':'muc#roominfo_description', 'label':'Description'})
.c('value').t('This is the description').up().up()
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
.c('value').t(0);
_converse.connection._dataRecv(utils.createRequest(features_stanza));
return utils.waitUntil(() => {
return _.filter(
_converse.connection.IQ_stanzas, (node) => {
const query = node.nodeTree.querySelector('query');
if (query && query.getAttribute('node') === 'x-roomuser-item') {
last_stanza = node.nodeTree;
return true;
}
}).length
});
}).then(() => {
// The XMPP server returns the reserved nick for this user. // The XMPP server returns the reserved nick for this user.
const IQ_id = last_stanza.getAttribute('id'); const IQ_id = last_stanza.getAttribute('id');
const stanza = $iq({ const stanza = $iq({
...@@ -194,8 +196,8 @@ ...@@ -194,8 +196,8 @@
// See example 24: http://xmpp.org/extensions/xep-0045.html#enter-pres // See example 24: http://xmpp.org/extensions/xep-0045.html#enter-pres
var presence = $pres({ var presence = $pres({
to: _converse.connection.jid, to: _converse.connection.jid,
from: room+'@'+server+'/'+nick, from: `${room_jid}/${nick}`,
id: 'DC352437-C019-40EC-B590-AF29E879AF97' id: u.getUniqueId()
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'}) }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
.c('item').attrs({ .c('item').attrs({
affiliation: 'owner', affiliation: 'owner',
......
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