/*jshint sub:true*/ /*eslint dot-notation: "off"*/ (function (root, factory) { define([ "jasmine", "mock", "test-utils", ], factory); } (this, function (jasmine, mock, test_utils) { "use strict"; const Strophe = converse.env.Strophe; const u = converse.env.utils; // See: https://xmpp.org/rfcs/rfc3921.html describe("A sent presence stanza", function () { it("includes a entity capabilities node", mock.initConverse( ['rosterGroupsFetched'], {}, (done, _converse) => { _converse.api.disco.own.identities.clear(); _converse.api.disco.own.features.clear(); _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"); const presence = _converse.xmppstatus.constructPresence(); expect(presence.toLocaleString()).toBe( ``+ `0`+ ``+ ``) done(); })); it("has a given priority", mock.initConverse((done, _converse) => { let pres = _converse.xmppstatus.constructPresence('online', null, 'Hello world'); expect(pres.toLocaleString()).toBe( ``+ `Hello world`+ `0`+ ``+ `` ); _converse.priority = 2; pres = _converse.xmppstatus.constructPresence('away', null, 'Going jogging'); expect(pres.toLocaleString()).toBe( ``+ `away`+ `Going jogging`+ `2`+ ``+ `` ); delete _converse.priority; pres = _converse.xmppstatus.constructPresence('dnd', null, 'Doing taxes'); expect(pres.toLocaleString()).toBe( ``+ `dnd`+ `Doing taxes`+ `0`+ ``+ `` ); done(); })); it("includes the saved status message", mock.initConverse( ['rosterGroupsFetched'], {}, async (done, _converse) => { test_utils.openControlBox(_converse); spyOn(_converse.connection, 'send').and.callThrough(); const cbview = _converse.chatboxviews.get('controlbox'); cbview.el.querySelector('.change-status').click() const modal = _converse.xmppstatusview.status_modal; 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(``+ `My custom status`+ `0`+ ``+ ``) await u.waitUntil(() => modal.el.getAttribute('aria-hidden') === "true"); await u.waitUntil(() => !u.isVisible(modal.el)); cbview.el.querySelector('.change-status').click() 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( ``+ `dnd`+ `My custom status`+ `0`+ ``+ ``) done(); })); }); describe("A received presence stanza", function () { it("has its priority taken into account", mock.initConverse( ['rosterGroupsFetched'], {}, async (done, _converse) => { test_utils.openControlBox(_converse); await test_utils.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(` 1 ce51d94f7f22b87a21274abb93710b9eb7cc1c65 `); _converse.connection._dataRecv(test_utils.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'); stanza = u.toStanza( ''+ ' '+ ' 0'+ ' xa'+ ' '+ ' '+ ''); _converse.connection._dataRecv(test_utils.createRequest(stanza)); expect(contact.presence.get('show')).toBe('online'); 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'); stanza = u.toStanza( ''+ ' 2'+ ' dnd'+ ''); _converse.connection._dataRecv(test_utils.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'); stanza = u.toStanza( ''+ ' 3'+ ' away'+ ''); _converse.connection._dataRecv(test_utils.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'); stanza = u.toStanza( ''+ ' 1'+ ' dnd'+ ' '+ ''); _converse.connection._dataRecv(test_utils.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'); stanza = u.toStanza( ''+ ''); _converse.connection._dataRecv(test_utils.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'); stanza = u.toStanza( ''+ ''); _converse.connection._dataRecv(test_utils.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'); stanza = u.toStanza( ''+ ''); _converse.connection._dataRecv(test_utils.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'); stanza = u.toStanza( ''+ ''); _converse.connection._dataRecv(test_utils.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'); stanza = u.toStanza( ''+ ''); _converse.connection._dataRecv(test_utils.createRequest(stanza)); expect(_converse.roster.get(contact_jid).presence.get('show')).toBe('offline'); expect(contact.presence.resources.length).toBe(0); done(); })); }); }));