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.
This commit is contained in:
parent
8806efce50
commit
603708a9c9
@ -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 @@
|
|||||||
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 @@
|
|||||||
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,28 +127,28 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
return utils.waitUntil(() => _.get(_.filter(
|
if (!_converse.disco_entities.get(room_jid)) {
|
||||||
_converse.connection.IQ_stanzas,
|
utils.waitUntil(() => _.get(_.filter(
|
||||||
|
stanzas,
|
||||||
iq => iq.nodeTree.querySelector(
|
iq => iq.nodeTree.querySelector(
|
||||||
`iq[to="coven@chat.shakespeare.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]`
|
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
|
||||||
)
|
)).pop(), 'nodeTree'))
|
||||||
).pop(), 'nodeTree'));
|
.then(stanza => {
|
||||||
}).then(stanza => {
|
|
||||||
const features_stanza = $iq({
|
const features_stanza = $iq({
|
||||||
'from': room_jid,
|
'from': room_jid,
|
||||||
'id': stanza.getAttribute('id'),
|
'id': stanza.getAttribute('id'),
|
||||||
'to': 'dummy@localhost/desktop',
|
'to': 'dummy@localhost/desktop',
|
||||||
'type': 'result'
|
'type': 'result'
|
||||||
})
|
}).c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
|
||||||
.c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
|
|
||||||
.c('identity', {
|
.c('identity', {
|
||||||
'category': 'conference',
|
'category': 'conference',
|
||||||
'name': 'A Dark Cave',
|
'name': room[0].toUpperCase() + room.slice(1),
|
||||||
'type': 'text'
|
'type': 'text'
|
||||||
}).up()
|
}).up()
|
||||||
.c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
|
.c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
|
||||||
@ -166,17 +167,18 @@
|
|||||||
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
|
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
|
||||||
.c('value').t(0);
|
.c('value').t(0);
|
||||||
_converse.connection._dataRecv(utils.createRequest(features_stanza));
|
_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(() => {
|
}
|
||||||
|
return utils.waitUntil(() => _.get(_.filter(
|
||||||
|
stanzas,
|
||||||
|
s => sizzle(`iq[to="${room_jid}"] query[node="x-roomuser-item"]`, s.nodeTree).length
|
||||||
|
).pop(), 'nodeTree')
|
||||||
|
);
|
||||||
|
}).then(last_stanza => {
|
||||||
|
// We empty the array, otherwise we might get stale stanzas
|
||||||
|
// returned in our filter above.
|
||||||
|
stanzas.length = 0;
|
||||||
|
|
||||||
// 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 @@
|
|||||||
// 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',
|
||||||
|
Loading…
Reference in New Issue
Block a user