Commit 4e6ac905 authored by JC Brand's avatar JC Brand

Async/await in controlbox tests

parent c22fe41a
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
it("can be used to add contact and it checks for case-sensivity", it("can be used to add contact and it checks for case-sensivity",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
spyOn(_converse, 'emit'); spyOn(_converse, 'emit');
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
...@@ -55,14 +55,11 @@ ...@@ -55,14 +55,11 @@
ask: 'subscribe', ask: 'subscribe',
fullname: mock.pend_names[0] fullname: mock.pend_names[0]
}); });
test_utils.waitUntil(function () { await test_utils.waitUntil(() => $(_converse.rosterview.el).find('.roster-group li:visible').length, 700);
return $(_converse.rosterview.el).find('.roster-group li:visible').length;
}, 700).then(function () {
// Checking that only one entry is created because both JID is same (Case sensitive check) // Checking that only one entry is created because both JID is same (Case sensitive check)
expect($(_converse.rosterview.el).find('li:visible').length).toBe(1); expect($(_converse.rosterview.el).find('li:visible').length).toBe(1);
expect(_converse.rosterview.update).toHaveBeenCalled(); expect(_converse.rosterview.update).toHaveBeenCalled();
done(); done();
});
})); }));
it("shows the number of unread mentions received", it("shows the number of unread mentions received",
...@@ -130,7 +127,7 @@ ...@@ -130,7 +127,7 @@
it("can be used to set the current user's chat status", it("can be used to set the current user's chat status",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openControlBox(); test_utils.openControlBox();
...@@ -138,10 +135,8 @@ ...@@ -138,10 +135,8 @@
cbview.el.querySelector('.change-status').click() cbview.el.querySelector('.change-status').click()
var modal = _converse.xmppstatusview.status_modal; var modal = _converse.xmppstatusview.status_modal;
test_utils.waitUntil(function () { await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
return u.isVisible(modal.el); const view = _converse.xmppstatusview;
}, 1000).then(function () {
var view = _converse.xmppstatusview;
spyOn(_converse, 'emit'); spyOn(_converse, 'emit');
modal.el.querySelector('label[for="radio-busy"]').click(); // Change status to "dnd" modal.el.querySelector('label[for="radio-busy"]').click(); // Change status to "dnd"
modal.el.querySelector('[type="submit"]').click(); modal.el.querySelector('[type="submit"]').click();
...@@ -151,27 +146,24 @@ ...@@ -151,27 +146,24 @@
expect($(view.el).find('.xmpp-status span:first-child').hasClass('dnd')).toBe(true); expect($(view.el).find('.xmpp-status span:first-child').hasClass('dnd')).toBe(true);
expect(view.el.querySelector('.xmpp-status span:first-child').textContent.trim()).toBe('I am busy'); expect(view.el.querySelector('.xmpp-status span:first-child').textContent.trim()).toBe('I am busy');
done(); done();
});
})); }));
it("can be used to set a custom status message", it("can be used to set a custom status message",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.openControlBox(); test_utils.openControlBox();
var cbview = _converse.chatboxviews.get('controlbox'); const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.change-status').click() cbview.el.querySelector('.change-status').click()
var modal = _converse.xmppstatusview.status_modal; const modal = _converse.xmppstatusview.status_modal;
test_utils.waitUntil(function () { await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
return u.isVisible(modal.el); const view = _converse.xmppstatusview;
}, 1000).then(function () {
var view = _converse.xmppstatusview;
spyOn(_converse, 'emit'); spyOn(_converse, 'emit');
var msg = 'I am happy'; const msg = 'I am happy';
modal.el.querySelector('input[name="status_message"]').value = msg; modal.el.querySelector('input[name="status_message"]').value = msg;
modal.el.querySelector('[type="submit"]').click(); modal.el.querySelector('[type="submit"]').click();
...@@ -179,7 +171,6 @@ ...@@ -179,7 +171,6 @@
expect($(view.el).find('.xmpp-status span:first-child').hasClass('online')).toBe(true); expect($(view.el).find('.xmpp-status span:first-child').hasClass('online')).toBe(true);
expect(view.el.querySelector('.xmpp-status span:first-child').textContent.trim()).toBe(msg); expect(view.el.querySelector('.xmpp-status span:first-child').textContent.trim()).toBe(msg);
done(); done();
});
})); }));
}); });
}); });
...@@ -189,29 +180,27 @@ ...@@ -189,29 +180,27 @@
it("opens up an add modal when you click on it", it("opens up an add modal when you click on it",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'all').openControlBox(); test_utils.createContacts(_converse, 'all').openControlBox();
var panel = _converse.chatboxviews.get('controlbox').contactspanel; const panel = _converse.chatboxviews.get('controlbox').contactspanel;
var cbview = _converse.chatboxviews.get('controlbox'); const cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.add-contact').click() cbview.el.querySelector('.add-contact').click()
var modal = _converse.rosterview.add_contact_modal; const modal = _converse.rosterview.add_contact_modal;
return test_utils.waitUntil(function () { await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
return u.isVisible(modal.el); const sendIQ = _converse.connection.sendIQ;
}, 1000).then(function () { let sent_stanza, IQ_id;
var sendIQ = _converse.connection.sendIQ;
var sent_stanza, IQ_id;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
sent_stanza = iq; sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback); IQ_id = sendIQ.bind(this)(iq, callback, errback);
}); });
expect(!_.isNull(modal.el.querySelector('form.add-xmpp-contact'))).toBeTruthy(); expect(!_.isNull(modal.el.querySelector('form.add-xmpp-contact'))).toBeTruthy();
var input_jid = modal.el.querySelector('input[name="jid"]'); const input_jid = modal.el.querySelector('input[name="jid"]');
var input_name = modal.el.querySelector('input[name="name"]'); const input_name = modal.el.querySelector('input[name="name"]');
input_jid.value = 'someone@'; input_jid.value = 'someone@';
var evt = new Event('input'); const evt = new Event('input');
input_jid.dispatchEvent(evt); input_jid.dispatchEvent(evt);
expect(modal.el.querySelector('.awesomplete li').textContent).toBe('someone@localhost'); expect(modal.el.querySelector('.awesomplete li').textContent).toBe('someone@localhost');
input_jid.value = 'someone@localhost'; input_jid.value = 'someone@localhost';
...@@ -222,7 +211,6 @@ ...@@ -222,7 +211,6 @@
`<query xmlns="jabber:iq:roster"><item jid="someone@localhost" name="Someone"/></query>`+ `<query xmlns="jabber:iq:roster"><item jid="someone@localhost" name="Someone"/></query>`+
`</iq>`); `</iq>`);
done(); done();
});
})); }));
...@@ -232,7 +220,7 @@ ...@@ -232,7 +220,7 @@
{ 'xhr_user_search': true, { 'xhr_user_search': true,
'xhr_user_search_url': 'http://example.org/' 'xhr_user_search_url': 'http://example.org/'
}, },
function (done, _converse) { async function (done, _converse) {
var xhr = { var xhr = {
'open': _.noop, 'open': _.noop,
...@@ -255,17 +243,12 @@ ...@@ -255,17 +243,12 @@
var cbview = _converse.chatboxviews.get('controlbox'); var cbview = _converse.chatboxviews.get('controlbox');
cbview.el.querySelector('.add-contact').click() cbview.el.querySelector('.add-contact').click()
var modal = _converse.rosterview.add_contact_modal; var modal = _converse.rosterview.add_contact_modal;
return test_utils.waitUntil(function () { await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
return u.isVisible(modal.el);
}, 1000).then(function () {
input_el = modal.el.querySelector('input[name="name"]'); input_el = modal.el.querySelector('input[name="name"]');
input_el.value = 'marty'; input_el.value = 'marty';
var evt = new Event('input'); var evt = new Event('input');
input_el.dispatchEvent(evt); input_el.dispatchEvent(evt);
return test_utils.waitUntil(function () { await test_utils.waitUntil(() => modal.el.querySelector('.awesomplete li'), 1000);
return modal.el.querySelector('.awesomplete li');
}, 1000);
}).then(function () {
var sendIQ = _converse.connection.sendIQ; var sendIQ = _converse.connection.sendIQ;
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
...@@ -278,7 +261,7 @@ ...@@ -278,7 +261,7 @@
// Can't trigger "mousedown" event so trigger the Awesomplete // Can't trigger "mousedown" event so trigger the Awesomplete
// custom event which would have been triggered upon mousedown. // custom event which would have been triggered upon mousedown.
var evt = document.createEvent("HTMLEvents"); evt = document.createEvent("HTMLEvents");
evt.initEvent('awesomplete-selectcomplete', true, true ); evt.initEvent('awesomplete-selectcomplete', true, true );
evt.text = { evt.text = {
'label': 'Marty McFly', 'label': 'Marty McFly',
...@@ -294,7 +277,6 @@ ...@@ -294,7 +277,6 @@
`</iq>`); `</iq>`);
window.XMLHttpRequest = XMLHttpRequestBackup; window.XMLHttpRequest = XMLHttpRequestBackup;
done(); done();
});
})); }));
}); });
})); }));
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