2020-12-02 18:37:32 +01:00
|
|
|
/*global mock, converse */
|
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
// See: https://xmpp.org/rfcs/rfc3921.html
|
2017-02-20 20:47:08 +01:00
|
|
|
|
2020-04-28 12:19:22 +02:00
|
|
|
const original_timeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
describe("A sent presence stanza", function () {
|
2017-02-22 22:13:23 +01:00
|
|
|
|
2020-04-28 12:19:22 +02:00
|
|
|
beforeEach(() => (jasmine.DEFAULT_TIMEOUT_INTERVAL = 7000));
|
|
|
|
afterEach(() => (jasmine.DEFAULT_TIMEOUT_INTERVAL = original_timeout));
|
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("includes a entity capabilities node",
|
2021-01-26 14:01:37 +01:00
|
|
|
mock.initConverse([], {}, async (done, _converse) => {
|
2018-05-11 13:31:48 +02:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
await mock.waitForRoster(_converse, 'current', 0);
|
2020-04-22 13:11:48 +02:00
|
|
|
_converse.api.disco.own.identities.clear();
|
|
|
|
_converse.api.disco.own.features.clear();
|
2018-05-11 13:31:48 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
_converse.api.disco.own.identities.add("client", "pc", "Exodus 0.9.1");
|
|
|
|
_converse.api.disco.own.features.add("http://jabber.org/protocol/caps");
|
|
|
|
_converse.api.disco.own.features.add("http://jabber.org/protocol/disco#info");
|
|
|
|
_converse.api.disco.own.features.add("http://jabber.org/protocol/disco#items");
|
|
|
|
_converse.api.disco.own.features.add("http://jabber.org/protocol/muc");
|
2018-05-11 13:31:48 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const presence = _converse.xmppstatus.constructPresence();
|
|
|
|
expect(presence.toLocaleString()).toBe(
|
|
|
|
`<presence xmlns="jabber:client">`+
|
|
|
|
`<priority>0</priority>`+
|
|
|
|
`<c hash="sha-1" node="https://conversejs.org" ver="QgayPKawpkPSDYmwT/WM94uAlu0=" xmlns="http://jabber.org/protocol/caps"/>`+
|
|
|
|
`</presence>`)
|
|
|
|
done();
|
|
|
|
}));
|
2018-05-11 13:31:48 +02:00
|
|
|
|
2020-09-04 12:51:03 +02:00
|
|
|
it("has a given priority", mock.initConverse(['statusInitialized'], {}, (done, _converse) => {
|
2020-04-22 13:11:48 +02:00
|
|
|
let pres = _converse.xmppstatus.constructPresence('online', null, 'Hello world');
|
|
|
|
expect(pres.toLocaleString()).toBe(
|
|
|
|
`<presence xmlns="jabber:client">`+
|
|
|
|
`<status>Hello world</status>`+
|
|
|
|
`<priority>0</priority>`+
|
2020-10-14 13:09:33 +02:00
|
|
|
`<c hash="sha-1" node="https://conversejs.org" ver="PxXfr6uz8ClMWIga0OB/MhKNH/M=" xmlns="http://jabber.org/protocol/caps"/>`+
|
2020-04-22 13:11:48 +02:00
|
|
|
`</presence>`
|
|
|
|
);
|
|
|
|
_converse.priority = 2;
|
|
|
|
pres = _converse.xmppstatus.constructPresence('away', null, 'Going jogging');
|
|
|
|
expect(pres.toLocaleString()).toBe(
|
|
|
|
`<presence xmlns="jabber:client">`+
|
|
|
|
`<show>away</show>`+
|
|
|
|
`<status>Going jogging</status>`+
|
|
|
|
`<priority>2</priority>`+
|
2020-10-14 13:09:33 +02:00
|
|
|
`<c hash="sha-1" node="https://conversejs.org" ver="PxXfr6uz8ClMWIga0OB/MhKNH/M=" xmlns="http://jabber.org/protocol/caps"/>`+
|
2020-04-22 13:11:48 +02:00
|
|
|
`</presence>`
|
|
|
|
);
|
|
|
|
|
|
|
|
delete _converse.priority;
|
|
|
|
pres = _converse.xmppstatus.constructPresence('dnd', null, 'Doing taxes');
|
|
|
|
expect(pres.toLocaleString()).toBe(
|
|
|
|
`<presence xmlns="jabber:client">`+
|
|
|
|
`<show>dnd</show>`+
|
|
|
|
`<status>Doing taxes</status>`+
|
|
|
|
`<priority>0</priority>`+
|
2020-10-14 13:09:33 +02:00
|
|
|
`<c hash="sha-1" node="https://conversejs.org" ver="PxXfr6uz8ClMWIga0OB/MhKNH/M=" xmlns="http://jabber.org/protocol/caps"/>`+
|
2020-04-22 13:11:48 +02:00
|
|
|
`</presence>`
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("includes the saved status message",
|
2021-01-26 14:01:37 +01:00
|
|
|
mock.initConverse([], {}, async (done, _converse) => {
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
const { u, Strophe } = converse.env;
|
|
|
|
mock.openControlBox(_converse);
|
|
|
|
spyOn(_converse.connection, 'send').and.callThrough();
|
|
|
|
|
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
2020-12-08 12:54:14 +01:00
|
|
|
const change_status_el = await u.waitUntil(() => cbview.querySelector('.change-status'));
|
2020-06-01 16:05:00 +02:00
|
|
|
change_status_el.click()
|
2020-12-02 18:37:32 +01:00
|
|
|
let modal = _converse.api.modal.get('modal-status-change');
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
|
|
|
const msg = 'My custom status';
|
|
|
|
modal.el.querySelector('input[name="status_message"]').value = msg;
|
|
|
|
modal.el.querySelector('[type="submit"]').click();
|
|
|
|
|
|
|
|
const sent_stanzas = _converse.connection.sent_stanzas;
|
|
|
|
let sent_presence = await u.waitUntil(() => sent_stanzas.filter(s => Strophe.serialize(s).match('presence')).pop());
|
|
|
|
expect(Strophe.serialize(sent_presence))
|
|
|
|
.toBe(`<presence xmlns="jabber:client">`+
|
|
|
|
`<status>My custom status</status>`+
|
2018-10-02 17:01:39 +02:00
|
|
|
`<priority>0</priority>`+
|
2020-10-14 13:09:33 +02:00
|
|
|
`<c hash="sha-1" node="https://conversejs.org" ver="PxXfr6uz8ClMWIga0OB/MhKNH/M=" xmlns="http://jabber.org/protocol/caps"/>`+
|
2020-04-22 13:11:48 +02:00
|
|
|
`</presence>`)
|
|
|
|
await u.waitUntil(() => modal.el.getAttribute('aria-hidden') === "true");
|
|
|
|
await u.waitUntil(() => !u.isVisible(modal.el));
|
2020-12-02 18:37:32 +01:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
cbview.querySelector('.change-status').click()
|
2020-12-02 18:37:32 +01:00
|
|
|
modal = _converse.api.modal.get('modal-status-change');
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => modal.el.getAttribute('aria-hidden') === "false", 1000);
|
|
|
|
modal.el.querySelector('label[for="radio-busy"]').click(); // Change status to "dnd"
|
|
|
|
modal.el.querySelector('[type="submit"]').click();
|
|
|
|
await u.waitUntil(() => sent_stanzas.filter(s => Strophe.serialize(s).match('presence')).length === 2);
|
|
|
|
sent_presence = sent_stanzas.filter(s => Strophe.serialize(s).match('presence')).pop();
|
|
|
|
expect(Strophe.serialize(sent_presence))
|
|
|
|
.toBe(
|
2018-10-02 17:01:39 +02:00
|
|
|
`<presence xmlns="jabber:client">`+
|
|
|
|
`<show>dnd</show>`+
|
2020-04-22 13:11:48 +02:00
|
|
|
`<status>My custom status</status>`+
|
2018-10-02 17:01:39 +02:00
|
|
|
`<priority>0</priority>`+
|
2020-10-14 13:09:33 +02:00
|
|
|
`<c hash="sha-1" node="https://conversejs.org" ver="PxXfr6uz8ClMWIga0OB/MhKNH/M=" xmlns="http://jabber.org/protocol/caps"/>`+
|
2020-04-22 13:11:48 +02:00
|
|
|
`</presence>`)
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
});
|
2017-02-22 22:13:23 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
describe("A received presence stanza", function () {
|
2017-02-20 20:47:08 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("has its priority taken into account",
|
2021-01-26 14:01:37 +01:00
|
|
|
mock.initConverse([], {}, async (done, _converse) => {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const u = converse.env.utils;
|
|
|
|
mock.openControlBox(_converse);
|
|
|
|
await mock.waitForRoster(_converse, 'current');
|
|
|
|
const contact_jid = mock.cur_names[8].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
const contact = await _converse.api.contacts.get(contact_jid);
|
|
|
|
let stanza = u.toStanza(`
|
|
|
|
<presence xmlns="jabber:client"
|
|
|
|
to="romeo@montague.lit/converse.js-21770972"
|
|
|
|
from="${contact_jid}/priority-1-resource">
|
|
|
|
<priority>1</priority>
|
|
|
|
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" ext="voice-v1 camera-v1 video-v1"
|
|
|
|
ver="AcN1/PEN8nq7AHD+9jpxMV4U6YM=" node="http://pidgin.im/"/>
|
|
|
|
<x xmlns="vcard-temp:x:update">
|
|
|
|
<photo>ce51d94f7f22b87a21274abb93710b9eb7cc1c65</photo>
|
|
|
|
</x>
|
|
|
|
<delay xmlns="urn:xmpp:delay" stamp="2017-02-15T20:26:05Z" from="${contact_jid}/priority-1-resource"/>
|
|
|
|
</presence>`);
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(contact.presence.get('show')).toBe('online');
|
|
|
|
expect(contact.presence.resources.length).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('show')).toBe('online');
|
2017-02-20 20:47:08 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' from="'+contact_jid+'/priority-0-resource">'+
|
|
|
|
' <status/>'+
|
|
|
|
' <priority>0</priority>'+
|
|
|
|
' <show>xa</show>'+
|
|
|
|
' <c xmlns="http://jabber.org/protocol/caps" ver="GyIX/Kpa4ScVmsZCxRBboJlLAYU=" hash="sha-1"'+
|
|
|
|
' node="http://www.igniterealtime.org/projects/smack/"/>'+
|
|
|
|
' <delay xmlns="urn:xmpp:delay" stamp="2017-02-15T17:02:24Z" from="'+contact_jid+'/priority-0-resource"/>'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(contact.presence.get('show')).toBe('online');
|
2019-01-28 11:24:46 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
expect(contact.presence.resources.length).toBe(2);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('priority')).toBe(0);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('show')).toBe('xa');
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('show')).toBe('online');
|
2017-02-20 22:27:34 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' from="'+contact_jid+'/priority-2-resource">'+
|
|
|
|
' <priority>2</priority>'+
|
|
|
|
' <show>dnd</show>'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(contact.presence.get('show')).toBe('dnd');
|
|
|
|
expect(contact.presence.resources.length).toBe(3);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('priority')).toBe(0);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('show')).toBe('xa');
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('show')).toBe('online');
|
|
|
|
expect(contact.presence.resources.get('priority-2-resource').get('priority')).toBe(2);
|
|
|
|
expect(contact.presence.resources.get('priority-2-resource').get('show')).toBe('dnd');
|
2017-02-20 22:37:06 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' from="'+contact_jid+'/priority-3-resource">'+
|
|
|
|
' <priority>3</priority>'+
|
|
|
|
' <show>away</show>'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(_converse.roster.get(contact_jid).presence.get('show')).toBe('away');
|
|
|
|
expect(contact.presence.resources.length).toBe(4);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('priority')).toBe(0);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('show')).toBe('xa');
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('show')).toBe('online');
|
|
|
|
expect(contact.presence.resources.get('priority-2-resource').get('priority')).toBe(2);
|
|
|
|
expect(contact.presence.resources.get('priority-2-resource').get('show')).toBe('dnd');
|
|
|
|
expect(contact.presence.resources.get('priority-3-resource').get('priority')).toBe(3);
|
|
|
|
expect(contact.presence.resources.get('priority-3-resource').get('show')).toBe('away');
|
2017-02-20 22:37:06 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' from="'+contact_jid+'/older-priority-1-resource">'+
|
|
|
|
' <priority>1</priority>'+
|
|
|
|
' <show>dnd</show>'+
|
|
|
|
' <delay xmlns="urn:xmpp:delay" stamp="2017-02-15T15:02:24Z" from="'+contact_jid+'/older-priority-1-resource"/>'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(_converse.roster.get(contact_jid).presence.get('show')).toBe('away');
|
|
|
|
expect(contact.presence.resources.length).toBe(5);
|
|
|
|
expect(contact.presence.resources.get('older-priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('older-priority-1-resource').get('show')).toBe('dnd');
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('priority')).toBe(0);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('show')).toBe('xa');
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('show')).toBe('online');
|
|
|
|
expect(contact.presence.resources.get('priority-2-resource').get('priority')).toBe(2);
|
|
|
|
expect(contact.presence.resources.get('priority-2-resource').get('show')).toBe('dnd');
|
|
|
|
expect(contact.presence.resources.get('priority-3-resource').get('priority')).toBe(3);
|
|
|
|
expect(contact.presence.resources.get('priority-3-resource').get('show')).toBe('away');
|
2017-02-20 22:37:06 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' type="unavailable"'+
|
|
|
|
' from="'+contact_jid+'/priority-3-resource">'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(_converse.roster.get(contact_jid).presence.get('show')).toBe('dnd');
|
|
|
|
expect(contact.presence.resources.length).toBe(4);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('priority')).toBe(0);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('show')).toBe('xa');
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('show')).toBe('online');
|
|
|
|
expect(contact.presence.resources.get('priority-2-resource').get('priority')).toBe(2);
|
|
|
|
expect(contact.presence.resources.get('priority-2-resource').get('show')).toBe('dnd');
|
|
|
|
expect(contact.presence.resources.get('older-priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('older-priority-1-resource').get('show')).toBe('dnd');
|
2017-02-20 22:27:34 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' type="unavailable"'+
|
|
|
|
' from="'+contact_jid+'/priority-2-resource">'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(_converse.roster.get(contact_jid).presence.get('show')).toBe('online');
|
|
|
|
expect(contact.presence.resources.length).toBe(3);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('priority')).toBe(0);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('show')).toBe('xa');
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-1-resource').get('show')).toBe('online');
|
|
|
|
expect(contact.presence.resources.get('older-priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('older-priority-1-resource').get('show')).toBe('dnd');
|
2017-02-21 22:13:49 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' type="unavailable"'+
|
|
|
|
' from="'+contact_jid+'/priority-1-resource">'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(_converse.roster.get(contact_jid).presence.get('show')).toBe('dnd');
|
|
|
|
expect(contact.presence.resources.length).toBe(2);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('priority')).toBe(0);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('show')).toBe('xa');
|
|
|
|
expect(contact.presence.resources.get('older-priority-1-resource').get('priority')).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('older-priority-1-resource').get('show')).toBe('dnd');
|
2017-02-21 22:13:49 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' type="unavailable"'+
|
|
|
|
' from="'+contact_jid+'/older-priority-1-resource">'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(_converse.roster.get(contact_jid).presence.get('show')).toBe('xa');
|
|
|
|
expect(contact.presence.resources.length).toBe(1);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('priority')).toBe(0);
|
|
|
|
expect(contact.presence.resources.get('priority-0-resource').get('show')).toBe('xa');
|
2017-02-21 23:25:19 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
stanza = u.toStanza(
|
|
|
|
'<presence xmlns="jabber:client"'+
|
|
|
|
' to="romeo@montague.lit/converse.js-21770972"'+
|
|
|
|
' type="unavailable"'+
|
|
|
|
' from="'+contact_jid+'/priority-0-resource">'+
|
|
|
|
'</presence>');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(_converse.roster.get(contact_jid).presence.get('show')).toBe('offline');
|
|
|
|
expect(contact.presence.resources.length).toBe(0);
|
|
|
|
done();
|
|
|
|
}));
|
2020-04-22 12:10:39 +02:00
|
|
|
});
|