2018-09-04 11:39:27 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define(["jasmine", "mock", "test-utils" ], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
|
|
|
const _ = converse.env._,
|
|
|
|
$iq = converse.env.$iq,
|
2018-09-13 14:22:59 +02:00
|
|
|
$pres = converse.env.$pres,
|
2018-09-04 11:39:27 +02:00
|
|
|
Strophe = converse.env.Strophe,
|
2018-09-12 12:33:28 +02:00
|
|
|
sizzle = converse.env.sizzle,
|
2018-09-04 11:39:27 +02:00
|
|
|
u = converse.env.utils;
|
|
|
|
|
2018-09-12 07:20:57 +02:00
|
|
|
describe("Chatrooms", function () {
|
2018-09-12 15:06:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
describe("The /register commmand", function () {
|
|
|
|
|
|
|
|
it("allows you to register your nickname in a room",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-09-12 15:06:08 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
|
|
|
|
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';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-09-12 15:06:08 +02:00
|
|
|
target: textarea,
|
|
|
|
preventDefault: _.noop,
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2018-10-02 17:01:39 +02:00
|
|
|
return test_utils.waitUntil(() => _.filter(
|
2018-09-12 15:06:08 +02:00
|
|
|
_converse.connection.IQ_stanzas,
|
2019-05-20 12:38:33 +02:00
|
|
|
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
|
2018-10-02 17:01:39 +02:00
|
|
|
).pop());
|
2019-05-20 12:38:33 +02:00
|
|
|
}).then(stanza => {
|
|
|
|
expect(Strophe.serialize(stanza))
|
2019-06-03 07:58:51 +02:00
|
|
|
.toBe(`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" `+
|
2018-10-02 17:01:39 +02:00
|
|
|
`type="get" xmlns="jabber:client">`+
|
2018-09-12 15:06:08 +02:00
|
|
|
`<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));
|
2018-10-02 17:01:39 +02:00
|
|
|
return test_utils.waitUntil(() => _.filter(
|
2018-09-12 15:06:08 +02:00
|
|
|
_converse.connection.IQ_stanzas,
|
2019-05-20 12:38:33 +02:00
|
|
|
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
|
2018-10-02 17:01:39 +02:00
|
|
|
).pop());
|
2019-05-20 12:38:33 +02:00
|
|
|
}).then(stanza => {
|
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
|
2018-09-12 15:06:08 +02:00
|
|
|
`<query xmlns="jabber:iq:register">`+
|
2018-10-02 17:01:39 +02:00
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
2018-09-12 15:06:08 +02:00
|
|
|
`<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));
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-09-12 07:20:57 +02:00
|
|
|
describe("The auto_register_muc_nickname option", function () {
|
2018-09-04 11:39:27 +02:00
|
|
|
|
2018-09-12 15:06:08 +02:00
|
|
|
it("allows you to automatically register your nickname when joining a room",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-09-12 07:20:57 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
|
2019-07-01 10:44:59 +02:00
|
|
|
async function (done, _converse) {
|
2018-09-04 11:39:27 +02:00
|
|
|
|
2019-05-20 12:38:33 +02:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
2018-09-12 07:20:57 +02:00
|
|
|
const room_jid = 'coven@chat.shakespeare.lit';
|
2019-07-01 10:44:59 +02:00
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'romeo');
|
|
|
|
const view = _converse.chatboxviews.get(room_jid);
|
|
|
|
|
|
|
|
let stanza = await 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());
|
|
|
|
|
|
|
|
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>`);
|
|
|
|
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="coven@chat.shakespeare.lit"][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();
|
2018-09-12 07:20:57 +02:00
|
|
|
}));
|
|
|
|
});
|
2018-09-04 11:39:27 +02:00
|
|
|
});
|
|
|
|
}));
|