|
@@ -427,7 +427,7 @@ describe("The Contacts Roster", function () {
|
|
|
|
|
|
const roster = rosterview.querySelector('.roster-contacts');
|
|
const roster = rosterview.querySelector('.roster-contacts');
|
|
await u.waitUntil(() => sizzle('li', roster).filter(u.isVisible).length === 21, 900);
|
|
await u.waitUntil(() => sizzle('li', roster).filter(u.isVisible).length === 21, 900);
|
|
- expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(6);
|
|
|
|
|
|
+ expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(5);
|
|
|
|
|
|
filter.value = "online";
|
|
filter.value = "online";
|
|
u.triggerEvent(filter, 'change');
|
|
u.triggerEvent(filter, 'change');
|
|
@@ -465,7 +465,7 @@ describe("The Contacts Roster", function () {
|
|
// Check that the groups appear alphabetically and that
|
|
// Check that the groups appear alphabetically and that
|
|
// requesting and pending contacts are last.
|
|
// requesting and pending contacts are last.
|
|
const rosterview = document.querySelector('converse-roster');
|
|
const rosterview = document.querySelector('converse-roster');
|
|
- await u.waitUntil(() => sizzle('.roster-group a.group-toggle', rosterview).length === 7);
|
|
|
|
|
|
+ await u.waitUntil(() => sizzle('.roster-group a.group-toggle', rosterview).length === 6);
|
|
let group_titles = sizzle('.roster-group a.group-toggle', rosterview).map(o => o.textContent.trim());
|
|
let group_titles = sizzle('.roster-group a.group-toggle', rosterview).map(o => o.textContent.trim());
|
|
expect(group_titles).toEqual([
|
|
expect(group_titles).toEqual([
|
|
"Contact requests",
|
|
"Contact requests",
|
|
@@ -474,14 +474,13 @@ describe("The Contacts Roster", function () {
|
|
"friends & acquaintences",
|
|
"friends & acquaintences",
|
|
"ænemies",
|
|
"ænemies",
|
|
"Ungrouped",
|
|
"Ungrouped",
|
|
- "Pending contacts",
|
|
|
|
]);
|
|
]);
|
|
|
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
const contact = await _converse.api.contacts.get(contact_jid);
|
|
const contact = await _converse.api.contacts.get(contact_jid);
|
|
contact.save({'num_unread': 5});
|
|
contact.save({'num_unread': 5});
|
|
|
|
|
|
- await u.waitUntil(() => sizzle('.roster-group a.group-toggle', rosterview).length === 8);
|
|
|
|
|
|
+ await u.waitUntil(() => sizzle('.roster-group a.group-toggle', rosterview).length === 7);
|
|
group_titles = sizzle('.roster-group a.group-toggle', rosterview).map(o => o.textContent.trim());
|
|
group_titles = sizzle('.roster-group a.group-toggle', rosterview).map(o => o.textContent.trim());
|
|
|
|
|
|
expect(group_titles).toEqual([
|
|
expect(group_titles).toEqual([
|
|
@@ -492,7 +491,6 @@ describe("The Contacts Roster", function () {
|
|
"friends & acquaintences",
|
|
"friends & acquaintences",
|
|
"ænemies",
|
|
"ænemies",
|
|
"Ungrouped",
|
|
"Ungrouped",
|
|
- "Pending contacts",
|
|
|
|
]);
|
|
]);
|
|
const contacts = sizzle('.roster-group[data-group="New messages"] li', rosterview);
|
|
const contacts = sizzle('.roster-group[data-group="New messages"] li', rosterview);
|
|
expect(contacts.length).toBe(1);
|
|
expect(contacts.length).toBe(1);
|
|
@@ -500,7 +498,7 @@ describe("The Contacts Roster", function () {
|
|
expect(contacts[0].querySelector('.msgs-indicator').textContent).toBe("5");
|
|
expect(contacts[0].querySelector('.msgs-indicator').textContent).toBe("5");
|
|
|
|
|
|
contact.save({'num_unread': 0});
|
|
contact.save({'num_unread': 0});
|
|
- await u.waitUntil(() => sizzle('.roster-group a.group-toggle', rosterview).length === 7);
|
|
|
|
|
|
+ await u.waitUntil(() => sizzle('.roster-group a.group-toggle', rosterview).length === 6);
|
|
group_titles = sizzle('.roster-group a.group-toggle', rosterview).map(o => o.textContent.trim());
|
|
group_titles = sizzle('.roster-group a.group-toggle', rosterview).map(o => o.textContent.trim());
|
|
expect(group_titles).toEqual([
|
|
expect(group_titles).toEqual([
|
|
"Contact requests",
|
|
"Contact requests",
|
|
@@ -509,7 +507,6 @@ describe("The Contacts Roster", function () {
|
|
"friends & acquaintences",
|
|
"friends & acquaintences",
|
|
"ænemies",
|
|
"ænemies",
|
|
"Ungrouped",
|
|
"Ungrouped",
|
|
- "Pending contacts",
|
|
|
|
]);
|
|
]);
|
|
}));
|
|
}));
|
|
|
|
|
|
@@ -522,7 +519,7 @@ describe("The Contacts Roster", function () {
|
|
await mock.waitForRoster(_converse, 'all');
|
|
await mock.waitForRoster(_converse, 'all');
|
|
await mock.createContacts(_converse, 'requesting');
|
|
await mock.createContacts(_converse, 'requesting');
|
|
const rosterview = document.querySelector('converse-roster');
|
|
const rosterview = document.querySelector('converse-roster');
|
|
- await u.waitUntil(() => sizzle('.roster-group a.group-toggle', rosterview).length === 7);
|
|
|
|
|
|
+ await u.waitUntil(() => sizzle('.roster-group a.group-toggle', rosterview).length === 6);
|
|
const group_titles = sizzle('.roster-group a.group-toggle', rosterview).map(o => o.textContent.trim());
|
|
const group_titles = sizzle('.roster-group a.group-toggle', rosterview).map(o => o.textContent.trim());
|
|
expect(group_titles).toEqual([
|
|
expect(group_titles).toEqual([
|
|
"Contact requests",
|
|
"Contact requests",
|
|
@@ -531,7 +528,6 @@ describe("The Contacts Roster", function () {
|
|
"friends & acquaintences",
|
|
"friends & acquaintences",
|
|
"ænemies",
|
|
"ænemies",
|
|
"Ungrouped",
|
|
"Ungrouped",
|
|
- "Pending contacts",
|
|
|
|
]);
|
|
]);
|
|
// Check that usernames appear alphabetically per group
|
|
// Check that usernames appear alphabetically per group
|
|
Object.keys(mock.groups).forEach(name => {
|
|
Object.keys(mock.groups).forEach(name => {
|
|
@@ -650,17 +646,6 @@ describe("The Contacts Roster", function () {
|
|
|
|
|
|
describe("Pending Contacts", function () {
|
|
describe("Pending Contacts", function () {
|
|
|
|
|
|
- it("can be collapsed under their own header (if roster_groups is false)",
|
|
|
|
- mock.initConverse([], {'roster_groups': false}, async function (_converse) {
|
|
|
|
-
|
|
|
|
- await mock.openControlBox(_converse);
|
|
|
|
- await mock.waitForRoster(_converse, 'all');
|
|
|
|
- await Promise.all(_converse.roster.map(contact => u.waitUntil(() => contact.vcard.get('fullname'))));
|
|
|
|
- const rosterview = document.querySelector('converse-roster');
|
|
|
|
- await u.waitUntil(() => sizzle('.roster-group', rosterview).filter(u.isVisible).map(e => e.querySelector('li')).length, 1000);
|
|
|
|
- await checkHeaderToggling.apply(_converse, [rosterview.querySelector('[data-group="Pending contacts"]')]);
|
|
|
|
- }));
|
|
|
|
-
|
|
|
|
it("can be added to the roster",
|
|
it("can be added to the roster",
|
|
mock.initConverse(
|
|
mock.initConverse(
|
|
[], {},
|
|
[], {},
|
|
@@ -691,7 +676,9 @@ describe("The Contacts Roster", function () {
|
|
await u.waitUntil(() => sizzle('li', rosterview).filter(u.isVisible).length, 500)
|
|
await u.waitUntil(() => sizzle('li', rosterview).filter(u.isVisible).length, 500)
|
|
expect(u.isVisible(rosterview)).toBe(true);
|
|
expect(u.isVisible(rosterview)).toBe(true);
|
|
expect(sizzle('li', rosterview).filter(u.isVisible).length).toBe(4);
|
|
expect(sizzle('li', rosterview).filter(u.isVisible).length).toBe(4);
|
|
- expect(sizzle('ul.roster-group-contacts', rosterview).filter(u.isVisible).length).toBe(2);
|
|
|
|
|
|
+ expect(sizzle('ul.roster-group-contacts', rosterview).filter(u.isVisible).length).toBe(1);
|
|
|
|
+ const el = sizzle('ul.roster-group-contacts', rosterview).filter(u.isVisible).pop();
|
|
|
|
+ expect(el.getAttribute('data-group')).toBe('Ungrouped');
|
|
}));
|
|
}));
|
|
|
|
|
|
it("can be removed by the user", mock.initConverse([], {'roster_groups': false}, async function (_converse) {
|
|
it("can be removed by the user", mock.initConverse([], {'roster_groups': false}, async function (_converse) {
|
|
@@ -715,51 +702,12 @@ describe("The Contacts Roster", function () {
|
|
await u.waitUntil(() => !sizzle(`.pending-xmpp-contact .contact-name:contains("${name}")`, rosterview).length, 500);
|
|
await u.waitUntil(() => !sizzle(`.pending-xmpp-contact .contact-name:contains("${name}")`, rosterview).length, 500);
|
|
expect(_converse.api.confirm).toHaveBeenCalled();
|
|
expect(_converse.api.confirm).toHaveBeenCalled();
|
|
expect(contact.sendRosterRemoveStanza).toHaveBeenCalled();
|
|
expect(contact.sendRosterRemoveStanza).toHaveBeenCalled();
|
|
- expect(Strophe.serialize(sent_IQ)).toBe(
|
|
|
|
- `<iq type="set" xmlns="jabber:client">`+
|
|
|
|
- `<query xmlns="jabber:iq:roster">`+
|
|
|
|
- `<item jid="lord.capulet@montague.lit" subscription="remove"/>`+
|
|
|
|
- `</query>`+
|
|
|
|
- `</iq>`);
|
|
|
|
- }));
|
|
|
|
-
|
|
|
|
- it("do not have a header if there aren't any",
|
|
|
|
- mock.initConverse(
|
|
|
|
- ['VCardsInitialized'], {'roster_groups': false},
|
|
|
|
- async function (_converse) {
|
|
|
|
-
|
|
|
|
- await mock.openControlBox(_converse);
|
|
|
|
- await mock.waitForRoster(_converse, 'current', 0);
|
|
|
|
- const name = mock.pend_names[0];
|
|
|
|
- _converse.roster.create({
|
|
|
|
- jid: name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
|
|
|
- subscription: 'none',
|
|
|
|
- ask: 'subscribe',
|
|
|
|
- fullname: name
|
|
|
|
- });
|
|
|
|
- const rosterview = document.querySelector('converse-roster');
|
|
|
|
- await u.waitUntil(() => {
|
|
|
|
- const el = rosterview.querySelector(`ul[data-group="Pending contacts"]`);
|
|
|
|
- return u.isVisible(el) && Array.from(el.querySelectorAll('li')).filter(li => u.isVisible(li)).length;
|
|
|
|
- }, 700)
|
|
|
|
-
|
|
|
|
- const remove_el = await u.waitUntil(() => sizzle(`.remove-xmpp-contact[title="Click to remove ${name} as a contact"]`, rosterview).pop());
|
|
|
|
- spyOn(_converse.api, 'confirm').and.callFake(() => Promise.resolve(true));
|
|
|
|
- remove_el.click();
|
|
|
|
- expect(_converse.api.confirm).toHaveBeenCalled();
|
|
|
|
-
|
|
|
|
- const iq_stanzas = _converse.api.connection.get().IQ_stanzas;
|
|
|
|
- await u.waitUntil(() => Strophe.serialize(iq_stanzas.at(-1)) ===
|
|
|
|
- `<iq id="${iq_stanzas.at(-1).getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
|
|
|
- `<query xmlns="jabber:iq:roster">`+
|
|
|
|
- `<item jid="lord.capulet@montague.lit" subscription="remove"/>`+
|
|
|
|
- `</query>`+
|
|
|
|
- `</iq>`);
|
|
|
|
-
|
|
|
|
- const iq = iq_stanzas.at(-1);
|
|
|
|
- const stanza = stx`<iq id="${iq.getAttribute('id')}" to="romeo@montague.lit/orchard" type="result" xmlns="jabber:client"/>`;
|
|
|
|
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
|
|
|
|
- await u.waitUntil(() => rosterview.querySelector(`ul[data-group="Pending contacts"]`) === null);
|
|
|
|
|
|
+ expect(sent_IQ).toEqualStanza(stx`
|
|
|
|
+ <iq type="set" xmlns="jabber:client">
|
|
|
|
+ <query xmlns="jabber:iq:roster">
|
|
|
|
+ <item jid="lord.capulet@montague.lit" subscription="remove"/>
|
|
|
|
+ </query>
|
|
|
|
+ </iq>`);
|
|
}));
|
|
}));
|
|
|
|
|
|
it("can be removed by the user",
|
|
it("can be removed by the user",
|
|
@@ -793,36 +741,6 @@ describe("The Contacts Roster", function () {
|
|
}
|
|
}
|
|
await u.waitUntil(() => rosterview.querySelector(`ul[data-group="Pending contacts"]`) === null);
|
|
await u.waitUntil(() => rosterview.querySelector(`ul[data-group="Pending contacts"]`) === null);
|
|
}));
|
|
}));
|
|
-
|
|
|
|
- it("can be added to the roster and they will be sorted alphabetically",
|
|
|
|
- mock.initConverse(
|
|
|
|
- [], {'roster_groups': false},
|
|
|
|
- async function (_converse) {
|
|
|
|
-
|
|
|
|
- await mock.openControlBox(_converse);
|
|
|
|
- await mock.waitForRoster(_converse, 'current');
|
|
|
|
- await Promise.all(_converse.roster.map(contact => u.waitUntil(() => contact.vcard.get('fullname'))));
|
|
|
|
- let i;
|
|
|
|
- for (i=0; i<mock.pend_names.length; i++) {
|
|
|
|
- _converse.roster.create({
|
|
|
|
- jid: mock.pend_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
|
|
|
- subscription: 'none',
|
|
|
|
- ask: 'subscribe',
|
|
|
|
- fullname: mock.pend_names[i]
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- const rosterview = document.querySelector('converse-roster');
|
|
|
|
- await u.waitUntil(() => sizzle('li', rosterview.querySelector(`ul[data-group="Pending contacts"]`)).filter(u.isVisible).length);
|
|
|
|
- // Check that they are sorted alphabetically
|
|
|
|
- const el = await u.waitUntil(() => rosterview.querySelector(`ul[data-group="Pending contacts"]`));
|
|
|
|
- const spans = el.querySelectorAll('.pending-xmpp-contact .contact-name');
|
|
|
|
-
|
|
|
|
- await u.waitUntil(
|
|
|
|
- () => Array.from(spans).reduce((result, value) => result + value.textContent?.trim(), '') ===
|
|
|
|
- mock.pend_names.slice(0,i+1).sort().join('')
|
|
|
|
- );
|
|
|
|
- expect(true).toBe(true);
|
|
|
|
- }));
|
|
|
|
});
|
|
});
|
|
|
|
|
|
describe("Existing Contacts", function () {
|
|
describe("Existing Contacts", function () {
|
|
@@ -1279,20 +1197,46 @@ describe("The Contacts Roster", function () {
|
|
await mock.createContacts(_converse, 'requesting');
|
|
await mock.createContacts(_converse, 'requesting');
|
|
const name = mock.req_names.sort()[0];
|
|
const name = mock.req_names.sort()[0];
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
const jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
- const contact = _converse.roster.get(jid);
|
|
|
|
- spyOn(contact, 'authorize').and.callFake(() => contact);
|
|
|
|
|
|
+ const { api, roster } = _converse;
|
|
|
|
+ const contact = roster.get(jid);
|
|
|
|
+ spyOn(contact, 'authorize').and.callThrough();
|
|
const rosterview = document.querySelector('converse-roster');
|
|
const rosterview = document.querySelector('converse-roster');
|
|
await u.waitUntil(() => rosterview.querySelectorAll('.roster-group li').length)
|
|
await u.waitUntil(() => rosterview.querySelectorAll('.roster-group li').length)
|
|
- // 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());
|
|
|
|
|
|
|
|
const req_contact = sizzle(`.contact-name:contains("${contact.getDisplayName()}")`, rosterview).pop();
|
|
const req_contact = sizzle(`.contact-name:contains("${contact.getDisplayName()}")`, rosterview).pop();
|
|
req_contact.parentElement.parentElement.querySelector('.accept-xmpp-request').click();
|
|
req_contact.parentElement.parentElement.querySelector('.accept-xmpp-request').click();
|
|
- expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
|
|
|
|
|
|
+
|
|
|
|
+ const modal = _converse.api.modal.get('converse-accept-contact-request-modal');
|
|
|
|
+ await u.waitUntil(() => u.isVisible(modal), 1000);
|
|
|
|
+
|
|
|
|
+ expect(modal.querySelector('input[name="name"]')?.value).toBe('Escalus, prince of Verona');
|
|
|
|
+ const group_input = modal.querySelector('input[name="group"]');
|
|
|
|
+ group_input.value = 'Princes';
|
|
|
|
+
|
|
|
|
+ const sent_stanzas = _converse.api.connection.get().sent_stanzas;
|
|
|
|
+ while (sent_stanzas.length) sent_stanzas.pop();
|
|
|
|
+
|
|
|
|
+ modal.querySelector('button[type="submit"]').click();
|
|
|
|
+
|
|
|
|
+ let stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.matches('iq[type="set"]')).pop());
|
|
|
|
+ expect(stanza).toEqualStanza(
|
|
|
|
+ stx`<iq type="set" xmlns="jabber:client" id="${stanza.getAttribute('id')}">
|
|
|
|
+ <query xmlns="jabber:iq:roster">
|
|
|
|
+ <item jid="${contact.get('jid')}" name="Escalus, prince of Verona"/>
|
|
|
|
+ </query>
|
|
|
|
+ </iq>`);
|
|
|
|
+
|
|
|
|
+ const result = stx`
|
|
|
|
+ <iq to="${api.connection.get().jid}" type="result" id="${stanza.getAttribute('id')}" xmlns="jabber:client"/>`;
|
|
|
|
+ api.connection.get()._dataRecv(mock.createRequest(result));
|
|
|
|
+
|
|
|
|
+ stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.matches('presence[type="subscribed"]')).pop());
|
|
|
|
+ expect(stanza).toEqualStanza(
|
|
|
|
+ stx`<presence to="${contact.get('jid')}" type="subscribed" xmlns="jabber:client"/>`);
|
|
|
|
+
|
|
await u.waitUntil(() => contact.authorize.calls.count());
|
|
await u.waitUntil(() => contact.authorize.calls.count());
|
|
expect(contact.authorize).toHaveBeenCalled();
|
|
expect(contact.authorize).toHaveBeenCalled();
|
|
|
|
+ expect(contact.get('groups')).toEqual(['Princes']);
|
|
}));
|
|
}));
|
|
|
|
|
|
it("can have their requests denied by the user",
|
|
it("can have their requests denied by the user",
|