2021-01-29 14:15:27 +01:00
|
|
|
/*global mock, converse */
|
2020-04-13 15:19:21 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const u = converse.env.utils;
|
2020-04-13 15:19:21 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
describe("A XEP-0317 MUC Hat", function () {
|
2020-04-13 15:19:21 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("can be included in a presence stanza",
|
2021-01-29 14:15:27 +01:00
|
|
|
mock.initConverse(['chatBoxesFetched'], {}, async function (done, _converse) {
|
2020-04-22 13:11:48 +02:00
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
|
|
|
const view = _converse.chatboxviews.get(muc_jid);
|
|
|
|
const hat1_id = u.getUniqueId();
|
|
|
|
const hat2_id = u.getUniqueId();
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(u.toStanza(`
|
|
|
|
<presence from="${muc_jid}/Terry" id="${u.getUniqueId()}" to="${_converse.jid}">
|
|
|
|
<x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
<item affiliation="member" role="participant"/>
|
|
|
|
</x>
|
|
|
|
<hats xmlns="xmpp:prosody.im/protocol/hats:1">
|
|
|
|
<hat title="Teacher's Assistant" id="${hat1_id}"/>
|
|
|
|
<hat title="Dark Mage" id="${hat2_id}"/>
|
|
|
|
</hats>
|
|
|
|
</presence>
|
|
|
|
`)));
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
|
2020-04-22 13:11:48 +02:00
|
|
|
"romeo and Terry have entered the groupchat");
|
2020-04-13 15:19:21 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
let hats = view.model.getOccupant("Terry").get('hats');
|
|
|
|
expect(hats.length).toBe(2);
|
|
|
|
expect(hats.map(h => h.title).join(' ')).toBe("Teacher's Assistant Dark Mage");
|
2020-04-13 15:19:21 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
_converse.connection._dataRecv(mock.createRequest(u.toStanza(`
|
|
|
|
<message type="groupchat" from="${muc_jid}/Terry" id="${u.getUniqueId()}" to="${_converse.jid}">
|
|
|
|
<body>Hello world</body>
|
|
|
|
</message>
|
|
|
|
`)));
|
2020-04-13 15:19:21 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
const msg_el = await u.waitUntil(() => view.querySelector('.chat-msg'));
|
2020-04-22 13:11:48 +02:00
|
|
|
let badges = Array.from(msg_el.querySelectorAll('.badge'));
|
|
|
|
expect(badges.length).toBe(2);
|
|
|
|
expect(badges.map(b => b.textContent.trim()).join(' ' )).toBe("Teacher's Assistant Dark Mage");
|
2020-04-13 15:19:21 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const hat3_id = u.getUniqueId();
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(u.toStanza(`
|
|
|
|
<presence from="${muc_jid}/Terry" id="${u.getUniqueId()}" to="${_converse.jid}">
|
|
|
|
<x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
<item affiliation="member" role="participant"/>
|
|
|
|
</x>
|
|
|
|
<hats xmlns="xmpp:prosody.im/protocol/hats:1">
|
|
|
|
<hat title="Teacher's Assistant" id="${hat1_id}"/>
|
|
|
|
<hat title="Dark Mage" id="${hat2_id}"/>
|
|
|
|
<hat title="Mad hatter" id="${hat3_id}"/>
|
|
|
|
</hats>
|
|
|
|
</presence>
|
|
|
|
`)));
|
2020-04-13 15:19:21 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => view.model.getOccupant("Terry").get('hats').length === 3);
|
|
|
|
hats = view.model.getOccupant("Terry").get('hats');
|
|
|
|
expect(hats.map(h => h.title).join(' ')).toBe("Teacher's Assistant Dark Mage Mad hatter");
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => view.querySelectorAll('.chat-msg .badge').length === 3, 1000);
|
|
|
|
badges = Array.from(view.querySelectorAll('.chat-msg .badge'));
|
2020-04-22 13:11:48 +02:00
|
|
|
expect(badges.map(b => b.textContent.trim()).join(' ' )).toBe("Teacher's Assistant Dark Mage Mad hatter");
|
|
|
|
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(u.toStanza(`
|
|
|
|
<presence from="${muc_jid}/Terry" id="${u.getUniqueId()}" to="${_converse.jid}">
|
|
|
|
<x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
<item affiliation="member" role="participant"/>
|
|
|
|
</x>
|
|
|
|
</presence>
|
|
|
|
`)));
|
|
|
|
await u.waitUntil(() => view.model.getOccupant("Terry").get('hats').length === 0);
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => view.querySelectorAll('.chat-msg .badge').length === 0);
|
2020-04-22 13:11:48 +02:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
})
|