|
@@ -52,35 +52,8 @@ describe("The 'Add Contact' widget", function () {
|
|
</iq>`);
|
|
</iq>`);
|
|
}));
|
|
}));
|
|
|
|
|
|
- it("can be configured to not provide search suggestions",
|
|
|
|
- mock.initConverse([], {'autocomplete_add_contact': false}, async function (_converse) {
|
|
|
|
-
|
|
|
|
- await mock.waitForRoster(_converse, 'all', 0);
|
|
|
|
- await mock.openControlBox(_converse);
|
|
|
|
- const cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
- cbview.querySelector('.add-contact').click()
|
|
|
|
- const modal = _converse.api.modal.get('converse-add-contact-modal');
|
|
|
|
- expect(modal.jid_auto_complete).toBe(undefined);
|
|
|
|
- expect(modal.name_auto_complete).toBe(undefined);
|
|
|
|
-
|
|
|
|
- await u.waitUntil(() => u.isVisible(modal), 1000);
|
|
|
|
- expect(modal.querySelector('form.add-xmpp-contact')).not.toBe(null);
|
|
|
|
- const input_jid = modal.querySelector('input[name="jid"]');
|
|
|
|
- input_jid.value = 'someone@montague.lit';
|
|
|
|
- modal.querySelector('button[type="submit"]').click();
|
|
|
|
-
|
|
|
|
- const IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
|
|
|
|
- const sent_stanza = await u.waitUntil(
|
|
|
|
- () => IQ_stanzas.filter(s => sizzle(`iq[type="set"] query[xmlns="${Strophe.NS.ROSTER}"]`, s).length).pop()
|
|
|
|
- );
|
|
|
|
- expect(sent_stanza).toEqualStanza(stx`
|
|
|
|
- <iq id="${sent_stanza.getAttribute('id')}" type="set" xmlns="jabber:client">
|
|
|
|
- <query xmlns="jabber:iq:roster"><item jid="someone@montague.lit"/></query>
|
|
|
|
- </iq>`);
|
|
|
|
- }));
|
|
|
|
-
|
|
|
|
it("integrates with xhr_user_search_url to search for contacts",
|
|
it("integrates with xhr_user_search_url to search for contacts",
|
|
- mock.initConverse([], { 'xhr_user_search_url': 'http://example.org/?' },
|
|
|
|
|
|
+ mock.initConverse([], { xhr_user_search_url: 'http://example.org/?' },
|
|
async function (_converse) {
|
|
async function (_converse) {
|
|
|
|
|
|
await mock.waitForRoster(_converse, 'all', 0);
|
|
await mock.waitForRoster(_converse, 'all', 0);
|
|
@@ -99,96 +72,29 @@ describe("The 'Add Contact' widget", function () {
|
|
const modal = _converse.api.modal.get('converse-add-contact-modal');
|
|
const modal = _converse.api.modal.get('converse-add-contact-modal');
|
|
await u.waitUntil(() => u.isVisible(modal), 1000);
|
|
await u.waitUntil(() => u.isVisible(modal), 1000);
|
|
|
|
|
|
-
|
|
|
|
- const input_el = modal.querySelector('input[name="name"]');
|
|
|
|
|
|
+ const input_el = modal.querySelector('input[name="jid"]');
|
|
input_el.value = 'marty';
|
|
input_el.value = 'marty';
|
|
input_el.dispatchEvent(new Event('input'));
|
|
input_el.dispatchEvent(new Event('input'));
|
|
|
|
+
|
|
await u.waitUntil(() => modal.querySelector('.suggestion-box li'), 1000);
|
|
await u.waitUntil(() => modal.querySelector('.suggestion-box li'), 1000);
|
|
expect(modal.querySelectorAll('.suggestion-box li').length).toBe(1);
|
|
expect(modal.querySelectorAll('.suggestion-box li').length).toBe(1);
|
|
const suggestion = modal.querySelector('.suggestion-box li');
|
|
const suggestion = modal.querySelector('.suggestion-box li');
|
|
- expect(suggestion.textContent).toBe('Marty McFly');
|
|
|
|
|
|
+ expect(suggestion.textContent).toBe('Marty McFly <marty@mcfly.net>');
|
|
|
|
|
|
const el = u.ancestor(suggestion, 'converse-autocomplete');
|
|
const el = u.ancestor(suggestion, 'converse-autocomplete');
|
|
el.auto_complete.select(suggestion);
|
|
el.auto_complete.select(suggestion);
|
|
|
|
|
|
- expect(input_el.value.trim()).toBe('Marty McFly');
|
|
|
|
- // TODO: We only have autocomplete for the name input
|
|
|
|
- return;
|
|
|
|
|
|
+ expect(input_el.value.trim()).toBe('Marty McFly <marty@mcfly.net>');
|
|
|
|
|
|
- expect(modal.querySelector('input[name="jid"]').value).toBe('marty@mcfly.net');
|
|
|
|
- modal.querySelector('button[type="submit"]').click();
|
|
|
|
-
|
|
|
|
- const sent_IQs = _converse.api.connection.get().IQ_stanzas;
|
|
|
|
- const sent_stanza = await u.waitUntil(() => sent_IQs.filter(iq => iq.querySelector(`iq[type="set"] query[xmlns="${Strophe.NS.ROSTER}"]`)).pop());
|
|
|
|
- expect(Strophe.serialize(sent_stanza)).toEqual(
|
|
|
|
- `<iq id="${sent_stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
|
|
|
- `<query xmlns="jabber:iq:roster"><item jid="marty@mcfly.net" name="Marty McFly"/></query>`+
|
|
|
|
- `</iq>`);
|
|
|
|
- window.XMLHttpRequest = XMLHttpRequestBackup;
|
|
|
|
- }));
|
|
|
|
-
|
|
|
|
- it("can be configured to not provide search suggestions for XHR search results",
|
|
|
|
- mock.initConverse([],
|
|
|
|
- { 'autocomplete_add_contact': false,
|
|
|
|
- 'xhr_user_search_url': 'http://example.org/?' },
|
|
|
|
- async function (_converse) {
|
|
|
|
-
|
|
|
|
- await mock.waitForRoster(_converse, 'all');
|
|
|
|
- await mock.openControlBox(_converse);
|
|
|
|
-
|
|
|
|
- spyOn(window, 'fetch').and.callFake(() => {
|
|
|
|
- let json;
|
|
|
|
- const value = modal.querySelector('input[name="name"]').value;
|
|
|
|
- if (value === 'existing') {
|
|
|
|
- const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
- json = [{"jid": contact_jid, "fullname": mock.cur_names[0]}];
|
|
|
|
- } else if (value === 'romeo') {
|
|
|
|
- json = [{"jid": "romeo@montague.lit", "fullname": "Romeo Montague"}];
|
|
|
|
- } else if (value === 'ambiguous') {
|
|
|
|
- json = [
|
|
|
|
- {"jid": "marty@mcfly.net", "fullname": "Marty McFly"},
|
|
|
|
- {"jid": "doc@brown.com", "fullname": "Doc Brown"}
|
|
|
|
- ];
|
|
|
|
- } else if (value === 'insufficient') {
|
|
|
|
- json = [];
|
|
|
|
- } else {
|
|
|
|
- json = [{"jid": "marty@mcfly.net", "fullname": "Marty McFly"}];
|
|
|
|
- }
|
|
|
|
- return { json };
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- const cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
- cbview.querySelector('.add-contact').click()
|
|
|
|
- const modal = _converse.api.modal.get('converse-add-contact-modal');
|
|
|
|
- await u.waitUntil(() => u.isVisible(modal), 1000);
|
|
|
|
-
|
|
|
|
- expect(modal.jid_auto_complete).toBe(undefined);
|
|
|
|
- expect(modal.name_auto_complete).toBe(undefined);
|
|
|
|
-
|
|
|
|
- const input_el = modal.querySelector('input[name="name"]');
|
|
|
|
- input_el.value = 'ambiguous';
|
|
|
|
- modal.querySelector('button[type="submit"]').click();
|
|
|
|
-
|
|
|
|
- const feedback_el = await u.waitUntil(() => modal.querySelector('.alert-danger'));
|
|
|
|
- expect(feedback_el.textContent).toBe('Sorry, could not find a contact with that name');
|
|
|
|
-
|
|
|
|
- input_el.value = 'existing';
|
|
|
|
- modal.querySelector('button[type="submit"]').click();
|
|
|
|
- await u.waitUntil(() => feedback_el.textContent === 'This contact has already been added');
|
|
|
|
-
|
|
|
|
- input_el.value = 'insufficient';
|
|
|
|
- modal.querySelector('button[type="submit"]').click();
|
|
|
|
- await u.waitUntil(() => feedback_el.textContent === 'Sorry, could not find a contact with that name');
|
|
|
|
-
|
|
|
|
- input_el.value = 'Marty McFly';
|
|
|
|
modal.querySelector('button[type="submit"]').click();
|
|
modal.querySelector('button[type="submit"]').click();
|
|
|
|
|
|
const sent_IQs = _converse.api.connection.get().IQ_stanzas;
|
|
const sent_IQs = _converse.api.connection.get().IQ_stanzas;
|
|
const sent_stanza = await u.waitUntil(() => sent_IQs.filter(
|
|
const sent_stanza = await u.waitUntil(() => sent_IQs.filter(
|
|
iq => sizzle(`iq[type="set"] query[xmlns="${Strophe.NS.ROSTER}"]`, iq).length).pop());
|
|
iq => sizzle(`iq[type="set"] query[xmlns="${Strophe.NS.ROSTER}"]`, iq).length).pop());
|
|
|
|
+
|
|
expect(sent_stanza).toEqualStanza(stx`
|
|
expect(sent_stanza).toEqualStanza(stx`
|
|
<iq id="${sent_stanza.getAttribute('id')}" type="set" xmlns="jabber:client">
|
|
<iq id="${sent_stanza.getAttribute('id')}" type="set" xmlns="jabber:client">
|
|
- <query xmlns="jabber:iq:roster"><item jid="marty@mcfly.net" name="Marty McFly"></item></query>
|
|
|
|
|
|
+ <query xmlns="jabber:iq:roster"><item jid="marty@mcfly.net" name="Marty McFly"/></query>
|
|
</iq>`);
|
|
</iq>`);
|
|
}));
|
|
}));
|
|
});
|
|
});
|