Commit a1630b5c authored by JC Brand's avatar JC Brand

Replace wait-until-promise with utility method

and bump default timeout

Also let `_converse.api.waitUntil` use it if a function is passed in.
parent 8a98ef87
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -59,7 +59,7 @@
ask: 'subscribe',
fullname: mock.pend_names[0]
});
await test_utils.waitUntil(() => _.filter(_converse.rosterview.el.querySelectorAll('.roster-group li'), u.isVisible).length, 700);
await u.waitUntil(() => _.filter(_converse.rosterview.el.querySelectorAll('.roster-group li'), u.isVisible).length, 700);
// Checking that only one entry is created because both JID is same (Case sensitive check)
expect(_.filter(_converse.rosterview.el.querySelectorAll('li'), u.isVisible).length).toBe(1);
expect(_converse.rosterview.update).toHaveBeenCalled();
......@@ -76,7 +76,7 @@
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await test_utils.openChatBoxFor(_converse, sender_jid);
await test_utils.waitUntil(() => _converse.chatboxes.length);
await u.waitUntil(() => _converse.chatboxes.length);
const chatview = _converse.chatboxviews.get(sender_jid);
chatview.model.set({'minimized': true});
......@@ -91,7 +91,7 @@
}).c('body').t('hello').up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
_converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll(".msgs-indicator").length);
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll(".msgs-indicator").length);
spyOn(chatview.model, 'incrementUnreadMsgCounter').and.callThrough();
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('1');
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('1');
......@@ -104,7 +104,7 @@
}).c('body').t('hello again').up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
_converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => chatview.model.incrementUnreadMsgCounter.calls.count());
await u.waitUntil(() => chatview.model.incrementUnreadMsgCounter.calls.count());
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('2');
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('2');
chatview.model.set({'minimized': false});
......@@ -139,7 +139,7 @@
cbview.el.querySelector('.change-status').click()
var modal = _converse.xmppstatusview.status_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
const view = _converse.xmppstatusview;
modal.el.querySelector('label[for="radio-busy"]').click(); // Change status to "dnd"
modal.el.querySelector('[type="submit"]').click();
......@@ -168,7 +168,7 @@
cbview.el.querySelector('.change-status').click()
const modal = _converse.xmppstatusview.status_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
const view = _converse.xmppstatusview;
const msg = 'I am happy';
modal.el.querySelector('input[name="status_message"]').value = msg;
......@@ -202,7 +202,7 @@
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.add-contact').click()
const modal = _converse.rosterview.add_contact_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
const sendIQ = _converse.connection.sendIQ;
let sent_stanza, IQ_id;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
......@@ -240,7 +240,7 @@
expect(modal.jid_auto_complete).toBe(undefined);
expect(modal.name_auto_complete).toBe(undefined);
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
expect(!_.isNull(modal.el.querySelector('form.add-xmpp-contact'))).toBeTruthy();
const input_jid = modal.el.querySelector('input[name="jid"]');
const input_name = modal.el.querySelector('input[name="name"]');
......@@ -248,7 +248,7 @@
modal.el.querySelector('button[type="submit"]').click();
const IQ_stanzas = _converse.connection.IQ_stanzas;
const sent_stanza = await test_utils.waitUntil(
const sent_stanza = await u.waitUntil(
() => IQ_stanzas.filter(s => sizzle(`query[xmlns="${Strophe.NS.ROSTER}"]`, s).length).pop()
);
expect(Strophe.serialize(sent_stanza)).toEqual(
......@@ -284,7 +284,7 @@
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.add-contact').click()
const modal = _converse.rosterview.add_contact_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
// We only have autocomplete for the name input
expect(modal.jid_auto_complete).toBe(undefined);
......@@ -293,7 +293,7 @@
const input_el = modal.el.querySelector('input[name="name"]');
input_el.value = 'marty';
input_el.dispatchEvent(new Event('input'));
await test_utils.waitUntil(() => modal.el.querySelector('.suggestion-box li'), 1000);
await u.waitUntil(() => modal.el.querySelector('.suggestion-box li'), 1000);
const sendIQ = _converse.connection.sendIQ;
let sent_stanza, IQ_id;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
......@@ -357,7 +357,7 @@
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.add-contact').click()
modal = _converse.rosterview.add_contact_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
expect(modal.jid_auto_complete).toBe(undefined);
expect(modal.name_auto_complete).toBe(undefined);
......
......@@ -271,10 +271,10 @@
expect(box.get('box_id')).toBe(`box-${btoa(jid)}`);
const view = _converse.chatboxviews.get(jid);
await test_utils.waitUntil(() => u.isVisible(view.el));
await u.waitUntil(() => u.isVisible(view.el));
// Test for multiple JIDs
test_utils.openChatBoxFor(_converse, jid2);
await test_utils.waitUntil(() => _converse.chatboxes.length == 2);
await u.waitUntil(() => _converse.chatboxes.length == 2);
const list = _converse.api.chats.get([jid, jid2]);
expect(Array.isArray(list)).toBeTruthy();
expect(list[0].get('box_id')).toBe(`box-${btoa(jid)}`);
......@@ -303,7 +303,7 @@
['close', 'endOTR', 'focus', 'get', 'initiateOTR', 'is_chatroom', 'maximize', 'minimize', 'open', 'set']
);
const view = _converse.chatboxviews.get(jid);
await test_utils.waitUntil(() => u.isVisible(view.el));
await u.waitUntil(() => u.isVisible(view.el));
// Test for multiple JIDs
const list = await _converse.api.chats.open([jid, jid2]);
expect(Array.isArray(list)).toBeTruthy();
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,6 +2,8 @@
define(["jasmine", "mock", "test-utils"], factory);
} (this, function (jasmine, mock, test_utils) {
const u = converse.env.utils;
describe("The Login Form", function () {
it("contains a checkbox to indicate whether the computer is trusted or not",
......@@ -12,7 +14,7 @@
async function (done, _converse) {
test_utils.openControlBox();
const cbview = await test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'));
const cbview = await u.waitUntil(() => _converse.chatboxviews.get('controlbox'));
const checkboxes = cbview.el.querySelectorAll('input[type="checkbox"]');
expect(checkboxes.length).toBe(1);
......@@ -46,7 +48,7 @@
allow_registration: false },
function (done, _converse) {
test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'))
u.waitUntil(() => _converse.chatboxviews.get('controlbox'))
.then(() => {
var cbview = _converse.chatboxviews.get('controlbox');
test_utils.openControlBox();
......
This diff is collapsed.
This diff is collapsed.
......@@ -66,7 +66,7 @@
expect(u.isVisible(_converse.minimized_chats.el.querySelector('.minimized-chats-flyout'))).toBeTruthy();
expect(_converse.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
_converse.minimized_chats.el.querySelector('#toggle-minimized-chats').click();
await test_utils.waitUntil(() => u.isVisible(_converse.minimized_chats.el.querySelector('.minimized-chats-flyout')));
await u.waitUntil(() => u.isVisible(_converse.minimized_chats.el.querySelector('.minimized-chats-flyout')));
expect(_converse.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
done();
}));
......@@ -93,7 +93,7 @@
contact_jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
test_utils.openChatBoxFor(_converse, contact_jid);
}
test_utils.waitUntil(() => _converse.chatboxes.length == 4).then(() => {
u.waitUntil(() => _converse.chatboxes.length == 4).then(() => {
for (i=0; i<3; i++) {
chatview = _converse.chatboxviews.get(contact_jid);
chatview.model.set({'minimized': true});
......@@ -106,7 +106,7 @@
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
_converse.chatboxes.onMessage(msg);
}
return test_utils.waitUntil(() => chatview.model.messages.length);
return u.waitUntil(() => chatview.model.messages.length);
}).then(() => {
expect(u.isVisible(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count'))).toBeTruthy();
expect(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count').textContent).toBe((3).toString());
......@@ -169,7 +169,7 @@
type: 'groupchat'
}).c('body').t(message).tree();
view.model.onMessage(msg);
await test_utils.waitUntil(() => view.model.messages.length);
await u.waitUntil(() => view.model.messages.length);
expect(u.isVisible(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count'))).toBeTruthy();
expect(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count').textContent).toBe('1');
done();
......
This diff is collapsed.
......@@ -2,9 +2,10 @@
define(["jasmine", "mock", "test-utils"], factory);
} (this, function (jasmine, mock, test_utils) {
"use strict";
const Strophe = converse.env.Strophe,
_ = converse.env._,
$msg = converse.env.$msg;
const Strophe = converse.env.Strophe;
const _ = converse.env._;
const $msg = converse.env.$msg;
const u = converse.env.utils;
describe("Notifications", function () {
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
......@@ -35,7 +36,7 @@
}).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
await _converse.chatboxes.onMessage(msg); // This will emit 'message'
await test_utils.waitUntil(() => _converse.api.chatviews.get(sender_jid));
await u.waitUntil(() => _converse.api.chatviews.get(sender_jid));
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showMessageNotification).toHaveBeenCalled();
done();
......@@ -102,7 +103,7 @@
.c('x', {'xmlns': 'jabber:x:oob'})
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.chatboxviews.keys().length);
await u.waitUntil(() => _converse.chatboxviews.keys().length);
const view = _converse.chatboxviews.get('notify.example.com');
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(
......@@ -188,7 +189,7 @@
type: 'groupchat'
}).c('body').t(text);
await view.model.onMessage(message.nodeTree);
await test_utils.waitUntil(() => _converse.playSoundNotification.calls.count());
await u.waitUntil(() => _converse.playSoundNotification.calls.count());
expect(_converse.playSoundNotification).toHaveBeenCalled();
text = "This message won't play a sound";
......
This diff is collapsed.
......@@ -86,7 +86,7 @@
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.change-status').click()
const modal = _converse.xmppstatusview.status_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
const msg = 'My custom status';
modal.el.querySelector('input[name="status_message"]').value = msg;
modal.el.querySelector('[type="submit"]').click();
......@@ -98,9 +98,9 @@
`<c hash="sha-1" node="https://conversejs.org" ver="Hxbsr5fazs62i+O0GxIXf2OEDNs=" xmlns="http://jabber.org/protocol/caps"/>`+
`</presence>`)
await test_utils.waitUntil(() => modal.el.getAttribute('aria-hidden') === "true");
await u.waitUntil(() => modal.el.getAttribute('aria-hidden') === "true");
cbview.el.querySelector('.change-status').click()
await test_utils.waitUntil(() => modal.el.getAttribute('aria-hidden') === "false", 1000);
await u.waitUntil(() => modal.el.getAttribute('aria-hidden') === "false", 1000);
modal.el.querySelector('label[for="radio-busy"]').click(); // Change status to "dnd"
modal.el.querySelector('[type="submit"]').click();
expect(_converse.connection.send.calls.mostRecent().args[0].toLocaleString())
......
......@@ -64,7 +64,7 @@
});
_converse.roster.onReceivedFromServer(stanza.tree());
return test_utils.waitUntil(function () {
return u.waitUntil(function () {
var $group = _converse.rosterview.$el.find('.roster-group')
return $group.length && u.isVisible($group[0]);
}).then(function () {
......@@ -75,7 +75,7 @@
count += 1;
}
});
return test_utils.waitUntil(function () {
return u.waitUntil(function () {
return _converse.rosterview.$el.find('li.online').length
})
}).then(done);
......@@ -109,7 +109,7 @@
});
_converse.roster.onReceivedFromServer(stanza.tree());
return test_utils.waitUntil(function () {
return u.waitUntil(function () {
var $group = _converse.rosterview.$el.find('.roster-group')
return $group.length && u.isVisible($group[0]);
}).then(function () {
......@@ -124,7 +124,7 @@
}
});
});
return test_utils.waitUntil(function () {
return u.waitUntil(function () {
return _converse.rosterview.$el.find('li.online').length
})
}).then(done);
......
......@@ -56,7 +56,7 @@
let contact, sent_stanza, IQ_id, stanza;
await test_utils.waitUntilDiscoConfirmed(_converse, 'montague.lit', [], ['vcard-temp']);
await test_utils.waitUntil(() => _converse.xmppstatus.vcard.get('fullname'), 300);
await u.waitUntil(() => _converse.xmppstatus.vcard.get('fullname'), 300);
/* The process by which a user subscribes to a contact, including
* the interaction between roster items and subscription states.
*/
......@@ -76,7 +76,7 @@
cbview.el.querySelector('.add-contact').click()
const modal = _converse.rosterview.add_contact_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
spyOn(modal, "addContactFromForm").and.callThrough();
modal.delegateEvents();
......@@ -160,7 +160,7 @@
stanza = $iq({'type': 'result', 'id':IQ_id});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.roster.create.calls.count());
await u.waitUntil(() => _converse.roster.create.calls.count());
// A contact should now have been created
expect(_converse.roster.get('contact@example.org') instanceof _converse.RosterContact).toBeTruthy();
......@@ -173,7 +173,7 @@
*
* <presence to='contact@example.org' type='subscribe'/>
*/
const sent_presence = await test_utils.waitUntil(() => sent_stanzas.filter(s => s.match('presence')).pop());
const sent_presence = await u.waitUntil(() => sent_stanzas.filter(s => s.match('presence')).pop());
expect(contact.subscribe).toHaveBeenCalled();
expect(sent_presence).toBe( // Strophe adds the xmlns attr (although not in spec)
`<presence to="contact@example.org" type="subscribe" xmlns="jabber:client">`+
......@@ -211,7 +211,7 @@
expect(_converse.roster.updateContact).toHaveBeenCalled();
// Check that the user is now properly shown as a pending
// contact in the roster.
await test_utils.waitUntil(() => {
await u.waitUntil(() => {
const header = sizzle('a:contains("Pending contacts")', _converse.rosterview.el).pop();
const contacts = _.filter(header.parentElement.querySelectorAll('li'), u.isVisible);
return contacts.length;
......@@ -280,7 +280,7 @@
// The contact should now be visible as an existing
// contact (but still offline).
await test_utils.waitUntil(() => {
await u.waitUntil(() => {
const header = sizzle('a:contains("My contacts")', _converse.rosterview.el);
return sizzle('li', header[0].parentNode).filter(l => u.isVisible(l)).length;
}, 600);
......@@ -471,7 +471,7 @@
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
const header = sizzle('a:contains("My contacts")', _converse.rosterview.el).pop();
await test_utils.waitUntil(() => header.parentElement.querySelectorAll('li').length);
await u.waitUntil(() => header.parentElement.querySelectorAll('li').length);
// remove the first user
header.parentElement.querySelector('li .remove-xmpp-contact').click();
......@@ -508,7 +508,7 @@
const stanza = $iq({'type': 'result', 'id':IQ_id});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
// Our contact has now been removed
await test_utils.waitUntil(() => typeof _converse.roster.get(jid) === "undefined");
await u.waitUntil(() => typeof _converse.roster.get(jid) === "undefined");
done();
}));
......@@ -533,7 +533,7 @@
'xmlns': Strophe.NS.NICK,
}).t('Clint Contact');
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => {
await u.waitUntil(() => {
const header = sizzle('a:contains("Contact requests")', _converse.rosterview.el).pop();
const contacts = _.filter(header.parentElement.querySelectorAll('li'), u.isVisible);
return contacts.length;
......
......@@ -31,7 +31,7 @@
_converse.bare_jid,
[{'category': 'account', 'type':'registered'}],
['urn:xmpp:push:0'], [], 'info');
const stanza = await test_utils.waitUntil(() =>
const stanza = await u.waitUntil(() =>
_.filter(IQ_stanzas, iq => iq.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
);
expect(Strophe.serialize(stanza)).toEqual(
......@@ -44,7 +44,7 @@
'type': 'result',
'id': stanza.getAttribute('id')
})));
await test_utils.waitUntil(() => _converse.session.get('push_enabled'));
await u.waitUntil(() => _converse.session.get('push_enabled'));
done();
}));
......@@ -68,7 +68,7 @@
_converse, _converse.bare_jid, [],
['urn:xmpp:push:0']);
let iq = await test_utils.waitUntil(() => _.filter(
let iq = await u.waitUntil(() => _.filter(
IQ_stanzas,
iq => sizzle(`iq[type="set"] enable[xmlns="${Strophe.NS.PUSH}"]`, iq).length
).pop());
......@@ -81,7 +81,7 @@
const result = u.toStanza(`<iq type="result" id="${iq.getAttribute('id')}" to="romeo@montague.lit" />`);
_converse.connection._dataRecv(test_utils.createRequest(result));
await test_utils.waitUntil(() => _converse.session.get('push_enabled'));
await u.waitUntil(() => _converse.session.get('push_enabled'));
expect(_converse.session.get('push_enabled').length).toBe(1);
expect(_.includes(_converse.session.get('push_enabled'), 'romeo@montague.lit')).toBe(true);
......@@ -90,7 +90,7 @@
_converse, 'chat.shakespeare.lit',
[{'category': 'account', 'type':'registered'}],
['urn:xmpp:push:0'], [], 'info');
iq = await test_utils.waitUntil(() => _.filter(
iq = await u.waitUntil(() => _.filter(
IQ_stanzas,
iq => sizzle(`iq[type="set"][to="chat.shakespeare.lit"] enable[xmlns="${Strophe.NS.PUSH}"]`, iq).length
).pop());
......@@ -105,7 +105,7 @@
'type': 'result',
'id': iq.getAttribute('id')
})));
await test_utils.waitUntil(() => _.includes(_converse.session.get('push_enabled'), 'chat.shakespeare.lit'));
await u.waitUntil(() => _.includes(_converse.session.get('push_enabled'), 'chat.shakespeare.lit'));
done();
}));
......@@ -127,7 +127,7 @@
_converse.bare_jid,
[{'category': 'account', 'type':'registered'}],
['urn:xmpp:push:0'], [], 'info');
const stanza = await test_utils.waitUntil(
const stanza = await u.waitUntil(
() => _.filter(IQ_stanzas, iq => iq.querySelector('iq[type="set"] disable[xmlns="urn:xmpp:push:0"]')).pop()
);
expect(Strophe.serialize(stanza)).toEqual(
......@@ -140,7 +140,7 @@
'type': 'result',
'id': stanza.getAttribute('id')
})));
await test_utils.waitUntil(() => _converse.session.get('push_enabled'))
await u.waitUntil(() => _converse.session.get('push_enabled'))
done();
}));
......@@ -168,7 +168,7 @@
[{'category': 'account', 'type':'registered'}],
['urn:xmpp:push:0'], [], 'info');
const stanza = await test_utils.waitUntil(
const stanza = await u.waitUntil(
() => _.filter(IQ_stanzas, iq => iq.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
);
expect(Strophe.serialize(stanza)).toEqual(
......@@ -186,7 +186,7 @@
'type': 'result',
'id': stanza.getAttribute('id')
})));
await test_utils.waitUntil(() => _converse.session.get('push_enabled'))
await u.waitUntil(() => _converse.session.get('push_enabled'))
done();
}));
});
......
......@@ -15,7 +15,7 @@
allow_registration: false },
async function (done, _converse) {
await test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'));
await u.waitUntil(() => _converse.chatboxviews.get('controlbox'));
test_utils.openControlBox();
const cbview = _converse.chatboxviews.get('controlbox');
expect(cbview.el.querySelectorAll('a.register-account').length).toBe(0);
......@@ -29,7 +29,7 @@
allow_registration: true },
async function (done, _converse) {
await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'), 300);
await u.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'), 300);
const cbview = _converse.chatboxviews.get('controlbox');
test_utils.openControlBox();
const panels = cbview.el.querySelector('.controlbox-panes');
......@@ -38,7 +38,7 @@
const register_link = cbview.el.querySelector('a.register-account');
expect(register_link.textContent).toBe("Create an account");
register_link.click();
await test_utils.waitUntil(() => u.isVisible(registration));
await u.waitUntil(() => u.isVisible(registration));
expect(u.isVisible(login)).toBe(false);
done();
}));
......@@ -50,7 +50,7 @@
allow_registration: true },
async function (done, _converse) {
await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
await u.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
test_utils.openControlBox();
const cbview = _converse.chatboxviews.get('controlbox');
const registerview = cbview.registerpanel;
......@@ -86,7 +86,7 @@
allow_registration: true },
async function (done, _converse) {
await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
await u.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
test_utils.openControlBox();
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.toggle-register-login').click();
......@@ -142,7 +142,7 @@
allow_registration: true },
async function (done, _converse) {
await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
await u.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
test_utils.openControlBox();
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.toggle-register-login').click();
......@@ -199,7 +199,7 @@
allow_registration: true },
async function (done, _converse) {
await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
await u.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
test_utils.openControlBox();
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.toggle-register-login').click();
......@@ -273,7 +273,7 @@
allow_registration: true },
async function (done, _converse) {
await test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
await u.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'));
test_utils.openControlBox();
const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.toggle-register-login').click();
......
......@@ -27,7 +27,7 @@
preventDefault: _.noop,
keyCode: 13
});
let stanza = await test_utils.waitUntil(() => _.filter(
let stanza = await u.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[to="${muc_jid}"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
).pop());
......@@ -48,7 +48,7 @@
'var': 'muc#register_roomnick'
}).c('required');
_converse.connection._dataRecv(test_utils.createRequest(result));
stanza = await test_utils.waitUntil(() => _.filter(
stanza = await u.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[to="${muc_jid}"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
).pop());
......@@ -79,7 +79,7 @@
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
const view = _converse.chatboxviews.get(muc_jid);
let stanza = await test_utils.waitUntil(() => _.filter(
let stanza = await u.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="get"] query[xmlns="jabber:iq:register"]`, iq).length
).pop());
......@@ -101,7 +101,7 @@
'var': 'muc#register_roomnick'
}).c('required');
_converse.connection._dataRecv(test_utils.createRequest(result));
stanza = await test_utils.waitUntil(() => _.filter(
stanza = await u.waitUntil(() => _.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[to="coven@chat.shakespeare.lit"][type="set"] query[xmlns="jabber:iq:register"]`, iq).length
).pop());
......
......@@ -10,7 +10,7 @@
it("is shown in controlbox", mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'],
{ allow_bookmarks: false // Makes testing easier, otherwise we
// have to mock stanza traffic.
// have to mock stanza traffic.
}, async function (done, _converse) {
test_utils.openControlBox();
......@@ -22,13 +22,13 @@
expect(_.isUndefined(_converse.rooms_list_view)).toBeFalsy();
const lview = _converse.rooms_list_view
await test_utils.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
let room_els = lview.el.querySelectorAll(".open-room");
expect(room_els.length).toBe(1);
expect(room_els[0].innerText).toBe('room@conference.shakespeare.lit');
await test_utils.openChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
await test_utils.waitUntil(() => lview.el.querySelectorAll(".open-room").length > 1);
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length > 1);
room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
expect(room_els.length).toBe(2);
......@@ -38,7 +38,7 @@
expect(room_els.length).toBe(1);
expect(room_els[0].innerText).toBe('lounge@montague.lit');
list = controlbox.el.querySelector('div.rooms-list-container');
test_utils.waitUntil(() => _.includes(list.classList, 'hidden'));
u.waitUntil(() => _.includes(list.classList, 'hidden'));
view = _converse.chatboxviews.get('lounge@montague.lit');
view.close();
......@@ -80,7 +80,7 @@
[`${Strophe.NS.PUBSUB}#publish-options`]
);
const call = await test_utils.waitUntil(() =>
const call = await u.waitUntil(() =>
_.filter(
_converse.connection.send.calls.all(),
c => sizzle('items[node="storage:bookmarks"]', c.args[0]).length
......@@ -119,24 +119,22 @@
describe("A groupchat shown in the groupchats list", function () {
it("is highlighted if its currently open", mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'],
null, ['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'],
{ view_mode: 'fullscreen',
allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic.
}, async function (done, _converse) {
let item;
await _converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'});
const lview = _converse.rooms_list_view
await test_utils.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
let room_els = lview.el.querySelectorAll(".available-chatroom");
expect(room_els.length).toBe(1);
item = room_els[0];
let item = room_els[0];
expect(u.hasClass('open', item)).toBe(true);
expect(item.textContent.trim()).toBe('coven@chat.shakespeare.lit');
await _converse.api.rooms.open('balcony@chat.shakespeare.lit', {'nick': 'some1'});
await test_utils.waitUntil(() => lview.el.querySelectorAll(".open-room").length > 1);
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length > 1);
room_els = lview.el.querySelectorAll(".open-room");
expect(room_els.length).toBe(2);
......@@ -160,7 +158,7 @@
const room_jid = 'coven@chat.shakespeare.lit';
test_utils.openControlBox();
await _converse.api.rooms.open(room_jid, {'nick': 'some1'});
const last_stanza = await test_utils.waitUntil(() => _.filter(
const last_stanza = await u.waitUntil(() => _.filter(
IQ_stanzas,
iq => iq.querySelector(
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
......@@ -195,7 +193,7 @@
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
.c('value').t(0);
_converse.connection._dataRecv(test_utils.createRequest(features_stanza));
await test_utils.waitUntil(() => view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)
await u.waitUntil(() => view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING)
let presence = $pres({
to: _converse.connection.jid,
from: 'coven@chat.shakespeare.lit/some1',
......@@ -209,14 +207,14 @@
.c('status').attrs({code:'110'});
_converse.connection._dataRecv(test_utils.createRequest(presence));
await test_utils.waitUntil(() => _converse.rooms_list_view.el.querySelectorAll(".open-room").length, 500);
await u.waitUntil(() => _converse.rooms_list_view.el.querySelectorAll(".open-room").length, 500);
const room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room");
expect(room_els.length).toBe(1);
const info_el = _converse.rooms_list_view.el.querySelector(".room-info");
info_el.click();
const modal = view.model.room_details_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
let els = modal.el.querySelectorAll('p.room-info');
expect(els[0].textContent).toBe("Name: A Dark Cave")
expect(els[1].textContent).toBe("Groupchat address (JID): coven@chat.shakespeare.lit")
......@@ -269,7 +267,7 @@
await test_utils.openChatRoom(_converse, 'lounge', 'conference.shakespeare.lit', 'JC');
expect(_converse.chatboxes.length).toBe(2);
const lview = _converse.rooms_list_view
await test_utils.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
await u.waitUntil(() => lview.el.querySelectorAll(".open-room").length);
let room_els = lview.el.querySelectorAll(".open-room");
expect(room_els.length).toBe(1);
const close_el = _converse.rooms_list_view.el.querySelector(".close-room");
......@@ -290,7 +288,7 @@
test_utils.openControlBox();
const room_jid = 'kitchen@conference.shakespeare.lit';
await test_utils.waitUntil(() => !_.isUndefined(_converse.rooms_list_view), 500);
await u.waitUntil(() => !_.isUndefined(_converse.rooms_list_view), 500);
await test_utils.openAndEnterChatRoom(_converse, 'kitchen@conference.shakespeare.lit', 'romeo');
const view = _converse.chatboxviews.get(room_jid);
view.model.set({'minimized': true});
......@@ -305,7 +303,7 @@
}).c('body').t('foo').tree());
const lview = _converse.rooms_list_view
await test_utils.waitUntil(() => lview.el.querySelectorAll(".available-chatroom").length, 500);
await u.waitUntil(() => lview.el.querySelectorAll(".available-chatroom").length, 500);
// If the user isn't mentioned, the counter doesn't get incremented, but the text of the groupchat is bold
let room_el = lview.el.querySelector(".available-chatroom");
......@@ -320,7 +318,7 @@
type: 'groupchat'
}).c('body').t('romeo: Your attention is required').tree()
);
await test_utils.waitUntil(() => _converse.rooms_list_view.el.querySelectorAll(".msgs-indicator").length);
await u.waitUntil(() => _converse.rooms_list_view.el.querySelectorAll(".msgs-indicator").length);
spyOn(view.model, 'incrementUnreadMsgCounter').and.callThrough();
let indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(indicator_el.textContent).toBe('1');
......@@ -332,7 +330,7 @@
type: 'groupchat'
}).c('body').t('romeo: and another thing...').tree()
);
await test_utils.waitUntil(() => view.model.incrementUnreadMsgCounter.calls.count());
await u.waitUntil(() => view.model.incrementUnreadMsgCounter.calls.count());
indicator_el = _converse.rooms_list_view.el.querySelector(".msgs-indicator");
expect(indicator_el.textContent).toBe('2');
......
This diff is collapsed.
......@@ -24,7 +24,7 @@
_converse.api.user.login('romeo@montague.lit/orchard', 'secret');
const sent_stanzas = _converse.connection.sent_stanzas;
let stanza = await test_utils.waitUntil(() =>
let stanza = await u.waitUntil(() =>
sent_stanzas.filter(s => (s.tagName === 'enable')).pop());
expect(_converse.session.get('smacks_enabled')).toBe(false);
......@@ -34,10 +34,10 @@
_converse.connection._dataRecv(test_utils.createRequest(result));
expect(_converse.session.get('smacks_enabled')).toBe(true);
await test_utils.waitUntil(() => view.renderControlBoxPane.calls.count());
await u.waitUntil(() => view.renderControlBoxPane.calls.count());
let IQ_stanzas = _converse.connection.IQ_stanzas;
await test_utils.waitUntil(() => IQ_stanzas.length === 4);
await u.waitUntil(() => IQ_stanzas.length === 4);
let iq = IQ_stanzas.pop();
expect(Strophe.serialize(iq)).toBe(
......@@ -69,7 +69,7 @@
// test handling of ack requests
let r = u.toStanza(`<r xmlns="urn:xmpp:sm:3"/>`);
_converse.connection._dataRecv(test_utils.createRequest(r));
ack = await test_utils.waitUntil(() => sent_stanzas.filter(s => (s.nodeName === 'a')).pop());
ack = await u.waitUntil(() => sent_stanzas.filter(s => (s.nodeName === 'a')).pop());
expect(Strophe.serialize(ack)).toBe('<a h="0" xmlns="urn:xmpp:sm:3"/>');
const disco_result = $iq({
......@@ -92,14 +92,14 @@
r = u.toStanza(`<r xmlns="urn:xmpp:sm:3"/>`);
_converse.connection._dataRecv(test_utils.createRequest(r));
ack = await test_utils.waitUntil(() => sent_stanzas.filter(s => (s.nodeName === 'a' && s.getAttribute('h') === '1')).pop());
ack = await u.waitUntil(() => sent_stanzas.filter(s => (s.nodeName === 'a' && s.getAttribute('h') === '1')).pop());
expect(Strophe.serialize(ack)).toBe('<a h="1" xmlns="urn:xmpp:sm:3"/>');
// test session resumption
_converse.connection.IQ_stanzas = [];
IQ_stanzas = _converse.connection.IQ_stanzas;
_converse.api.connection.reconnect();
stanza = await test_utils.waitUntil(() =>
stanza = await u.waitUntil(() =>
sent_stanzas.filter(s => (s.tagName === 'resume')).pop());
expect(Strophe.serialize(stanza)).toEqual('<resume h="1" previd="some-long-sm-id" xmlns="urn:xmpp:sm:3"/>');
......@@ -110,7 +110,7 @@
expect(sizzle('enable', sent_stanzas).length).toBe(0);
expect(_converse.session.get('smacks_enabled')).toBe(true);
await test_utils.waitUntil(() => IQ_stanzas.length === 2);
await u.waitUntil(() => IQ_stanzas.length === 2);
// Test that unacked stanzas get resent out
iq = IQ_stanzas.pop();
......
......@@ -11,7 +11,7 @@
it("can be received with a hint",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async (done, _converse) => {
await test_utils.waitForRoster(_converse, 'current');
......@@ -37,7 +37,7 @@
await _converse.chatboxes.onMessage(msg);
const view = _converse.chatboxviews.get(sender_jid);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
await test_utils.waitUntil(() => view.model.vcard.get('fullname') === 'Mercutio')
await u.waitUntil(() => view.model.vcard.get('fullname') === 'Mercutio')
expect(view.el.querySelector('.chat-msg__author').textContent.trim()).toBe('Mercutio');
const message_content = view.el.querySelector('.chat-msg__text');
expect(message_content.textContent).toBe(spoiler);
......@@ -48,7 +48,7 @@
it("can be received without a hint",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async (done, _converse) => {
await test_utils.waitForRoster(_converse, 'current');
......@@ -71,7 +71,7 @@
await _converse.chatboxes.onMessage(msg);
const view = _converse.chatboxviews.get(sender_jid);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
await test_utils.waitUntil(() => view.model.vcard.get('fullname') === 'Mercutio')
await u.waitUntil(() => view.model.vcard.get('fullname') === 'Mercutio')
expect(_.includes(view.el.querySelector('.chat-msg__author').textContent, 'Mercutio')).toBeTruthy();
const message_content = view.el.querySelector('.chat-msg__text');
expect(message_content.textContent).toBe(spoiler);
......@@ -103,7 +103,7 @@
const view = _converse.api.chatviews.get(contact_jid);
spyOn(_converse.connection, 'send');
await test_utils.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
await u.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
spoiler_toggle.click();
......@@ -175,7 +175,7 @@
await test_utils.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]);
const view = _converse.chatboxviews.get(contact_jid);
await test_utils.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
await u.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
spoiler_toggle.click();
......
......@@ -24,13 +24,13 @@
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
test_utils.openChatBoxFor(_converse, contact_jid);
await test_utils.waitUntil(() => _converse.chatboxes.length > 1);
await u.waitUntil(() => _converse.chatboxes.length > 1);
const view = _converse.chatboxviews.get(contact_jid);
let show_modal_button = view.el.querySelector('.show-user-details-modal');
expect(u.isVisible(show_modal_button)).toBeTruthy();
show_modal_button.click();
const modal = view.user_details_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
await u.waitUntil(() => u.isVisible(modal.el), 1000);
spyOn(window, 'confirm').and.returnValue(true);
spyOn(view.model.contact, 'removeFromRoster').and.callFake(function (callback) {
callback();
......@@ -38,7 +38,7 @@
let remove_contact_button = modal.el.querySelector('button.remove-contact');
expect(u.isVisible(remove_contact_button)).toBeTruthy();
remove_contact_button.click();
await test_utils.waitUntil(() => modal.el.getAttribute('aria-hidden'), 1000);
await u.waitUntil(() => modal.el.getAttribute('aria-hidden'), 1000);
show_modal_button = view.el.querySelector('.show-user-details-modal');
show_modal_button.click();
......@@ -62,7 +62,7 @@
expect(u.isVisible(show_modal_button)).toBeTruthy();
show_modal_button.click();
const modal = view.user_details_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 2000);
await u.waitUntil(() => u.isVisible(modal.el), 2000);
spyOn(window, 'confirm').and.returnValue(true);
spyOn(view.model.contact, 'removeFromRoster').and.callFake(function (callback, errback) {
errback();
......@@ -70,7 +70,7 @@
let remove_contact_button = modal.el.querySelector('button.remove-contact');
expect(u.isVisible(remove_contact_button)).toBeTruthy();
remove_contact_button.click();
await test_utils.waitUntil(() => u.isVisible(document.querySelector('.alert-danger')), 2000);
await u.waitUntil(() => u.isVisible(document.querySelector('.alert-danger')), 2000);
const header = document.querySelector('.alert-danger .modal-title');
expect(header.textContent).toBe("Error");
......@@ -79,11 +79,11 @@
document.querySelector('.alert-danger button.close').click();
show_modal_button = view.el.querySelector('.show-user-details-modal');
show_modal_button.click();
await test_utils.waitUntil(() => u.isVisible(modal.el), 2000)
await u.waitUntil(() => u.isVisible(modal.el), 2000)
show_modal_button = view.el.querySelector('.show-user-details-modal');
show_modal_button.click();
await test_utils.waitUntil(() => u.isVisible(modal.el), 2000)
await u.waitUntil(() => u.isVisible(modal.el), 2000)
remove_contact_button = modal.el.querySelector('button.remove-contact');
expect(u.isVisible(remove_contact_button)).toBeTruthy();
......
......@@ -1769,17 +1769,23 @@ _converse.api = {
},
/**
* Wait until a promise is resolved
* Wait until a promise is resolved or until the passed in function returns
* a truthy value.
* @method _converse.api.waitUntil
* @param {string} name The name of the promise
* @param {string|function} condition - The name of the promise to wait for,
* or a function which should eventually return a truthy value.
* @returns {Promise}
*/
waitUntil (name) {
const promise = _converse.promises[name];
if (_.isUndefined(promise)) {
return null;
waitUntil (condition) {
if (_.isFunction(condition)) {
return u.waitUntil(condition);
} else {
const promise = _converse.promises[condition];
if (_.isUndefined(promise)) {
return null;
}
return promise;
}
return promise;
},
/**
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment