2017-12-22 16:55:03 +01:00
|
|
|
(function (root, factory) {
|
2019-04-06 16:31:42 +02:00
|
|
|
define(["jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2018-10-25 07:32:44 +02:00
|
|
|
const $iq = converse.env.$iq;
|
|
|
|
const $pres = converse.env.$pres;
|
|
|
|
const Strophe = converse.env.Strophe;
|
|
|
|
const _ = converse.env._;
|
|
|
|
const sizzle = converse.env.sizzle;
|
|
|
|
const u = converse.env.utils;
|
|
|
|
|
2018-10-26 10:15:01 +02:00
|
|
|
const checkHeaderToggling = async function (group) {
|
2019-04-06 16:31:42 +02:00
|
|
|
const toggle = group.querySelector('a.group-toggle');
|
2018-10-26 10:15:01 +02:00
|
|
|
expect(u.isVisible(group)).toBeTruthy();
|
|
|
|
expect(group.querySelectorAll('ul.collapsed').length).toBe(0);
|
2018-03-18 04:35:34 +01:00
|
|
|
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy();
|
|
|
|
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy();
|
|
|
|
toggle.click();
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => group.querySelectorAll('ul.collapsed').length === 1);
|
2018-10-26 10:15:01 +02:00
|
|
|
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeTruthy();
|
|
|
|
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeFalsy();
|
|
|
|
toggle.click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => group.querySelectorAll('li').length === _.filter(group.querySelectorAll('li'), u.isVisible).length);
|
2018-10-26 10:15:01 +02:00
|
|
|
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy();
|
|
|
|
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy();
|
2017-12-22 16:55:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
describe("The Contacts Roster", function () {
|
|
|
|
|
2019-09-12 19:42:53 +02:00
|
|
|
it("verifies the origin of roster pushes",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-09-12 19:42:53 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
// See: https://gultsch.de/gajim_roster_push_and_message_interception.html
|
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
|
|
|
expect(_converse.roster.models.length).toBe(1);
|
|
|
|
expect(_converse.roster.at(0).get('jid')).toBe(contact_jid);
|
|
|
|
|
2019-11-06 11:01:34 +01:00
|
|
|
spyOn(converse.env.log, 'warn');
|
2019-09-12 19:42:53 +02:00
|
|
|
let roster_push = u.toStanza(`
|
|
|
|
<iq type="set" to="${_converse.jid}" from="eve@siacs.eu">
|
|
|
|
<query xmlns='jabber:iq:roster'>
|
|
|
|
<item subscription="remove" jid="${contact_jid}"/>
|
|
|
|
</query>
|
|
|
|
</iq>`);
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(roster_push));
|
2019-11-06 11:01:34 +01:00
|
|
|
expect(converse.env.log.warn.calls.count()).toBe(1);
|
|
|
|
expect(converse.env.log.warn).toHaveBeenCalledWith(
|
|
|
|
`Ignoring roster illegitimate roster push message from ${roster_push.getAttribute('from')}`
|
2019-09-12 19:42:53 +02:00
|
|
|
);
|
|
|
|
roster_push = u.toStanza(`
|
|
|
|
<iq type="set" to="${_converse.jid}" from="eve@siacs.eu">
|
|
|
|
<query xmlns='jabber:iq:roster'>
|
|
|
|
<item subscription="both" jid="eve@siacs.eu" name="${mock.cur_names[0]}" />
|
|
|
|
</query>
|
|
|
|
</iq>`);
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(roster_push));
|
2019-11-06 11:01:34 +01:00
|
|
|
expect(converse.env.log.warn.calls.count()).toBe(2);
|
|
|
|
expect(converse.env.log.warn).toHaveBeenCalledWith(
|
|
|
|
`Ignoring roster illegitimate roster push message from ${roster_push.getAttribute('from')}`
|
2019-09-12 19:42:53 +02:00
|
|
|
);
|
|
|
|
expect(_converse.roster.models.length).toBe(1);
|
|
|
|
expect(_converse.roster.at(0).get('jid')).toBe(contact_jid);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-02-13 11:08:58 +01:00
|
|
|
it("is populated once we have registered a presence handler",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-02-13 11:08:58 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
const IQs = _converse.connection.IQ_stanzas;
|
2019-07-11 22:50:30 +02:00
|
|
|
const stanza = await u.waitUntil(
|
2019-05-20 12:38:33 +02:00
|
|
|
() => _.filter(IQs, iq => iq.querySelector('iq query[xmlns="jabber:iq:roster"]')).pop());
|
2019-02-13 11:08:58 +01:00
|
|
|
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
|
|
|
`<iq id="${stanza.getAttribute('id')}" type="get" xmlns="jabber:client">`+
|
2019-02-13 11:08:58 +01:00
|
|
|
`<query xmlns="jabber:iq:roster"/>`+
|
|
|
|
`</iq>`);
|
|
|
|
const result = $iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'result',
|
2019-05-20 12:38:33 +02:00
|
|
|
'id': stanza.getAttribute('id')
|
2019-02-13 11:08:58 +01:00
|
|
|
}).c('query', {
|
|
|
|
'xmlns': 'jabber:iq:roster'
|
|
|
|
}).c('item', {'jid': 'nurse@example.com'}).up()
|
|
|
|
.c('item', {'jid': 'romeo@example.com'})
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(result));
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => _converse.promises['rosterContactsFetched'].isResolved === true);
|
2019-02-13 11:08:58 +01:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2018-05-28 09:35:18 +02:00
|
|
|
it("supports roster versioning",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-25 07:32:44 +02:00
|
|
|
async function (done, _converse) {
|
2018-05-28 09:35:18 +02:00
|
|
|
|
2018-10-02 17:01:39 +02:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
2019-07-11 22:50:30 +02:00
|
|
|
let stanza = await u.waitUntil(
|
2019-05-20 12:38:33 +02:00
|
|
|
() => _.filter(IQ_stanzas, iq => iq.querySelector('iq query[xmlns="jabber:iq:roster"]')).pop()
|
2018-10-25 07:32:44 +02:00
|
|
|
);
|
|
|
|
expect(_converse.roster.data.get('version')).toBeUndefined();
|
2019-05-20 12:38:33 +02:00
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
2018-10-25 07:32:44 +02:00
|
|
|
`<iq id="${stanza.getAttribute('id')}" type="get" xmlns="jabber:client">`+
|
|
|
|
`<query xmlns="jabber:iq:roster"/>`+
|
|
|
|
`</iq>`);
|
|
|
|
let result = $iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'result',
|
|
|
|
'id': stanza.getAttribute('id')
|
|
|
|
}).c('query', {
|
|
|
|
'xmlns': 'jabber:iq:roster',
|
|
|
|
'ver': 'ver7'
|
|
|
|
}).c('item', {'jid': 'nurse@example.com'}).up()
|
|
|
|
.c('item', {'jid': 'romeo@example.com'})
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(result));
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.roster.models.length > 1);
|
2018-10-25 07:32:44 +02:00
|
|
|
expect(_converse.roster.data.get('version')).toBe('ver7');
|
|
|
|
expect(_converse.roster.models.length).toBe(2);
|
|
|
|
|
|
|
|
_converse.roster.fetchFromServer();
|
2019-05-20 12:38:33 +02:00
|
|
|
stanza = _converse.connection.IQ_stanzas.pop();
|
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
2018-10-25 07:32:44 +02:00
|
|
|
`<iq id="${stanza.getAttribute('id')}" type="get" xmlns="jabber:client">`+
|
|
|
|
`<query ver="ver7" xmlns="jabber:iq:roster"/>`+
|
|
|
|
`</iq>`);
|
|
|
|
|
|
|
|
result = $iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'result',
|
|
|
|
'id': stanza.getAttribute('id')
|
2018-05-28 09:35:18 +02:00
|
|
|
});
|
2018-10-25 07:32:44 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(result));
|
|
|
|
|
|
|
|
const roster_push = $iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'set',
|
|
|
|
}).c('query', {'xmlns': 'jabber:iq:roster', 'ver': 'ver34'})
|
|
|
|
.c('item', {'jid': 'romeo@example.com', 'subscription': 'remove'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(roster_push));
|
|
|
|
expect(_converse.roster.data.get('version')).toBe('ver34');
|
|
|
|
expect(_converse.roster.models.length).toBe(1);
|
|
|
|
expect(_converse.roster.at(0).get('jid')).toBe('nurse@example.com');
|
|
|
|
done();
|
2018-05-28 09:35:18 +02:00
|
|
|
}));
|
|
|
|
|
2017-12-22 16:55:03 +01:00
|
|
|
describe("The live filter", function () {
|
|
|
|
|
|
|
|
it("will only appear when roster contacts flow over the visible area",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-05-22 18:03:04 +02:00
|
|
|
const filter = _converse.rosterview.el.querySelector('.roster-filter');
|
2019-08-05 01:39:57 +02:00
|
|
|
expect(filter === null).toBe(false);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
|
|
|
await test_utils.openControlBox(_converse);
|
2019-05-23 21:44:00 +02:00
|
|
|
|
|
|
|
const view = _converse.chatboxviews.get('controlbox');
|
|
|
|
const flyout = view.el.querySelector('.box-flyout');
|
|
|
|
const panel = flyout.querySelector('.controlbox-pane');
|
2019-04-06 16:31:42 +02:00
|
|
|
function hasScrollBar (el) {
|
2019-05-23 21:44:00 +02:00
|
|
|
return el.isConnected && flyout.offsetHeight < panel.scrollHeight;
|
2019-04-06 16:31:42 +02:00
|
|
|
}
|
2019-05-23 21:44:00 +02:00
|
|
|
const el = _converse.rosterview.roster_el;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => hasScrollBar(el) ? u.isVisible(filter) : !u.isVisible(filter), 900);
|
2019-04-06 16:31:42 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be used to filter the contacts shown",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {'roster_groups': true},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-04-06 16:31:42 +02:00
|
|
|
let filter = _converse.rosterview.el.querySelector('.roster-filter');
|
|
|
|
const roster = _converse.rosterview.roster_el;
|
2017-12-22 16:55:03 +01:00
|
|
|
_converse.rosterview.filter_view.delegateEvents();
|
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', roster).filter(u.isVisible).length === 17), 600);
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(5);
|
2019-06-03 07:58:51 +02:00
|
|
|
filter.value = "juliet";
|
2019-04-06 16:31:42 +02:00
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', roster).filter(u.isVisible).length === 1), 600);
|
2019-04-06 16:31:42 +02:00
|
|
|
// Only one roster contact is now visible
|
|
|
|
let visible_contacts = sizzle('li', roster).filter(u.isVisible);
|
|
|
|
expect(visible_contacts.length).toBe(1);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(visible_contacts.pop().textContent.trim()).toBe('Juliet Capulet');
|
2019-04-06 16:31:42 +02:00
|
|
|
// Only one foster group is still visible
|
|
|
|
expect(sizzle('.roster-group', roster).filter(u.isVisible).length).toBe(1);
|
|
|
|
const visible_group = sizzle('.roster-group', roster).filter(u.isVisible).pop();
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(visible_group.querySelector('a.group-toggle').textContent.trim()).toBe('friends & acquaintences');
|
2019-04-06 16:31:42 +02:00
|
|
|
|
|
|
|
filter = _converse.rosterview.el.querySelector('.roster-filter');
|
2019-06-03 07:58:51 +02:00
|
|
|
filter.value = "j";
|
2019-04-06 16:31:42 +02:00
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', roster).filter(u.isVisible).length === 2), 700);
|
2018-01-04 17:12:09 +01:00
|
|
|
|
2019-04-06 16:31:42 +02:00
|
|
|
visible_contacts = sizzle('li', roster).filter(u.isVisible);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(visible_contacts.length).toBe(2);
|
2019-04-06 16:31:42 +02:00
|
|
|
|
|
|
|
let visible_groups = sizzle('.roster-group', roster).filter(u.isVisible).map(el => el.querySelector('a.group-toggle'));
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(visible_groups.length).toBe(2);
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(visible_groups[0].textContent.trim()).toBe('friends & acquaintences');
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(visible_groups[1].textContent.trim()).toBe('Ungrouped');
|
2019-04-06 16:31:42 +02:00
|
|
|
|
|
|
|
filter = _converse.rosterview.el.querySelector('.roster-filter');
|
|
|
|
filter.value = "xxx";
|
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', roster).filter(u.isVisible).length === 0), 600);
|
2019-04-06 16:31:42 +02:00
|
|
|
visible_groups = sizzle('.roster-group', roster).filter(u.isVisible).map(el => el.querySelector('a.group-toggle'));
|
|
|
|
expect(visible_groups.length).toBe(0);
|
|
|
|
|
|
|
|
filter = _converse.rosterview.el.querySelector('.roster-filter');
|
|
|
|
filter.value = "";
|
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', roster).filter(u.isVisible).length === 17), 600);
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(5);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("will also filter out contacts added afterwards",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-04-06 16:31:42 +02:00
|
|
|
const filter = _converse.rosterview.el.querySelector('.roster-filter');
|
|
|
|
const roster = _converse.rosterview.roster_el;
|
2017-12-22 16:55:03 +01:00
|
|
|
_converse.rosterview.filter_view.delegateEvents();
|
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', roster).filter(u.isVisible).length === 17), 800);
|
2019-06-03 07:58:51 +02:00
|
|
|
filter.value = "la";
|
2019-04-06 16:31:42 +02:00
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', roster).filter(u.isVisible).length === 4), 800);
|
2019-04-06 16:31:42 +02:00
|
|
|
|
|
|
|
// Five roster contact is now visible
|
|
|
|
const visible_contacts = sizzle('li', roster).filter(u.isVisible);
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(visible_contacts.length).toBe(4);
|
2019-04-06 16:31:42 +02:00
|
|
|
let visible_groups = sizzle('.roster-group', roster).filter(u.isVisible).map(el => el.querySelector('a.group-toggle'));
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(visible_groups.length).toBe(4);
|
|
|
|
expect(visible_groups[0].textContent.trim()).toBe('Colleagues');
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(visible_groups[1].textContent.trim()).toBe('Family');
|
|
|
|
expect(visible_groups[2].textContent.trim()).toBe('friends & acquaintences');
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(visible_groups[3].textContent.trim()).toBe('ænemies');
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-04-06 16:31:42 +02:00
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: 'valentine@montague.lit',
|
2019-04-06 16:31:42 +02:00
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
groups: ['newgroup'],
|
2019-06-03 07:58:51 +02:00
|
|
|
fullname: 'Valentine'
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group[data-group="newgroup"] li', roster).length, 300);
|
2019-04-06 16:31:42 +02:00
|
|
|
visible_groups = sizzle('.roster-group', roster).filter(u.isVisible).map(el => el.querySelector('a.group-toggle'));
|
|
|
|
// The "newgroup" group doesn't appear
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(visible_groups.length).toBe(4);
|
|
|
|
expect(visible_groups[0].textContent.trim()).toBe('Colleagues');
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(visible_groups[1].textContent.trim()).toBe('Family');
|
|
|
|
expect(visible_groups[2].textContent.trim()).toBe('friends & acquaintences');
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(visible_groups[3].textContent.trim()).toBe('ænemies');
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(roster.querySelectorAll('.roster-group').length).toBe(6);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be used to filter the groups shown",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {'roster_groups': true},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2017-12-22 16:55:03 +01:00
|
|
|
_converse.rosterview.filter_view.delegateEvents();
|
2019-04-06 16:31:42 +02:00
|
|
|
var roster = _converse.rosterview.roster_el;
|
2018-03-17 18:13:51 +01:00
|
|
|
|
|
|
|
var button = _converse.rosterview.el.querySelector('span[data-type="groups"]');
|
|
|
|
button.click();
|
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', roster).filter(u.isVisible).length === 17), 600);
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(sizzle('.roster-group', roster).filter(u.isVisible).length).toBe(5);
|
2018-03-17 18:13:51 +01:00
|
|
|
|
2019-04-06 16:31:42 +02:00
|
|
|
var filter = _converse.rosterview.el.querySelector('.roster-filter');
|
|
|
|
filter.value = "colleagues";
|
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (sizzle('div.roster-group:not(.collapsed)', roster).length === 1), 600);
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(sizzle('div.roster-group:not(.collapsed)', roster).pop().firstElementChild.textContent.trim()).toBe('Colleagues');
|
|
|
|
expect(sizzle('div.roster-group:not(.collapsed) li', roster).filter(u.isVisible).length).toBe(6);
|
2019-04-06 16:31:42 +02:00
|
|
|
// Check that all contacts under the group are shown
|
|
|
|
expect(sizzle('div.roster-group:not(.collapsed) li', roster).filter(l => !u.isVisible(l)).length).toBe(0);
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-04-06 16:31:42 +02:00
|
|
|
filter = _converse.rosterview.el.querySelector('.roster-filter');
|
|
|
|
filter.value = "xxx";
|
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
2018-01-04 17:12:09 +01:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (roster.querySelectorAll('div.roster-group.collapsed').length === 5), 700);
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(roster.querySelectorAll('div.roster-group:not(.collapsed) a').length).toBe(0);
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-04-06 16:31:42 +02:00
|
|
|
filter = _converse.rosterview.el.querySelector('.roster-filter');
|
|
|
|
filter.value = ""; // Check that groups are shown again, when the filter string is cleared.
|
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (roster.querySelectorAll('div.roster-group.collapsed').length === 0), 700);
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(sizzle('div.roster-group:not(collapsed)', roster).length).toBe(5);
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(sizzle('div.roster-group:not(collapsed) li', roster).length).toBe(17);
|
2019-04-06 16:31:42 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("has a button with which its contents can be cleared",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-24 14:29:15 +02:00
|
|
|
['rosterGroupsFetched'], {'roster_groups': true},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2018-03-17 18:13:51 +01:00
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
const filter = _converse.rosterview.el.querySelector('.roster-filter');
|
2018-03-17 18:13:51 +01:00
|
|
|
filter.value = "xxx";
|
|
|
|
u.triggerEvent(filter, "keydown", "KeyboardEvent");
|
|
|
|
expect(_.includes(filter.classList, "x")).toBeFalsy();
|
|
|
|
expect(u.hasClass('hidden', _converse.rosterview.el.querySelector('.roster-filter-form .clear-input'))).toBeTruthy();
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
const isHidden = _.partial(u.hasClass, 'hidden');
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => !isHidden(_converse.rosterview.el.querySelector('.roster-filter-form .clear-input')), 900);
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.rosterview.el.querySelector('.clear-input').click();
|
|
|
|
expect(document.querySelector('.roster-filter').value).toBe("");
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-24 08:39:21 +02:00
|
|
|
// Disabling for now, because since recently this test consistently
|
|
|
|
// fails on Travis and I couldn't get it to pass there.
|
|
|
|
xit("can be used to filter contacts by their chat state",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
test_utils.waitForRoster(_converse, 'all');
|
2019-06-03 07:58:51 +02:00
|
|
|
let jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-05-22 16:44:58 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'online');
|
2019-06-03 07:58:51 +02:00
|
|
|
jid = mock.cur_names[4].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-05-22 16:44:58 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'dnd');
|
2019-10-24 14:29:15 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
2019-05-22 16:13:15 +02:00
|
|
|
const button = _converse.rosterview.el.querySelector('span[data-type="state"]');
|
2018-03-17 18:13:51 +01:00
|
|
|
button.click();
|
2019-05-22 16:13:15 +02:00
|
|
|
const roster = _converse.rosterview.roster_el;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('li', roster).filter(u.isVisible).length === 15, 900);
|
2019-05-22 16:13:15 +02:00
|
|
|
const filter = _converse.rosterview.el.querySelector('.state-type');
|
|
|
|
expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(5);
|
|
|
|
filter.value = "online";
|
|
|
|
u.triggerEvent(filter, 'change');
|
2019-05-24 08:39:21 +02:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('li', roster).filter(u.isVisible).length === 1, 900);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(sizzle('li', roster).filter(u.isVisible).pop().textContent.trim()).toBe('Lord Montague');
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length === 1, 900);
|
2019-05-22 16:13:15 +02:00
|
|
|
const ul = sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).pop();
|
|
|
|
expect(ul.parentElement.firstElementChild.textContent.trim()).toBe('friends & acquaintences');
|
|
|
|
filter.value = "dnd";
|
|
|
|
u.triggerEvent(filter, 'change');
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('li', roster).filter(u.isVisible).pop().textContent.trim() === 'Friar Laurence', 900);
|
2019-05-22 16:13:15 +02:00
|
|
|
expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(1);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("A Roster Group", function () {
|
|
|
|
|
|
|
|
it("can be used to organize existing contacts",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-24 14:29:15 +02:00
|
|
|
['rosterGroupsFetched'], {'roster_groups': true},
|
2019-01-11 17:17:52 +01:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
_converse.rosterview.render();
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'all');
|
|
|
|
await test_utils.createContacts(_converse, 'requesting');
|
2017-12-22 16:55:03 +01:00
|
|
|
// Check that the groups appear alphabetically and that
|
|
|
|
// requesting and pending contacts are last.
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group a.group-toggle', _converse.rosterview.el).length);
|
2019-10-24 14:29:15 +02:00
|
|
|
const group_titles = sizzle('.roster-group a.group-toggle', _converse.rosterview.el).map(o => o.textContent.trim());
|
2019-01-11 17:17:52 +01:00
|
|
|
expect(group_titles).toEqual([
|
|
|
|
"Contact requests",
|
2019-10-24 14:29:15 +02:00
|
|
|
"Colleagues",
|
2019-01-11 17:17:52 +01:00
|
|
|
"Family",
|
|
|
|
"friends & acquaintences",
|
|
|
|
"ænemies",
|
|
|
|
"Ungrouped",
|
|
|
|
"Pending contacts"
|
|
|
|
]);
|
|
|
|
// Check that usernames appear alphabetically per group
|
2019-10-24 14:29:15 +02:00
|
|
|
Object.keys(mock.groups).forEach(name => {
|
2019-01-11 17:17:52 +01:00
|
|
|
const contacts = sizzle('.roster-group[data-group="'+name+'"] ul', _converse.rosterview.el);
|
|
|
|
const names = _.map(contacts, o => o.textContent.trim());
|
|
|
|
expect(names).toEqual(_.clone(names).sort());
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-01-11 17:17:52 +01:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2017-12-22 17:58:48 +01:00
|
|
|
it("gets created when a contact's \"groups\" attribute changes",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-24 14:29:15 +02:00
|
|
|
['rosterGroupsFetched'], {'roster_groups': true},
|
2019-01-11 17:17:52 +01:00
|
|
|
async function (done, _converse) {
|
2017-12-22 17:58:48 +01:00
|
|
|
|
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
_converse.rosterview.render();
|
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
2017-12-22 17:58:48 +01:00
|
|
|
|
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: 'groupchanger@montague.lit',
|
2017-12-22 17:58:48 +01:00
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
groups: ['firstgroup'],
|
|
|
|
fullname: 'George Groupchanger'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check that the groups appear alphabetically and that
|
|
|
|
// requesting and pending contacts are last.
|
2019-07-11 22:50:30 +02:00
|
|
|
let group_titles = await u.waitUntil(() => {
|
2019-01-11 17:17:52 +01:00
|
|
|
const toggles = sizzle('.roster-group a.group-toggle', _converse.rosterview.el);
|
|
|
|
if (_.reduce(toggles, (result, t) => result && u.isVisible(t), true)) {
|
|
|
|
return _.map(toggles, o => o.textContent.trim());
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
expect(group_titles).toEqual(['firstgroup']);
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact = _converse.roster.get('groupchanger@montague.lit');
|
2019-01-11 17:17:52 +01:00
|
|
|
contact.set({'groups': ['secondgroup']});
|
2019-07-11 22:50:30 +02:00
|
|
|
group_titles = await u.waitUntil(() => {
|
2019-01-11 17:17:52 +01:00
|
|
|
const toggles = sizzle('.roster-group[data-group="secondgroup"] a.group-toggle', _converse.rosterview.el);
|
|
|
|
if (_.reduce(toggles, (result, t) => result && u.isVisible(t), true)) {
|
|
|
|
return _.map(toggles, o => o.textContent.trim());
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
expect(group_titles).toEqual(['secondgroup']);
|
|
|
|
done();
|
2017-12-22 17:58:48 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can share contacts with other roster groups",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {'roster_groups': true},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
const groups = ['Colleagues', 'friends'];
|
2017-12-22 16:55:03 +01:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2019-10-24 14:29:15 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
2017-12-22 16:55:03 +01:00
|
|
|
_converse.rosterview.render();
|
|
|
|
for (var i=0; i<mock.cur_names.length; i++) {
|
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2017-12-22 16:55:03 +01:00
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
groups: groups,
|
|
|
|
fullname: mock.cur_names[i]
|
|
|
|
});
|
|
|
|
}
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (sizzle('li', _converse.rosterview.el).filter(u.isVisible).length === 30), 600);
|
2019-04-06 16:31:42 +02:00
|
|
|
// Check that usernames appear alphabetically per group
|
|
|
|
_.each(groups, function (name) {
|
|
|
|
const contacts = sizzle('.roster-group[data-group="'+name+'"] ul li', _converse.rosterview.el);
|
|
|
|
const names = contacts.map(o => o.textContent.trim());
|
|
|
|
expect(names).toEqual(_.clone(names).sort());
|
|
|
|
expect(names.length).toEqual(mock.cur_names.length);
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-04-06 16:31:42 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("remembers whether it is closed or opened",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-26 10:15:01 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
|
|
|
_converse.roster_groups = true;
|
2019-10-24 14:29:15 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
2017-12-22 16:55:03 +01:00
|
|
|
|
|
|
|
var i=0, j=0;
|
|
|
|
var groups = {
|
2019-10-24 14:29:15 +02:00
|
|
|
'Colleagues': 3,
|
2017-12-22 16:55:03 +01:00
|
|
|
'friends & acquaintences': 3,
|
|
|
|
'Ungrouped': 2
|
|
|
|
};
|
|
|
|
_.each(_.keys(groups), function (name) {
|
|
|
|
j = i;
|
|
|
|
for (i=j; i<j+groups[name]; i++) {
|
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2017-12-22 16:55:03 +01:00
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
groups: name === 'ungrouped'? [] : [name],
|
|
|
|
fullname: mock.cur_names[i]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-10-24 14:29:15 +02:00
|
|
|
const view = _converse.rosterview.get('Colleagues');
|
2018-10-26 10:15:01 +02:00
|
|
|
const toggle = view.el.querySelector('a.group-toggle');
|
2017-12-22 16:55:03 +01:00
|
|
|
expect(view.model.get('state')).toBe('opened');
|
2018-10-26 10:15:01 +02:00
|
|
|
toggle.click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.get('state') === 'closed');
|
2018-10-26 10:15:01 +02:00
|
|
|
toggle.click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.get('state') === 'opened');
|
2018-10-26 10:15:01 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Pending Contacts", function () {
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can be collapsed under their own header",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-25 07:32:44 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'all');
|
|
|
|
await Promise.all(_converse.roster.forEach(contact => u.waitUntil(() => contact.vcard.get('fullname'))));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group', _converse.rosterview.el).filter(u.isVisible).map(e => e.querySelector('li')).length, 1000);
|
2018-10-25 07:32:44 +02:00
|
|
|
await checkHeaderToggling.apply(
|
|
|
|
_converse,
|
|
|
|
[_converse.rosterview.get('Pending contacts').el]
|
|
|
|
);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be added to the roster",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-10-24 14:29:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2017-12-22 16:55:03 +01:00
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2017-12-22 16:55:03 +01:00
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[0]
|
|
|
|
});
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("are shown in the roster when hide_offline_users",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {'hide_offline_users': true},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'pending');
|
|
|
|
await Promise.all(_converse.roster.forEach(contact => u.waitUntil(() => contact.vcard.get('fullname'))));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('li', _converse.rosterview.el).filter(u.isVisible).length, 500)
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
|
|
|
expect(u.isVisible(_converse.rosterview.el)).toBe(true);
|
|
|
|
expect(sizzle('li', _converse.rosterview.el).filter(u.isVisible).length).toBe(3);
|
|
|
|
expect(sizzle('ul.roster-group-contacts', _converse.rosterview.el).filter(u.isVisible).length).toBe(1);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can be removed by the user",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'all');
|
|
|
|
await Promise.all(_converse.roster.forEach(contact => u.waitUntil(() => contact.vcard.get('fullname'))));
|
2019-04-06 16:31:42 +02:00
|
|
|
const name = mock.pend_names[0];
|
2019-06-03 07:58:51 +02:00
|
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-04-06 16:31:42 +02:00
|
|
|
const contact = _converse.roster.get(jid);
|
2018-03-27 19:07:55 +02:00
|
|
|
var sent_IQ;
|
2017-12-22 16:55:03 +01:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(contact, 'unauthorize').and.callFake(function () { return contact; });
|
2018-03-27 19:07:55 +02:00
|
|
|
spyOn(contact, 'removeFromRoster').and.callThrough();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle(".pending-contact-name:contains('"+name+"')", _converse.rosterview.el).length, 700);
|
2019-10-09 16:01:38 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
|
2019-04-06 16:31:42 +02:00
|
|
|
sent_IQ = iq;
|
|
|
|
callback();
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-04-06 16:31:42 +02:00
|
|
|
sizzle(`.remove-xmpp-contact[title="Click to remove ${name} as a contact"]`, _converse.rosterview.el).pop().click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (sizzle(".pending-contact-name:contains('"+name+"')", _converse.rosterview.el).length === 0), 1000);
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
`<iq type="set" xmlns="jabber:client">`+
|
|
|
|
`<query xmlns="jabber:iq:roster">`+
|
2019-06-03 07:58:51 +02:00
|
|
|
`<item jid="lord.capulet@montague.lit" subscription="remove"/>`+
|
2019-04-06 16:31:42 +02:00
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("do not have a header if there aren't any",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-24 17:55:20 +02:00
|
|
|
['rosterGroupsFetched', 'VCardsInitialized'], {},
|
2018-10-25 07:32:44 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
2018-10-25 07:32:44 +02:00
|
|
|
const name = mock.pend_names[0];
|
2017-12-22 16:55:03 +01:00
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2017-12-22 16:55:03 +01:00
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: name
|
|
|
|
});
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => {
|
2019-02-12 14:21:45 +01:00
|
|
|
const el = _converse.rosterview.get('Pending contacts').el;
|
|
|
|
return u.isVisible(el) && _.filter(el.querySelectorAll('li'), li => u.isVisible(li)).length;
|
2018-10-25 07:32:44 +02:00
|
|
|
}, 700)
|
2019-05-22 16:13:15 +02:00
|
|
|
|
2019-10-24 17:55:20 +02:00
|
|
|
const remove_el = await u.waitUntil(() => sizzle(`.remove-xmpp-contact[title="Click to remove ${name} as a contact"]`, _converse.rosterview.el).pop());
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
remove_el.click();
|
2018-10-25 07:32:44 +02:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
|
2019-05-23 14:39:46 +02:00
|
|
|
const iq = _converse.connection.IQ_stanzas.pop();
|
|
|
|
expect(Strophe.serialize(iq)).toBe(
|
|
|
|
`<iq id="${iq.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query xmlns="jabber:iq:roster">`+
|
2019-06-03 07:58:51 +02:00
|
|
|
`<item jid="lord.capulet@montague.lit" subscription="remove"/>`+
|
2019-05-23 14:39:46 +02:00
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const stanza = u.toStanza(`<iq id="${iq.getAttribute('id')}" to="romeo@montague.lit/orchard" type="result"/>`);
|
2019-05-23 14:39:46 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => !u.isVisible(_converse.rosterview.get('Pending contacts').el));
|
2018-10-25 07:32:44 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("is shown when a new private message is received",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'all');
|
|
|
|
await Promise.all(_converse.roster.forEach(contact => u.waitUntil(() => contact.vcard.get('fullname'))));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.roster.at(0).vcard.get('fullname'))
|
2019-04-06 16:31:42 +02:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
for (var i=0; i<mock.pend_names.length; i++) {
|
|
|
|
const name = mock.pend_names[i];
|
|
|
|
sizzle(`.remove-xmpp-contact[title="Click to remove ${name} as a contact"]`, _converse.rosterview.el).pop().click();
|
|
|
|
}
|
|
|
|
expect(u.isVisible(_converse.rosterview.get('Pending contacts').el)).toBe(false);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be added to the roster and they will be sorted alphabetically",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
|
|
|
await Promise.all(_converse.roster.forEach(contact => u.waitUntil(() => contact.vcard.get('fullname'))));
|
2017-12-22 16:55:03 +01:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2019-10-24 14:29:15 +02:00
|
|
|
let i;
|
2017-12-22 16:55:03 +01:00
|
|
|
for (i=0; i<mock.pend_names.length; i++) {
|
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: mock.pend_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2017-12-22 16:55:03 +01:00
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[i]
|
|
|
|
});
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
|
|
|
}
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => sizzle('li', _converse.rosterview.get('Pending contacts').el).filter(u.isVisible).length, 900);
|
2019-05-22 16:13:15 +02:00
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
const view = _converse.rosterview.get('Pending contacts');
|
|
|
|
const spans = view.el.querySelectorAll('.pending-xmpp-contact span');
|
|
|
|
const t = _.reduce(spans, (result, value) => result + _.trim(value.textContent), '');
|
|
|
|
expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join(''));
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Existing Contacts", function () {
|
2019-09-04 19:11:26 +02:00
|
|
|
async function _addContacts (_converse) {
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
|
|
|
await test_utils.openControlBox(_converse);
|
2019-09-04 19:11:26 +02:00
|
|
|
await Promise.all(_converse.roster.forEach(contact => u.waitUntil(() => contact.vcard.get('fullname'))));
|
2019-02-12 14:21:45 +01:00
|
|
|
}
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can be collapsed under their own header",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('li', _converse.rosterview.el).filter(u.isVisible).length, 500);
|
2019-05-22 16:13:15 +02:00
|
|
|
await checkHeaderToggling.apply(_converse, [_converse.rosterview.el.querySelector('.roster-group')]);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("will be hidden when appearing under a collapsed group",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
|
|
|
_converse.roster_groups = false;
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('li', _converse.rosterview.el).filter(u.isVisible).length, 500);
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.rosterview.el.querySelector('.roster-group a.group-toggle').click();
|
2019-06-03 07:58:51 +02:00
|
|
|
const name = "Romeo Montague";
|
|
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.create({
|
|
|
|
ask: null,
|
|
|
|
fullname: name,
|
|
|
|
jid: jid,
|
|
|
|
requesting: false,
|
|
|
|
subscription: 'both'
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-05-22 16:13:15 +02:00
|
|
|
const view = _converse.rosterview.get('My contacts').get(jid);
|
|
|
|
expect(u.isVisible(view.el)).toBe(false);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can be added to the roster and they will be sorted alphabetically",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2017-12-22 16:55:03 +01:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2019-09-04 19:11:26 +02:00
|
|
|
await Promise.all(mock.cur_names.map(name => {
|
|
|
|
const contact = _converse.roster.create({
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2017-12-22 16:55:03 +01:00
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
2019-09-04 19:11:26 +02:00
|
|
|
fullname: name
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-10-24 17:55:20 +02:00
|
|
|
return u.waitUntil(() => contact.initialized);
|
2019-09-04 19:11:26 +02:00
|
|
|
}));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('li', _converse.rosterview.el).length, 600);
|
2019-05-22 16:13:15 +02:00
|
|
|
// Check that they are sorted alphabetically
|
2019-09-04 19:11:26 +02:00
|
|
|
const els = sizzle('.roster-group .current-xmpp-contact.offline a.open-chat', _converse.rosterview.el)
|
|
|
|
const t = els.reduce((result, value) => (result + value.textContent.trim()), '');
|
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,mock.cur_names.length).sort().join(''));
|
2019-05-22 16:13:15 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can be removed by the user",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-25 07:32:44 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('li').length);
|
2018-10-25 07:32:44 +02:00
|
|
|
const name = mock.cur_names[0];
|
2019-06-03 07:58:51 +02:00
|
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-25 07:32:44 +02:00
|
|
|
const contact = _converse.roster.get(jid);
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(contact, 'removeFromRoster').and.callThrough();
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2018-10-25 07:32:44 +02:00
|
|
|
let sent_IQ;
|
2019-10-09 16:01:38 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
|
2018-10-25 07:32:44 +02:00
|
|
|
sent_IQ = iq;
|
|
|
|
callback();
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-04-06 16:31:42 +02:00
|
|
|
sizzle(`.remove-xmpp-contact[title="Click to remove ${name} as a contact"]`, _converse.rosterview.el).pop().click();
|
2018-10-25 07:32:44 +02:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(sent_IQ.toLocaleString()).toBe(
|
|
|
|
`<iq type="set" xmlns="jabber:client">`+
|
2019-06-03 07:58:51 +02:00
|
|
|
`<query xmlns="jabber:iq:roster"><item jid="mercutio@montague.lit" subscription="remove"/></query>`+
|
2018-10-25 07:32:44 +02:00
|
|
|
`</iq>`);
|
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle(".open-chat:contains('"+name+"')", _converse.rosterview.el).length === 0);
|
2018-10-25 07:32:44 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("do not have a header if there aren't any",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-25 07:32:44 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
|
|
|
const name = mock.cur_names[0];
|
|
|
|
const contact = _converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2017-12-22 16:55:03 +01:00
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
fullname: name
|
|
|
|
});
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group', _converse.rosterview.el).filter(u.isVisible).map(e => e.querySelector('li')).length, 1000);
|
2018-10-25 07:32:44 +02:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(contact, 'removeFromRoster').and.callThrough();
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
|
|
|
|
if (typeof callback === "function") { return callback(); }
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(u.isVisible(_converse.rosterview.el.querySelector('.roster-group'))).toBe(true);
|
|
|
|
sizzle(`.remove-xmpp-contact[title="Click to remove ${name} as a contact"]`, _converse.rosterview.el).pop().click();
|
2018-10-25 07:32:44 +02:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length === 0);
|
2018-10-25 07:32:44 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can change their status to online and be sorted alphabetically",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length, 700);
|
2019-05-22 16:13:15 +02:00
|
|
|
const roster = _converse.rosterview.el;
|
2019-10-24 14:29:15 +02:00
|
|
|
const groups = roster.querySelectorAll('.roster-group');
|
|
|
|
const groupnames = Array.from(groups).map(g => g.getAttribute('data-group'));
|
|
|
|
expect(groupnames.join(' ')).toBe("Colleagues Family friends & acquaintences ænemies Ungrouped");
|
2019-05-22 16:13:15 +02:00
|
|
|
for (let i=0; i<mock.cur_names.length; i++) {
|
2019-10-24 14:29:15 +02:00
|
|
|
const jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'online');
|
|
|
|
// Check that they are sorted alphabetically
|
2019-10-24 14:29:15 +02:00
|
|
|
for (let j=0; j<groups.length; j++) {
|
|
|
|
const group = groups[j];
|
|
|
|
const groupname = groupnames[j];
|
|
|
|
const els = group.querySelectorAll('.current-xmpp-contact.online a.open-chat');
|
|
|
|
const t = _.reduce(els, (result, value) => result + _.trim(value.textContent), '');
|
|
|
|
expect(t).toEqual(mock.groups_map[groupname].slice(0, els.length).sort().join(''));
|
|
|
|
}
|
2019-05-22 16:13:15 +02:00
|
|
|
}
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can change their status to busy and be sorted alphabetically",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
|
2019-05-22 16:13:15 +02:00
|
|
|
const roster = _converse.rosterview.el;
|
2019-10-24 14:29:15 +02:00
|
|
|
const groups = roster.querySelectorAll('.roster-group');
|
|
|
|
const groupnames = Array.from(groups).map(g => g.getAttribute('data-group'));
|
|
|
|
expect(groupnames.join(' ')).toBe("Colleagues Family friends & acquaintences ænemies Ungrouped");
|
2019-05-22 16:13:15 +02:00
|
|
|
for (let i=0; i<mock.cur_names.length; i++) {
|
2019-10-24 14:29:15 +02:00
|
|
|
const jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'dnd');
|
|
|
|
// Check that they are sorted alphabetically
|
2019-10-24 14:29:15 +02:00
|
|
|
for (let j=0; j<groups.length; j++) {
|
|
|
|
const group = groups[j];
|
|
|
|
const groupname = groupnames[j];
|
|
|
|
const els = group.querySelectorAll('.current-xmpp-contact.dnd a.open-chat');
|
|
|
|
const t = _.reduce(els, (result, value) => result + _.trim(value.textContent), '');
|
|
|
|
expect(t).toEqual(mock.groups_map[groupname].slice(0, els.length).sort().join(''));
|
|
|
|
}
|
2019-05-22 16:13:15 +02:00
|
|
|
}
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can change their status to away and be sorted alphabetically",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
|
2019-05-22 16:13:15 +02:00
|
|
|
const roster = _converse.rosterview.el;
|
2019-10-24 14:29:15 +02:00
|
|
|
const groups = roster.querySelectorAll('.roster-group');
|
|
|
|
const groupnames = Array.from(groups).map(g => g.getAttribute('data-group'));
|
|
|
|
expect(groupnames.join(' ')).toBe("Colleagues Family friends & acquaintences ænemies Ungrouped");
|
2019-05-22 16:13:15 +02:00
|
|
|
for (let i=0; i<mock.cur_names.length; i++) {
|
2019-10-24 14:29:15 +02:00
|
|
|
const jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'away');
|
|
|
|
// Check that they are sorted alphabetically
|
2019-10-24 14:29:15 +02:00
|
|
|
for (let j=0; j<groups.length; j++) {
|
|
|
|
const group = groups[j];
|
|
|
|
const groupname = groupnames[j];
|
|
|
|
const els = group.querySelectorAll('.current-xmpp-contact.away a.open-chat');
|
|
|
|
const t = _.reduce(els, (result, value) => result + _.trim(value.textContent), '');
|
|
|
|
expect(t).toEqual(mock.groups_map[groupname].slice(0, els.length).sort().join(''));
|
|
|
|
}
|
2019-05-22 16:13:15 +02:00
|
|
|
}
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can change their status to xa and be sorted alphabetically",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
|
2019-04-06 16:31:42 +02:00
|
|
|
const roster = _converse.rosterview.el;
|
2019-10-24 14:29:15 +02:00
|
|
|
const groups = roster.querySelectorAll('.roster-group');
|
|
|
|
const groupnames = Array.from(groups).map(g => g.getAttribute('data-group'));
|
|
|
|
expect(groupnames.join(' ')).toBe("Colleagues Family friends & acquaintences ænemies Ungrouped");
|
|
|
|
for (let i=0; i<mock.cur_names.length; i++) {
|
|
|
|
const jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-04-06 16:31:42 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'xa');
|
|
|
|
// Check that they are sorted alphabetically
|
2019-10-24 14:29:15 +02:00
|
|
|
for (let j=0; j<groups.length; j++) {
|
|
|
|
const group = groups[j];
|
|
|
|
const groupname = groupnames[j];
|
|
|
|
const els = group.querySelectorAll('.current-xmpp-contact.xa a.open-chat');
|
|
|
|
const t = _.reduce(els, (result, value) => result + _.trim(value.textContent), '');
|
|
|
|
expect(t).toEqual(mock.groups_map[groupname].slice(0, els.length).sort().join(''));
|
|
|
|
}
|
2019-04-06 16:31:42 +02:00
|
|
|
}
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can change their status to unavailable and be sorted alphabetically",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 500)
|
2019-10-24 14:29:15 +02:00
|
|
|
const roster = _converse.rosterview.el;
|
|
|
|
const groups = roster.querySelectorAll('.roster-group');
|
|
|
|
const groupnames = Array.from(groups).map(g => g.getAttribute('data-group'));
|
|
|
|
expect(groupnames.join(' ')).toBe("Colleagues Family friends & acquaintences ænemies Ungrouped");
|
|
|
|
for (let i=0; i<mock.cur_names.length; i++) {
|
|
|
|
const jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-04-06 16:31:42 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'unavailable');
|
|
|
|
// Check that they are sorted alphabetically
|
2019-10-24 14:29:15 +02:00
|
|
|
for (let j=0; j<groups.length; j++) {
|
|
|
|
const group = groups[j];
|
|
|
|
const groupname = groupnames[j];
|
|
|
|
const els = group.querySelectorAll('.current-xmpp-contact.unavailable a.open-chat');
|
|
|
|
const t = _.reduce(els, (result, value) => result + _.trim(value.textContent), '');
|
|
|
|
expect(t).toEqual(mock.groups_map[groupname].slice(0, els.length).sort().join(''));
|
|
|
|
}
|
2019-04-06 16:31:42 +02:00
|
|
|
}
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("are ordered according to status: online, busy, away, xa, unavailable, offline",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-09-04 19:11:26 +02:00
|
|
|
await _addContacts(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
|
2019-05-22 16:13:15 +02:00
|
|
|
let i, jid;
|
|
|
|
for (i=0; i<3; i++) {
|
2019-06-03 07:58:51 +02:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'online');
|
|
|
|
}
|
|
|
|
for (i=3; i<6; i++) {
|
2019-06-03 07:58:51 +02:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'dnd');
|
|
|
|
}
|
|
|
|
for (i=6; i<9; i++) {
|
2019-06-03 07:58:51 +02:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'away');
|
|
|
|
}
|
|
|
|
for (i=9; i<12; i++) {
|
2019-06-03 07:58:51 +02:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'xa');
|
|
|
|
}
|
|
|
|
for (i=12; i<15; i++) {
|
2019-06-03 07:58:51 +02:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-05-22 16:13:15 +02:00
|
|
|
_converse.roster.get(jid).presence.set('show', 'unavailable');
|
|
|
|
}
|
2019-10-24 14:29:15 +02:00
|
|
|
|
|
|
|
await u.waitUntil(() => u.isVisible(_converse.rosterview.el.querySelector('li:first-child')), 900);
|
|
|
|
const roster = _converse.rosterview.el;
|
|
|
|
const groups = roster.querySelectorAll('.roster-group');
|
|
|
|
const groupnames = Array.from(groups).map(g => g.getAttribute('data-group'));
|
|
|
|
expect(groupnames.join(' ')).toBe("Colleagues Family friends & acquaintences ænemies Ungrouped");
|
|
|
|
for (let j=0; j<groups.length; j++) {
|
|
|
|
const group = groups[j];
|
|
|
|
const groupname = groupnames[j];
|
|
|
|
const els = Array.from(group.querySelectorAll('.current-xmpp-contact'));
|
|
|
|
expect(els.length).toBe(mock.groups_map[groupname].length);
|
|
|
|
|
|
|
|
if (groupname === "Colleagues") {
|
|
|
|
const statuses = els.map(e => e.getAttribute('data-status'));
|
|
|
|
const subscription_classes = els.map(e => e.classList[3]);
|
|
|
|
const status_classes = els.map(e => e.classList[4]);
|
|
|
|
expect(statuses.join(" ")).toBe("online online away xa xa xa");
|
|
|
|
expect(status_classes.join(" ")).toBe("online online away xa xa xa");
|
|
|
|
expect(subscription_classes.join(" ")).toBe("both both both both both both");
|
|
|
|
} else if (groupname === "friends & acquaintences") {
|
|
|
|
const statuses = els.map(e => e.getAttribute('data-status'));
|
|
|
|
const subscription_classes = els.map(e => e.classList[3]);
|
|
|
|
const status_classes = els.map(e => e.classList[4]);
|
|
|
|
expect(statuses.join(" ")).toBe("online online dnd dnd away unavailable");
|
|
|
|
expect(status_classes.join(" ")).toBe("online online dnd dnd away unavailable");
|
|
|
|
expect(subscription_classes.join(" ")).toBe("both both both both both both");
|
|
|
|
} else if (groupname === "Family") {
|
|
|
|
const statuses = els.map(e => e.getAttribute('data-status'));
|
|
|
|
const subscription_classes = els.map(e => e.classList[3]);
|
|
|
|
const status_classes = els.map(e => e.classList[4]);
|
|
|
|
expect(statuses.join(" ")).toBe("online dnd");
|
|
|
|
expect(status_classes.join(" ")).toBe("online dnd");
|
|
|
|
expect(subscription_classes.join(" ")).toBe("both both");
|
|
|
|
} else if (groupname === "ænemies") {
|
|
|
|
const statuses = els.map(e => e.getAttribute('data-status'));
|
|
|
|
const subscription_classes = els.map(e => e.classList[3]);
|
|
|
|
const status_classes = els.map(e => e.classList[4]);
|
|
|
|
expect(statuses.join(" ")).toBe("away");
|
|
|
|
expect(status_classes.join(" ")).toBe("away");
|
|
|
|
expect(subscription_classes.join(" ")).toBe("both");
|
|
|
|
} else if (groupname === "Ungrouped") {
|
|
|
|
const statuses = els.map(e => e.getAttribute('data-status'));
|
|
|
|
const subscription_classes = els.map(e => e.classList[3]);
|
|
|
|
const status_classes = els.map(e => e.classList[4]);
|
|
|
|
expect(statuses.join(" ")).toBe("unavailable unavailable");
|
|
|
|
expect(status_classes.join(" ")).toBe("unavailable unavailable");
|
|
|
|
expect(subscription_classes.join(" ")).toBe("both both");
|
|
|
|
}
|
2019-05-22 16:13:15 +02:00
|
|
|
}
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Requesting Contacts", function () {
|
|
|
|
|
|
|
|
it("can be added to the roster and they will be sorted alphabetically",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-05-22 16:13:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
2019-05-22 16:13:15 +02:00
|
|
|
let names = [];
|
|
|
|
const addName = function (item) {
|
2019-04-06 16:31:42 +02:00
|
|
|
if (!u.hasClass('request-actions', item)) {
|
|
|
|
names.push(item.textContent.replace(/^\s+|\s+$/g, ''));
|
2017-12-22 16:55:03 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2019-09-04 19:11:26 +02:00
|
|
|
await Promise.all(mock.req_names.map(name => {
|
|
|
|
const contact = _converse.roster.create({
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2017-12-22 16:55:03 +01:00
|
|
|
subscription: 'none',
|
|
|
|
ask: null,
|
|
|
|
requesting: true,
|
2019-09-04 19:11:26 +02:00
|
|
|
nickname: name
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-10-24 17:55:20 +02:00
|
|
|
return u.waitUntil(() => contact.initialized);
|
2019-09-04 19:11:26 +02:00
|
|
|
}));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.get('Contact requests').el.querySelectorAll('li').length, 700);
|
2019-05-22 16:13:15 +02:00
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
const children = _converse.rosterview.get('Contact requests').el.querySelectorAll('.requesting-xmpp-contact span');
|
|
|
|
names = [];
|
|
|
|
Array.from(children).forEach(addName);
|
|
|
|
expect(names.join('')).toEqual(mock.req_names.slice(0,mock.req_names.length+1).sort().join(''));
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("do not have a header if there aren't any",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, "current", 0);
|
2019-04-06 16:31:42 +02:00
|
|
|
const name = mock.req_names[0];
|
2017-12-22 16:55:03 +01:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
'jid': name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
|
|
|
'subscription': 'none',
|
|
|
|
'ask': null,
|
|
|
|
'requesting': true,
|
|
|
|
'nickname': name
|
2017-12-22 16:55:03 +01:00
|
|
|
});
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group', _converse.rosterview.el).filter(u.isVisible).length, 900);
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(u.isVisible(_converse.rosterview.get('Contact requests').el)).toEqual(true);
|
|
|
|
expect(sizzle('.roster-group', _converse.rosterview.el).filter(u.isVisible).map(e => e.querySelector('li')).length).toBe(1);
|
|
|
|
sizzle('.roster-group', _converse.rosterview.el).filter(u.isVisible).map(e => e.querySelector('li .decline-xmpp-request'))[0].click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(u.isVisible(_converse.rosterview.get('Contact requests').el)).toEqual(false);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can be collapsed under their own header",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
|
|
|
test_utils.createContacts(_converse, 'requesting');
|
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group', _converse.rosterview.el).filter(u.isVisible).length, 700);
|
2019-04-06 16:31:42 +02:00
|
|
|
await checkHeaderToggling.apply(
|
|
|
|
_converse,
|
|
|
|
[_converse.rosterview.get('Contact requests').el]
|
|
|
|
);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can have their requests accepted by the user",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-12 12:04:56 +01:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
|
|
|
await test_utils.createContacts(_converse, 'requesting');
|
2019-04-06 16:31:42 +02:00
|
|
|
const name = mock.req_names.sort()[0];
|
2019-06-03 07:58:51 +02:00
|
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-04-06 16:31:42 +02:00
|
|
|
const contact = _converse.roster.get(jid);
|
|
|
|
spyOn(contact, 'authorize').and.callFake(() => contact);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length)
|
2018-11-12 12:04:56 +01:00
|
|
|
// TODO: Testing can be more thorough here, the user is
|
|
|
|
// actually not accepted/authorized because of
|
|
|
|
// mock_connection.
|
|
|
|
spyOn(_converse.roster, 'sendContactAddIQ').and.callFake(() => Promise.resolve());
|
2019-06-03 07:58:51 +02:00
|
|
|
const req_contact = sizzle(`.req-contact-name:contains("${contact.getDisplayName()}")`, _converse.rosterview.el).pop();
|
2019-04-06 16:31:42 +02:00
|
|
|
req_contact.parentElement.parentElement.querySelector('.accept-xmpp-request').click();
|
2018-11-12 12:04:56 +01:00
|
|
|
expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => contact.authorize.calls.count());
|
2018-11-12 12:04:56 +01:00
|
|
|
expect(contact.authorize).toHaveBeenCalled();
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("can have their requests denied by the user",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
|
|
|
await test_utils.createContacts(_converse, 'requesting');
|
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
|
2019-04-06 16:31:42 +02:00
|
|
|
_converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
|
|
|
const name = mock.req_names.sort()[1];
|
2019-06-03 07:58:51 +02:00
|
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-04-06 16:31:42 +02:00
|
|
|
const contact = _converse.roster.get(jid);
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(contact, 'unauthorize').and.callFake(function () { return contact; });
|
2019-09-04 19:11:26 +02:00
|
|
|
const req_contact = await u.waitUntil(() => sizzle(".req-contact-name:contains('"+name+"')", _converse.rosterview.el).pop());
|
2019-04-06 16:31:42 +02:00
|
|
|
req_contact.parentElement.parentElement.querySelector('.decline-xmpp-request').click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(contact.unauthorize).toHaveBeenCalled();
|
|
|
|
// There should now be one less contact
|
|
|
|
expect(_converse.roster.length).toEqual(mock.req_names.length-1);
|
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("are persisted even if other contacts' change their presence ", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {}, async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
|
|
|
/* This is a regression test.
|
|
|
|
* https://github.com/jcbrand/_converse.js/issues/262
|
|
|
|
*/
|
|
|
|
expect(_converse.roster.pluck('jid').length).toBe(0);
|
|
|
|
|
2019-07-29 11:21:00 +02:00
|
|
|
const sent_IQs = _converse.connection.IQ_stanzas;
|
|
|
|
const stanza = await u.waitUntil(() => _.filter(sent_IQs, iq => iq.querySelector('iq query[xmlns="jabber:iq:roster"]')).pop());
|
2019-04-06 16:31:42 +02:00
|
|
|
// Taken from the spec
|
|
|
|
// https://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
|
2019-07-29 11:21:00 +02:00
|
|
|
const result = $iq({
|
2019-04-06 16:31:42 +02:00
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'result',
|
2019-07-29 11:21:00 +02:00
|
|
|
id: stanza.getAttribute('id')
|
2019-04-06 16:31:42 +02:00
|
|
|
}).c('query', {
|
|
|
|
xmlns: 'jabber:iq:roster',
|
|
|
|
}).c('item', {
|
2019-07-29 11:21:00 +02:00
|
|
|
jid: 'juliet@example.net',
|
|
|
|
name: 'Juliet',
|
2019-04-06 16:31:42 +02:00
|
|
|
subscription:'both'
|
|
|
|
}).c('group').t('Friends').up().up()
|
|
|
|
.c('item', {
|
|
|
|
jid: 'mercutio@example.org',
|
|
|
|
name: 'Mercutio',
|
|
|
|
subscription:'from'
|
|
|
|
}).c('group').t('Friends').up().up()
|
2019-07-29 11:21:00 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(result));
|
|
|
|
|
|
|
|
const pres = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(pres));
|
|
|
|
expect(_converse.roster.pluck('jid').length).toBe(1);
|
|
|
|
await u.waitUntil(() => sizzle('a:contains("Contact requests")', _converse.rosterview.el).length, 700);
|
|
|
|
expect(_converse.roster.pluck('jid').includes('data@enterprise')).toBeTruthy();
|
|
|
|
|
|
|
|
const roster_push = $iq({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'set',
|
|
|
|
}).c('query', {'xmlns': 'jabber:iq:roster', 'ver': 'ver34'})
|
|
|
|
.c('item', {
|
|
|
|
jid: 'benvolio@example.org',
|
|
|
|
name: 'Benvolio',
|
|
|
|
subscription:'both'
|
|
|
|
}).c('group').t('Friends');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(roster_push));
|
|
|
|
expect(_converse.roster.data.get('version')).toBe('ver34');
|
|
|
|
expect(_converse.roster.models.length).toBe(4);
|
|
|
|
expect(_converse.roster.pluck('jid').includes('data@enterprise')).toBeTruthy();
|
2019-04-06 16:31:42 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("All Contacts", function () {
|
|
|
|
|
|
|
|
it("are saved to, and can be retrieved from browserStorage",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-10-24 14:29:15 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
|
|
|
await test_utils.createContacts(_converse, 'requesting');
|
|
|
|
await test_utils.openControlBox(_converse);
|
2017-12-22 16:55:03 +01:00
|
|
|
var new_attrs, old_attrs, attrs;
|
|
|
|
var num_contacts = _converse.roster.length;
|
|
|
|
var new_roster = new _converse.RosterContacts();
|
|
|
|
// Roster items are yet to be fetched from browserStorage
|
|
|
|
expect(new_roster.length).toEqual(0);
|
|
|
|
new_roster.browserStorage = _converse.roster.browserStorage;
|
2019-10-24 14:29:15 +02:00
|
|
|
await new Promise(success => new_roster.fetch({success}));
|
2017-12-22 16:55:03 +01:00
|
|
|
expect(new_roster.length).toEqual(num_contacts);
|
|
|
|
// Check that the roster items retrieved from browserStorage
|
|
|
|
// have the same attributes values as the original ones.
|
|
|
|
attrs = ['jid', 'fullname', 'subscription', 'ask'];
|
|
|
|
for (var i=0; i<attrs.length; i++) {
|
|
|
|
new_attrs = _.map(_.map(new_roster.models, 'attributes'), attrs[i]);
|
|
|
|
old_attrs = _.map(_.map(_converse.roster.models, 'attributes'), attrs[i]);
|
|
|
|
// Roster items in storage are not necessarily sorted,
|
|
|
|
// so we have to sort them here to do a proper
|
|
|
|
// comparison
|
|
|
|
expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-05-22 16:13:15 +02:00
|
|
|
it("will show fullname and jid properties on tooltip",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-04-06 16:31:42 +02:00
|
|
|
async function (done, _converse) {
|
2017-12-22 16:55:03 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 'all');
|
|
|
|
await test_utils.createContacts(_converse, 'requesting');
|
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
|
2019-09-04 19:11:26 +02:00
|
|
|
await Promise.all(mock.cur_names.map(async name => {
|
2019-06-03 07:58:51 +02:00
|
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-09-04 19:11:26 +02:00
|
|
|
const el = await u.waitUntil(() => sizzle("li:contains('"+name+"')", _converse.rosterview.el).pop());
|
|
|
|
const child = el.firstElementChild;
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(child.textContent.trim()).toBe(name);
|
|
|
|
expect(child.getAttribute('title')).toContain(name);
|
|
|
|
expect(child.getAttribute('title')).toContain(jid);
|
2019-09-04 19:11:26 +02:00
|
|
|
}));
|
2019-10-24 14:29:15 +02:00
|
|
|
await Promise.all(mock.req_names.map(async name => {
|
|
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
const el = await u.waitUntil(() => sizzle("li:contains('"+name+"')", _converse.rosterview.el).pop());
|
|
|
|
const child = el.firstElementChild;
|
|
|
|
expect(child.textContent.trim()).toBe(name);
|
|
|
|
expect(child.firstElementChild.getAttribute('title')).toContain(jid);
|
|
|
|
}));
|
2019-04-06 16:31:42 +02:00
|
|
|
done();
|
2017-12-22 16:55:03 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|