Commit 1a3526f5 authored by JC Brand's avatar JC Brand

Update `openAndEnterChatRoom` to take JID

parent da1d8764
......@@ -20,7 +20,7 @@
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'tom');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'tom');
const view = _converse.chatboxviews.get('lounge@montague.lit');
['dick', 'harry'].forEach((nick) => {
......@@ -62,7 +62,7 @@
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.chatboxviews.get('lounge@montague.lit');
expect(view.model.occupants.length).toBe(1);
let presence = $pres({
......@@ -173,7 +173,7 @@
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.chatboxviews.get('lounge@montague.lit');
expect(view.model.occupants.length).toBe(1);
const presence = $pres({
......
......@@ -190,7 +190,7 @@
null, ['rosterGroupsFetched'], {},
async (done, _converse) => {
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
test_utils.waitUntilDiscoConfirmed(
_converse, _converse.domain,
[{'category': 'server', 'type':'IM'}],
......@@ -239,7 +239,7 @@
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.lit'], 'items');
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.lit', [], [Strophe.NS.HTTPUPLOAD], []);
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
await test_utils.waitUntil(() => _converse.chatboxviews.get('lounge@montague.lit').el.querySelector('.upload-file'));
const view = _converse.chatboxviews.get('lounge@montague.lit');
expect(view.el.querySelector('.chat-toolbar .upload-file')).not.toBe(null);
......@@ -365,7 +365,7 @@
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.tld'], 'items');
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.tld', [], [Strophe.NS.HTTPUPLOAD], []);
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
// Wait until MAM query has been sent out
const sent_stanzas = _converse.connection.sent_stanzas;
......
......@@ -24,7 +24,7 @@
null, ['discoInitialized'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'trek-radio', 'conference.lightwitch.org', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'trek-radio@conference.lightwitch.org', 'romeo');
const view = _converse.chatboxviews.get('trek-radio@conference.lightwitch.org');
let stanza = u.toStanza(
......@@ -72,7 +72,7 @@
null, ['discoInitialized'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'trek-radio', 'conference.lightwitch.org', 'jcbrand');
await test_utils.openAndEnterChatRoom(_converse, 'trek-radio@conference.lightwitch.org', 'jcbrand');
const view = _converse.chatboxviews.get('trek-radio@conference.lightwitch.org');
let stanza = u.toStanza(
`<message xmlns="jabber:client" to="jcbrand@lightwitch.org/converse.js-73057452" type="groupchat" from="trek-radio@conference.lightwitch.org/comndrdukath#0805 (STO)">
......@@ -111,7 +111,7 @@
null, ['discoInitialized'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'discuss', 'conference.conversejs.org', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'discuss@conference.conversejs.org', 'romeo');
const view = _converse.chatboxviews.get('discuss@conference.conversejs.org');
let stanza = u.toStanza(
`<message xmlns="jabber:client" to="romeo@montague.lit/orchard" from="discuss@conference.conversejs.org">
......
This diff is collapsed.
......@@ -153,30 +153,26 @@
it("shows the number messages received to minimized groupchats",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
const room_jid = 'kitchen@conference.shakespeare.lit';
test_utils.openAndEnterChatRoom(
_converse, 'kitchen', 'conference.shakespeare.lit', 'fires').then(function () {
var view = _converse.chatboxviews.get(room_jid);
view.model.set({'minimized': true});
async function (done, _converse) {
var contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@montague.lit';
var message = 'fires: Your attention is required';
var nick = mock.chatroom_names[0],
msg = $msg({
from: room_jid+'/'+nick,
id: (new Date()).getTime(),
to: 'romeo@montague.lit',
type: 'groupchat'
}).c('body').t(message).tree();
view.model.onMessage(msg);
return test_utils.waitUntil(() => view.model.messages.length);
}).then(() => {
expect(u.isVisible(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count'))).toBeTruthy();
expect(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count').textContent).toBe('1');
done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
const muc_jid = 'kitchen@conference.shakespeare.lit';
await test_utils.openAndEnterChatRoom(_converse, 'kitchen@conference.shakespeare.lit', 'fires');
const view = _converse.chatboxviews.get(muc_jid);
view.model.set({'minimized': true});
const contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@montague.lit';
const message = 'fires: Your attention is required';
const nick = mock.chatroom_names[0];
const msg = $msg({
from: muc_jid+'/'+nick,
id: (new Date()).getTime(),
to: 'romeo@montague.lit',
type: 'groupchat'
}).c('body').t(message).tree();
view.model.onMessage(msg);
await test_utils.waitUntil(() => view.model.messages.length);
expect(u.isVisible(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count'))).toBeTruthy();
expect(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count').textContent).toBe('1');
done();
}));
});
}));
This diff is collapsed.
......@@ -47,7 +47,7 @@
async (done, _converse) => {
await test_utils.createContacts(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.api.chatviews.get('lounge@montague.lit');
if (!view.el.querySelectorAll('.chat-area').length) {
view.renderChatArea();
......@@ -173,7 +173,7 @@
async (done, _converse) => {
test_utils.createContacts(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
_converse.play_sounds = true;
spyOn(_converse, 'playSoundNotification');
const view = _converse.chatboxviews.get('lounge@montague.lit');
......
......@@ -250,7 +250,7 @@
'muc_unmoderated',
'muc_nonanonymous'
];
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo', features);
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo', features);
const view = _converse.chatboxviews.get('lounge@montague.lit');
await test_utils.waitUntil(() => initializedOMEMO(_converse));
......@@ -490,7 +490,7 @@
'muc_unmoderated',
'muc_nonanonymous'
];
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo', features);
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo', features);
const view = _converse.chatboxviews.get('lounge@montague.lit');
await test_utils.waitUntil(() => initializedOMEMO(_converse));
......@@ -1282,7 +1282,7 @@
['http://jabber.org/protocol/pubsub#publish-options']
);
// MEMO encryption works only in members-only conferences that are non-anonymous.
// MEMO encryption works only in members-only conferences that are non-anonymous.
const features = [
'http://jabber.org/protocol/muc',
'jabber:iq:register',
......@@ -1293,7 +1293,7 @@
'muc_unmoderated',
'muc_nonanonymous'
];
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo', features);
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo', features);
const view = _converse.chatboxviews.get('lounge@montague.lit');
await test_utils.waitUntil(() => initializedOMEMO(_converse));
......
......@@ -14,7 +14,7 @@
async function (done, _converse) {
test_utils.openControlBox();
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.chatboxviews.get('lounge@montague.lit'),
occupants = view.el.querySelector('.occupant-list');
_.rangeRight(3000, 0).forEach(i => {
......
......@@ -85,7 +85,7 @@
expect(_converse.session.get('push_enabled').length).toBe(1);
expect(_.includes(_converse.session.get('push_enabled'), 'romeo@montague.lit')).toBe(true);
test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'oldhag');
test_utils.openAndEnterChatRoom(_converse, 'coven@chat.shakespeare.lit', 'oldhag');
await test_utils.waitUntilDiscoConfirmed(
_converse, 'chat.shakespeare.lit',
[{'category': 'account', 'type':'registered'}],
......
......@@ -16,59 +16,54 @@
it("allows you to register your nickname in a room",
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
function (done, _converse) {
async function (done, _converse) {
let view;
const room_jid = 'coven@chat.shakespeare.lit';
test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'romeo')
.then(() => {
view = _converse.chatboxviews.get(room_jid);
const textarea = view.el.querySelector('.chat-textarea')
textarea.value = '/register';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
keyCode: 13
});
return test_utils.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
).pop());
}).then(stanza => {
expect(Strophe.serialize(stanza))
const muc_jid = 'coven@chat.shakespeare.lit';
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo')
const view = _converse.chatboxviews.get(muc_jid);
const textarea = view.el.querySelector('.chat-textarea')
textarea.value = '/register';
view.onKeyDown({
target: textarea,
preventDefault: _.noop,
keyCode: 13
});
let stanza = await test_utils.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[to="${muc_jid}"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
).pop());
expect(Strophe.serialize(stanza))
.toBe(`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" `+
`type="get" xmlns="jabber:client">`+
`<query xmlns="jabber:iq:register"/></iq>`);
view = _converse.chatboxviews.get(room_jid);
const result = $iq({
'from': view.model.get('jid'),
'id': stanza.getAttribute('id'),
'to': _converse.bare_jid,
'type': 'result',
}).c('query', {'type': 'jabber:iq:register'})
.c('x', {'xmlns': 'jabber:x:data', 'type': 'form'})
.c('field', {
'label': 'Desired Nickname',
'type': 'text-single',
'var': 'muc#register_roomnick'
}).c('required');
_converse.connection._dataRecv(test_utils.createRequest(result));
return test_utils.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
).pop());
}).then(stanza => {
expect(Strophe.serialize(stanza)).toBe(
`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
`<query xmlns="jabber:iq:register">`+
`<x type="submit" xmlns="jabber:x:data">`+
`<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#register</value></field>`+
`<field var="muc#register_roomnick"><value>romeo</value></field>`+
`</x>`+
`</query>`+
`</iq>`);
done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
const result = $iq({
'from': view.model.get('jid'),
'id': stanza.getAttribute('id'),
'to': _converse.bare_jid,
'type': 'result',
}).c('query', {'type': 'jabber:iq:register'})
.c('x', {'xmlns': 'jabber:x:data', 'type': 'form'})
.c('field', {
'label': 'Desired Nickname',
'type': 'text-single',
'var': 'muc#register_roomnick'
}).c('required');
_converse.connection._dataRecv(test_utils.createRequest(result));
stanza = await test_utils.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[to="${muc_jid}"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
).pop());
expect(Strophe.serialize(stanza)).toBe(
`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
`<query xmlns="jabber:iq:register">`+
`<x type="submit" xmlns="jabber:x:data">`+
`<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#register</value></field>`+
`<field var="muc#register_roomnick"><value>romeo</value></field>`+
`</x>`+
`</query>`+
`</iq>`);
done();
}));
});
......@@ -81,9 +76,9 @@
async function (done, _converse) {
const IQ_stanzas = _converse.connection.IQ_stanzas;
const room_jid = 'coven@chat.shakespeare.lit';
await test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'romeo');
const view = _converse.chatboxviews.get(room_jid);
const muc_jid = 'coven@chat.shakespeare.lit';
await test_utils.openAndEnterChatRoom(_converse, 'coven@chat.shakespeare.lit', 'romeo');
const view = _converse.chatboxviews.get(muc_jid);
let stanza = await test_utils.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
......
......@@ -56,7 +56,7 @@
{'connection': ['send']}, ['rosterGroupsFetched', 'chatBoxesFetched'], {'view_mode': 'fullscreen'},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
const view = _converse.chatboxviews.get('lounge@montague.lit');
const contact_jid = 'newguy@montague.lit';
......@@ -291,7 +291,7 @@
test_utils.openControlBox();
const room_jid = 'kitchen@conference.shakespeare.lit';
await test_utils.waitUntil(() => !_.isUndefined(_converse.rooms_list_view), 500);
await test_utils.openAndEnterChatRoom(_converse, 'kitchen', 'conference.shakespeare.lit', 'romeo');
await test_utils.openAndEnterChatRoom(_converse, 'kitchen@conference.shakespeare.lit', 'romeo');
const view = _converse.chatboxviews.get(room_jid);
view.model.set({'minimized': true});
const contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@montague.lit';
......
......@@ -49,32 +49,30 @@
return describe("Transcripts of chat logs", function () {
it("can be used to replay conversations",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
_converse.allow_non_roster_messaging = true;
test_utils.openAndEnterChatRoom(_converse, 'discuss', 'conference.conversejs.org', 'romeo').then(function () {
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
_.each(transcripts, function (transcript) {
var text = transcript();
var xml = Strophe.xmlHtmlNode(text);
_.each(xml.firstElementChild.children, function (el) {
_.each(el.children, function (el) {
if (el.nodeType === 3) {
return; // Ignore text
}
if (_.includes(IGNORED_TAGS, el.nodeName.toLowerCase())) {
return;
}
var _stanza = traverseElement(el);
_converse.connection._dataRecv(test_utils.createRequest(_stanza));
});
await test_utils.openAndEnterChatRoom(_converse, 'discuss@conference.conversejs.org', 'romeo');
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
_.each(transcripts, function (transcript) {
const text = transcript();
const xml = Strophe.xmlHtmlNode(text);
_.each(xml.firstElementChild.children, function (el) {
_.each(el.children, function (el) {
if (el.nodeType === 3) {
return; // Ignore text
}
if (_.includes(IGNORED_TAGS, el.nodeName.toLowerCase())) {
return;
}
const _stanza = traverseElement(el);
_converse.connection._dataRecv(test_utils.createRequest(_stanza));
});
});
done();
});
done();
}));
});
}));
......@@ -164,7 +164,9 @@
_converse.connection._dataRecv(utils.createRequest(features_stanza));
};
utils.openAndEnterChatRoom = async function (_converse, room, server, nick, features=[]) {
utils.openAndEnterChatRoom = async function (_converse, muc_jid, nick, features=[]) {
const room = Strophe.getNodeFromJid(muc_jid);
const server = Strophe.getDomainFromJid(muc_jid);
const room_jid = `${room}@${server}`.toLowerCase();
const stanzas = _converse.connection.IQ_stanzas;
await _converse.api.rooms.open(room_jid);
......
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