|
@@ -400,13 +400,34 @@
|
|
|
|
|
|
describe("A Groupchat", function () {
|
|
describe("A Groupchat", function () {
|
|
|
|
|
|
|
|
+
|
|
|
|
+ describe("upon being entered", function () {
|
|
|
|
+ it("will fetch the member list if muc_fetch_members is true",
|
|
|
|
+ mock.initConverse(
|
|
|
|
+ null, ['rosterGroupsFetched'], {'muc_fetch_members': true},
|
|
|
|
+ async function (done, _converse) {
|
|
|
|
+
|
|
|
|
+ spyOn(_converse.ChatRoomOccupants.prototype, 'fetchMembers').and.callThrough();
|
|
|
|
+ await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
|
|
|
|
+ let view = _converse.chatboxviews.get('lounge@montague.lit');
|
|
|
|
+ expect(view.model.occupants.fetchMembers).toHaveBeenCalled();
|
|
|
|
+
|
|
|
|
+ _converse.muc_fetch_members = false;
|
|
|
|
+ await test_utils.openAndEnterChatRoom(_converse, 'orchard@montague.lit', 'romeo');
|
|
|
|
+ view = _converse.chatboxviews.get('orchard@montague.lit');
|
|
|
|
+ expect(view.model.occupants.fetchMembers.calls.count()).toBe(1);
|
|
|
|
+ done();
|
|
|
|
+ }));
|
|
|
|
+ });
|
|
|
|
+
|
|
it("clears cached messages when it gets closed",
|
|
it("clears cached messages when it gets closed",
|
|
mock.initConverse(
|
|
mock.initConverse(
|
|
null, ['rosterGroupsFetched'], {},
|
|
null, ['rosterGroupsFetched'], {},
|
|
async function (done, _converse) {
|
|
async function (done, _converse) {
|
|
|
|
|
|
- await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
|
|
|
|
- const view = _converse.chatboxviews.get('lounge@montague.lit');
|
|
|
|
|
|
+ const muc_jid = 'lounge@montague.lit';
|
|
|
|
+ await test_utils.openAndEnterChatRoom(_converse, muc_jid , 'romeo');
|
|
|
|
+ const view = _converse.chatboxviews.get(muc_jid);
|
|
const message = 'Hello world',
|
|
const message = 'Hello world',
|
|
nick = mock.chatroom_names[0],
|
|
nick = mock.chatroom_names[0],
|
|
msg = $msg({
|
|
msg = $msg({
|
|
@@ -4185,14 +4206,10 @@
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
|
async function (done, _converse) {
|
|
async function (done, _converse) {
|
|
|
|
|
|
- var sent_IQs = [], IQ_ids = [];
|
|
|
|
|
|
+ spyOn(_converse.ChatRoomOccupants.prototype, 'fetchMembers').and.callThrough();
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
const muc_jid = 'coven@chat.shakespeare.lit';
|
|
const muc_jid = 'coven@chat.shakespeare.lit';
|
|
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
- sent_IQs.push(iq);
|
|
|
|
- IQ_ids.push(sendIQ.bind(this)(iq, callback, errback));
|
|
|
|
- });
|
|
|
|
|
|
|
|
await _converse.api.rooms.open(muc_jid, {'nick': 'romeo'});
|
|
await _converse.api.rooms.open(muc_jid, {'nick': 'romeo'});
|
|
let stanza = await u.waitUntil(() => _.filter(
|
|
let stanza = await u.waitUntil(() => _.filter(
|
|
@@ -4206,11 +4223,18 @@
|
|
`<query xmlns="http://jabber.org/protocol/disco#info"/>`+
|
|
`<query xmlns="http://jabber.org/protocol/disco#info"/>`+
|
|
`</iq>`);
|
|
`</iq>`);
|
|
|
|
|
|
- const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
|
|
|
|
|
|
+ const sent_IQs = _converse.connection.IQ_stanzas;
|
|
|
|
+ const last_sent_IQ = sent_IQs.pop();
|
|
|
|
+ expect(Strophe.serialize(last_sent_IQ)).toBe(
|
|
|
|
+ `<iq from="romeo@montague.lit/orchard" id="${last_sent_IQ.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="get" xmlns="jabber:client">`+
|
|
|
|
+ `<query xmlns="http://jabber.org/protocol/disco#info"/>`+
|
|
|
|
+ `</iq>`);
|
|
|
|
+
|
|
|
|
+ const view = _converse.chatboxviews.get(muc_jid);
|
|
// State that the chat is members-only via the features IQ
|
|
// State that the chat is members-only via the features IQ
|
|
const features_stanza = $iq({
|
|
const features_stanza = $iq({
|
|
from: 'coven@chat.shakespeare.lit',
|
|
from: 'coven@chat.shakespeare.lit',
|
|
- 'id': IQ_ids.pop(),
|
|
|
|
|
|
+ 'id': last_sent_IQ.getAttribute('id'),
|
|
'to': 'romeo@montague.lit/desktop',
|
|
'to': 'romeo@montague.lit/desktop',
|
|
'type': 'result'
|
|
'type': 'result'
|
|
})
|
|
})
|
|
@@ -4244,24 +4268,23 @@
|
|
|
|
|
|
// Check in reverse order that we requested all three lists
|
|
// Check in reverse order that we requested all three lists
|
|
// (member, owner and admin).
|
|
// (member, owner and admin).
|
|
- const admin_iq_id = IQ_ids.pop();
|
|
|
|
- const owner_iq_id = IQ_ids.pop();
|
|
|
|
- const member_iq_id = IQ_ids.pop();
|
|
|
|
-
|
|
|
|
- expect(sent_IQs.pop().toLocaleString()).toBe(
|
|
|
|
- `<iq id="${admin_iq_id}" to="coven@chat.shakespeare.lit" type="get" xmlns="jabber:client">`+
|
|
|
|
|
|
+ const admin_iq = sent_IQs.pop();
|
|
|
|
+ const owner_iq = sent_IQs.pop();
|
|
|
|
+ const member_iq = sent_IQs.pop();
|
|
|
|
+ expect(Strophe.serialize(admin_iq)).toBe(
|
|
|
|
+ `<iq id="${admin_iq.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="get" xmlns="jabber:client">`+
|
|
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
|
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
|
`<item affiliation="admin"/>`+
|
|
`<item affiliation="admin"/>`+
|
|
`</query>`+
|
|
`</query>`+
|
|
`</iq>`);
|
|
`</iq>`);
|
|
- expect(sent_IQs.pop().toLocaleString()).toBe(
|
|
|
|
- `<iq id="${owner_iq_id}" to="coven@chat.shakespeare.lit" type="get" xmlns="jabber:client">`+
|
|
|
|
|
|
+ expect(Strophe.serialize(owner_iq)).toBe(
|
|
|
|
+ `<iq id="${owner_iq.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="get" xmlns="jabber:client">`+
|
|
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
|
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
|
`<item affiliation="owner"/>`+
|
|
`<item affiliation="owner"/>`+
|
|
`</query>`+
|
|
`</query>`+
|
|
`</iq>`);
|
|
`</iq>`);
|
|
- expect(sent_IQs.pop().toLocaleString()).toBe(
|
|
|
|
- `<iq id="${member_iq_id}" to="coven@chat.shakespeare.lit" type="get" xmlns="jabber:client">`+
|
|
|
|
|
|
+ expect(Strophe.serialize(member_iq)).toBe(
|
|
|
|
+ `<iq id="${member_iq.getAttribute('id')}" to="coven@chat.shakespeare.lit" type="get" xmlns="jabber:client">`+
|
|
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
|
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
|
`<item affiliation="member"/>`+
|
|
`<item affiliation="member"/>`+
|
|
`</query>`+
|
|
`</query>`+
|
|
@@ -4281,9 +4304,9 @@
|
|
* </query>
|
|
* </query>
|
|
* </iq>
|
|
* </iq>
|
|
*/
|
|
*/
|
|
- var member_list_stanza = $iq({
|
|
|
|
|
|
+ const member_list_stanza = $iq({
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
- 'id': member_iq_id,
|
|
|
|
|
|
+ 'id': member_iq.getAttribute('id'),
|
|
'to': 'romeo@montague.lit/orchard',
|
|
'to': 'romeo@montague.lit/orchard',
|
|
'type': 'result'
|
|
'type': 'result'
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
@@ -4295,9 +4318,9 @@
|
|
});
|
|
});
|
|
_converse.connection._dataRecv(test_utils.createRequest(member_list_stanza));
|
|
_converse.connection._dataRecv(test_utils.createRequest(member_list_stanza));
|
|
|
|
|
|
- var admin_list_stanza = $iq({
|
|
|
|
|
|
+ const admin_list_stanza = $iq({
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
- 'id': admin_iq_id,
|
|
|
|
|
|
+ 'id': admin_iq.getAttribute('id'),
|
|
'to': 'romeo@montague.lit/orchard',
|
|
'to': 'romeo@montague.lit/orchard',
|
|
'type': 'result'
|
|
'type': 'result'
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
@@ -4308,9 +4331,9 @@
|
|
});
|
|
});
|
|
_converse.connection._dataRecv(test_utils.createRequest(admin_list_stanza));
|
|
_converse.connection._dataRecv(test_utils.createRequest(admin_list_stanza));
|
|
|
|
|
|
- var owner_list_stanza = $iq({
|
|
|
|
|
|
+ const owner_list_stanza = $iq({
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
'from': 'coven@chat.shakespeare.lit',
|
|
- 'id': owner_iq_id,
|
|
|
|
|
|
+ 'id': owner_iq.getAttribute('id'),
|
|
'to': 'romeo@montague.lit/orchard',
|
|
'to': 'romeo@montague.lit/orchard',
|
|
'type': 'result'
|
|
'type': 'result'
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
}).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
|
|
@@ -4319,20 +4342,31 @@
|
|
'jid': 'crone1@shakespeare.lit',
|
|
'jid': 'crone1@shakespeare.lit',
|
|
});
|
|
});
|
|
_converse.connection._dataRecv(test_utils.createRequest(owner_list_stanza));
|
|
_converse.connection._dataRecv(test_utils.createRequest(owner_list_stanza));
|
|
- await u.waitUntil(() => IQ_ids.length, 300);
|
|
|
|
|
|
+
|
|
stanza = await u.waitUntil(() => _.filter(
|
|
stanza = await u.waitUntil(() => _.filter(
|
|
IQ_stanzas,
|
|
IQ_stanzas,
|
|
iq => iq.querySelector(
|
|
iq => iq.querySelector(
|
|
`iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/muc#admin"]`
|
|
`iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/muc#admin"]`
|
|
)).pop());
|
|
)).pop());
|
|
expect(stanza.outerHTML,
|
|
expect(stanza.outerHTML,
|
|
- `<iq id="${IQ_ids.pop()}" 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="http://jabber.org/protocol/muc#admin">`+
|
|
`<query xmlns="http://jabber.org/protocol/muc#admin">`+
|
|
`<item affiliation="member" jid="${invitee_jid}">`+
|
|
`<item affiliation="member" jid="${invitee_jid}">`+
|
|
`<reason>Please join this groupchat</reason>`+
|
|
`<reason>Please join this groupchat</reason>`+
|
|
`</item>`+
|
|
`</item>`+
|
|
`</query>`+
|
|
`</query>`+
|
|
`</iq>`);
|
|
`</iq>`);
|
|
|
|
+
|
|
|
|
+ const result = $iq({
|
|
|
|
+ 'from': 'coven@chat.shakespeare.lit',
|
|
|
|
+ 'id': stanza.getAttribute('id'),
|
|
|
|
+ 'to': 'romeo@montague.lit/orchard',
|
|
|
|
+ 'type': 'result'
|
|
|
|
+ });
|
|
|
|
+ _converse.connection._dataRecv(test_utils.createRequest(result));
|
|
|
|
+
|
|
|
|
+ await u.waitUntil(() => view.model.occupants.fetchMembers.calls.count());
|
|
|
|
+
|
|
// Finally check that the user gets invited.
|
|
// Finally check that the user gets invited.
|
|
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
|
|
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
|
|
`<message from="romeo@montague.lit/orchard" id="${sent_id}" to="${invitee_jid}" xmlns="jabber:client">`+
|
|
`<message from="romeo@montague.lit/orchard" id="${sent_id}" to="${invitee_jid}" xmlns="jabber:client">`+
|