|
@@ -1,9 +1,6 @@
|
|
-/*global mock, converse, _ */
|
|
|
|
|
|
+/*global mock, converse */
|
|
|
|
|
|
-const $iq = converse.env.$iq,
|
|
|
|
- Strophe = converse.env.Strophe,
|
|
|
|
- sizzle = converse.env.sizzle,
|
|
|
|
- u = converse.env.utils;
|
|
|
|
|
|
+const { $iq, Strophe, sizzle, u } = converse.env;
|
|
|
|
|
|
describe("Chatrooms", function () {
|
|
describe("Chatrooms", function () {
|
|
|
|
|
|
@@ -24,12 +21,11 @@ describe("Chatrooms", function () {
|
|
preventDefault: function preventDefault () {},
|
|
preventDefault: function preventDefault () {},
|
|
keyCode: 13
|
|
keyCode: 13
|
|
});
|
|
});
|
|
- let stanza = await u.waitUntil(() => _.filter(
|
|
|
|
- _converse.connection.IQ_stanzas,
|
|
|
|
|
|
+ let stanza = await u.waitUntil(() => _converse.connection.IQ_stanzas.filter(
|
|
iq => sizzle(`iq[to="${muc_jid}"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
iq => sizzle(`iq[to="${muc_jid}"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
).pop());
|
|
).pop());
|
|
expect(Strophe.serialize(stanza))
|
|
expect(Strophe.serialize(stanza))
|
|
- .toBe(`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" `+
|
|
|
|
|
|
+ .toBe(`<iq id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" `+
|
|
`type="get" xmlns="jabber:client">`+
|
|
`type="get" xmlns="jabber:client">`+
|
|
`<query xmlns="jabber:iq:register"/></iq>`);
|
|
`<query xmlns="jabber:iq:register"/></iq>`);
|
|
const result = $iq({
|
|
const result = $iq({
|
|
@@ -45,64 +41,12 @@ describe("Chatrooms", function () {
|
|
'var': 'muc#register_roomnick'
|
|
'var': 'muc#register_roomnick'
|
|
}).c('required');
|
|
}).c('required');
|
|
_converse.connection._dataRecv(mock.createRequest(result));
|
|
_converse.connection._dataRecv(mock.createRequest(result));
|
|
- stanza = await u.waitUntil(() => _.filter(
|
|
|
|
- _converse.connection.IQ_stanzas,
|
|
|
|
|
|
+ stanza = await u.waitUntil(() => _converse.connection.IQ_stanzas.filter(
|
|
iq => sizzle(`iq[to="${muc_jid}"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
iq => sizzle(`iq[to="${muc_jid}"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
|
|
).pop());
|
|
).pop());
|
|
|
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
|
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();
|
|
|
|
- }));
|
|
|
|
-
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- describe("The auto_register_muc_nickname option", function () {
|
|
|
|
-
|
|
|
|
- it("allows you to automatically register your nickname when joining a room",
|
|
|
|
- mock.initConverse(['chatBoxesFetched'], {'auto_register_muc_nickname': true},
|
|
|
|
- async function (done, _converse) {
|
|
|
|
-
|
|
|
|
- const muc_jid = 'coven@chat.shakespeare.lit';
|
|
|
|
- await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
|
|
|
- const view = _converse.chatboxviews.get(muc_jid);
|
|
|
|
-
|
|
|
|
- let stanza = await u.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(mock.createRequest(result));
|
|
|
|
- stanza = await u.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">`+
|
|
|
|
|
|
+ `<iq id="${stanza.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
|
|
`<query xmlns="jabber:iq:register">`+
|
|
`<query xmlns="jabber:iq:register">`+
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
`<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#register</value></field>`+
|
|
`<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#register</value></field>`+
|