Commit 79b6a557 authored by JC Brand's avatar JC Brand

Use async/await and hopefully fix some failing Travis tests

parent 7ab59ad6
...@@ -297,64 +297,57 @@ ...@@ -297,64 +297,57 @@
it("has a button with which its contents can be cleared", it("has a button with which its contents can be cleared",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_converse.roster_groups = true; _converse.roster_groups = true;
test_utils.openControlBox(); test_utils.openControlBox();
test_utils.createGroupedContacts(_converse); test_utils.createGroupedContacts(_converse);
var filter = _converse.rosterview.el.querySelector('.roster-filter'); const filter = _converse.rosterview.el.querySelector('.roster-filter');
filter.value = "xxx"; filter.value = "xxx";
u.triggerEvent(filter, "keydown", "KeyboardEvent"); u.triggerEvent(filter, "keydown", "KeyboardEvent");
expect(_.includes(filter.classList, "x")).toBeFalsy(); expect(_.includes(filter.classList, "x")).toBeFalsy();
expect(u.hasClass('hidden', _converse.rosterview.el.querySelector('.roster-filter-form .clear-input'))).toBeTruthy(); expect(u.hasClass('hidden', _converse.rosterview.el.querySelector('.roster-filter-form .clear-input'))).toBeTruthy();
test_utils.waitUntil(function () { const isHidden = _.partial(u.hasClass, 'hidden');
return !u.hasClass('hidden', _converse.rosterview.el.querySelector('.roster-filter-form .clear-input')); await test_utils.waitUntil(() => !isHidden(_converse.rosterview.el.querySelector('.roster-filter-form .clear-input')), 900);
}, 900).then(function () {
var filter = _converse.rosterview.el.querySelector('.roster-filter');
_converse.rosterview.el.querySelector('.clear-input').click(); _converse.rosterview.el.querySelector('.clear-input').click();
expect(document.querySelector('.roster-filter').value).toBe(""); expect(document.querySelector('.roster-filter').value).toBe("");
done(); done();
});
})); }));
it("can be used to filter contacts by their chat state", it("can be used to filter contacts by their chat state",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createGroupedContacts(_converse); test_utils.createGroupedContacts(_converse);
var jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost'; let jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.get(jid).presence.set('show', 'online'); _converse.roster.get(jid).presence.set('show', 'online');
jid = mock.cur_names[4].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[4].replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.get(jid).presence.set('show', 'dnd'); _converse.roster.get(jid).presence.set('show', 'dnd');
test_utils.openControlBox(); test_utils.openControlBox();
var button = _converse.rosterview.el.querySelector('span[data-type="state"]'); const button = _converse.rosterview.el.querySelector('span[data-type="state"]');
button.click(); button.click();
var roster = _converse.rosterview.roster_el; const roster = _converse.rosterview.roster_el;
test_utils.waitUntil(() => sizzle('li', roster).filter(u.isVisible).length === 15, 500).then(function () { await test_utils.waitUntil(() => sizzle('li', roster).filter(u.isVisible).length === 15, 500);
var filter = _converse.rosterview.el.querySelector('.state-type'); const filter = _converse.rosterview.el.querySelector('.state-type');
expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(5); 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');
return test_utils.waitUntil(() => sizzle('li', roster).filter(u.isVisible).length === 1, 500); await test_utils.waitUntil(() => sizzle('li', roster).filter(u.isVisible).length === 1, 500);
}).then(function () {
expect(sizzle('li', roster).filter(u.isVisible).pop().textContent.trim()).toBe('Rinse Sommer'); expect(sizzle('li', roster).filter(u.isVisible).pop().textContent.trim()).toBe('Rinse Sommer');
expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(1); await test_utils.waitUntil(() => sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length === 1, 500);
const ul = sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).pop();
expect(ul.parentElement.firstElementChild.textContent.trim()).toBe('friends & acquaintences');
var filter = _converse.rosterview.el.querySelector('.state-type');
filter.value = "dnd"; filter.value = "dnd";
u.triggerEvent(filter, 'change'); u.triggerEvent(filter, 'change');
return test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('li', roster).filter(u.isVisible).pop().textContent.trim() === 'Annegreet Gomez', 900);
return sizzle('li', roster).filter(u.isVisible).pop().textContent.trim() === 'Annegreet Gomez';
}, 900)
}).then(function () {
expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(1); expect(sizzle('ul.roster-group-contacts', roster).filter(u.isVisible).length).toBe(1);
done(); done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
}); });
...@@ -661,9 +654,9 @@ ...@@ -661,9 +654,9 @@
it("can be added to the roster and they will be sorted alphabetically", it("can be added to the roster and they will be sorted alphabetically",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
var i, t; let i;
test_utils.openControlBox(); test_utils.openControlBox();
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
for (i=0; i<mock.pend_names.length; i++) { for (i=0; i<mock.pend_names.length; i++) {
...@@ -675,17 +668,13 @@ ...@@ -675,17 +668,13 @@
}); });
expect(_converse.rosterview.update).toHaveBeenCalled(); expect(_converse.rosterview.update).toHaveBeenCalled();
} }
return test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('li', _converse.rosterview.get('Pending contacts').el).filter(u.isVisible).length, 700);
return sizzle('li', _converse.rosterview.get('Pending contacts').el).filter(u.isVisible).length;
}, 700).then(function () {
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = _.reduce(_converse.rosterview.get('Pending contacts').el.querySelectorAll('.pending-xmpp-contact span'), const view = _converse.rosterview.get('Pending contacts');
function (result, value) { const spans = view.el.querySelectorAll('.pending-xmpp-contact span');
return result + _.trim(value.textContent); const t = _.reduce(spans, (result, value) => result + _.trim(value.textContent), '');
}, '');
expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join(''));
done(); done();
});
})); }));
}); });
...@@ -697,33 +686,25 @@ ...@@ -697,33 +686,25 @@
it("can be collapsed under their own header", it("can be collapsed under their own header",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_addContacts(_converse); _addContacts(_converse);
test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('li', _converse.rosterview.el).filter(u.isVisible).length, 500);
return sizzle('li', _converse.rosterview.el).filter(u.isVisible).length; await checkHeaderToggling.apply(_converse, [_converse.rosterview.el.querySelector('.roster-group')]);
}, 500).then(function () { done();
checkHeaderToggling.apply(
_converse,
[_converse.rosterview.el.querySelector('.roster-group')]
).then(done);
});
})); }));
it("will be hidden when appearing under a collapsed group", it("will be hidden when appearing under a collapsed group",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_converse.roster_groups = false; _converse.roster_groups = false;
_addContacts(_converse); _addContacts(_converse);
test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('li', _converse.rosterview.el).filter(u.isVisible).length, 500);
return sizzle('li', _converse.rosterview.el).filter(u.isVisible).length;
}, 500)
.then(function () {
_converse.rosterview.el.querySelector('.roster-group a.group-toggle').click(); _converse.rosterview.el.querySelector('.roster-group a.group-toggle').click();
var name = "Max Mustermann"; const name = "Max Mustermann";
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost'; const jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.create({ _converse.roster.create({
ask: null, ask: null,
fullname: name, fullname: name,
...@@ -731,20 +712,20 @@ ...@@ -731,20 +712,20 @@
requesting: false, requesting: false,
subscription: 'both' subscription: 'both'
}); });
var view = _converse.rosterview.get('My contacts').get(jid); const view = _converse.rosterview.get('My contacts').get(jid);
expect(u.isVisible(view.el)).toBe(false); expect(u.isVisible(view.el)).toBe(false);
done(); done();
});
})); }));
it("can be added to the roster and they will be sorted alphabetically", it("can be added to the roster and they will be sorted alphabetically",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
let i;
test_utils.openControlBox(); test_utils.openControlBox();
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
for (var i=0; i<mock.cur_names.length; i++) { for (i=0; i<mock.cur_names.length; i++) {
_converse.roster.create({ _converse.roster.create({
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost', jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
subscription: 'both', subscription: 'both',
...@@ -753,9 +734,7 @@ ...@@ -753,9 +734,7 @@
}); });
expect(_converse.rosterview.update).toHaveBeenCalled(); expect(_converse.rosterview.update).toHaveBeenCalled();
} }
test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('li', _converse.rosterview.el).length, 600);
return sizzle('li', _converse.rosterview.el).length;
}, 600).then(function () {
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
const t = _.reduce( const t = _.reduce(
_converse.rosterview.el.querySelectorAll('.roster-group .current-xmpp-contact.offline a.open-chat'), _converse.rosterview.el.querySelectorAll('.roster-group .current-xmpp-contact.offline a.open-chat'),
...@@ -763,7 +742,6 @@ ...@@ -763,7 +742,6 @@
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
done(); done();
});
})); }));
it("can be removed by the user", it("can be removed by the user",
...@@ -828,80 +806,67 @@ ...@@ -828,80 +806,67 @@
it("can change their status to online and be sorted alphabetically", it("can change their status to online and be sorted alphabetically",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_addContacts(_converse); _addContacts(_converse);
test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length, 700) await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length, 700);
.then(function () { let jid, t;
var jid, t;
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
const roster = _converse.rosterview.el; const roster = _converse.rosterview.el;
for (var i=0; i<mock.cur_names.length; i++) { for (let i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.get(jid).presence.set('show', 'online'); _converse.roster.get(jid).presence.set('show', 'online');
expect(_converse.rosterview.update).toHaveBeenCalled(); expect(_converse.rosterview.update).toHaveBeenCalled();
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = _.reduce(roster.querySelectorAll('.roster-group .current-xmpp-contact.online a.open-chat'), function (result, value) { const chat_els = roster.querySelectorAll('.roster-group .current-xmpp-contact.online a.open-chat');
return result + _.trim(value.textContent); t = _.reduce(chat_els, (result, value) => result + _.trim(value.textContent), '');
}, '');
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
} }
done(); done();
});
})); }));
it("can change their status to busy and be sorted alphabetically", it("can change their status to busy and be sorted alphabetically",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_addContacts(_converse); _addContacts(_converse);
test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
return sizzle('.roster-group li', _converse.rosterview.el).length; let jid, t;
}, 700).then(function () {
var jid, t;
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
const roster = _converse.rosterview.el; const roster = _converse.rosterview.el;
for (var i=0; i<mock.cur_names.length; i++) { for (let i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.get(jid).presence.set('show', 'dnd'); _converse.roster.get(jid).presence.set('show', 'dnd');
expect(_converse.rosterview.update).toHaveBeenCalled(); expect(_converse.rosterview.update).toHaveBeenCalled();
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = _.reduce(roster.querySelectorAll('.roster-group .current-xmpp-contact.dnd a.open-chat'), const chat_els = roster.querySelectorAll('.roster-group .current-xmpp-contact.dnd a.open-chat');
function (result, value) { t = _.reduce(chat_els, (result, value) => result + _.trim(value.textContent), '');
return result + _.trim(value.textContent);
}, '');
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
} }
done(); done();
});
})); }));
it("can change their status to away and be sorted alphabetically", it("can change their status to away and be sorted alphabetically",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_addContacts(_converse); _addContacts(_converse);
test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
return sizzle('.roster-group li', _converse.rosterview.el).length; let jid, t;
}, 700).then(function () {
var jid, t;
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
const roster = _converse.rosterview.el; const roster = _converse.rosterview.el;
for (var i=0; i<mock.cur_names.length; i++) { for (let i=0; i<mock.cur_names.length; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.get(jid).presence.set('show', 'away'); _converse.roster.get(jid).presence.set('show', 'away');
expect(_converse.rosterview.update).toHaveBeenCalled(); expect(_converse.rosterview.update).toHaveBeenCalled();
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
t = _.reduce(roster.querySelectorAll('.roster-group .current-xmpp-contact.away a.open-chat'), const chat_els = roster.querySelectorAll('.roster-group .current-xmpp-contact.away a.open-chat');
function (result, value) { t = _.reduce(chat_els, (result, value) => result + _.trim(value.textContent), '');
return result + _.trim(value.textContent);
}, '');
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
} }
done(); done();
});
})); }));
it("can change their status to xa and be sorted alphabetically", it("can change their status to xa and be sorted alphabetically",
...@@ -955,13 +920,11 @@ ...@@ -955,13 +920,11 @@
it("are ordered according to status: online, busy, away, xa, unavailable, offline", it("are ordered according to status: online, busy, away, xa, unavailable, offline",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_addContacts(_converse); _addContacts(_converse);
test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('.roster-group li', _converse.rosterview.el).length, 700);
return sizzle('.roster-group li', _converse.rosterview.el).length; let i, jid;
}, 700).then(function () {
var i, jid;
for (i=0; i<3; i++) { for (i=0; i<3; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.get(jid).presence.set('show', 'online'); _converse.roster.get(jid).presence.set('show', 'online');
...@@ -982,15 +945,8 @@ ...@@ -982,15 +945,8 @@
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.get(jid).presence.set('show', 'unavailable'); _converse.roster.get(jid).presence.set('show', 'unavailable');
} }
return test_utils.waitUntil(function () { await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('li.online').length)
return _converse.rosterview.el.querySelectorAll('li.online').length await test_utils.waitUntil(() => _converse.rosterview.el.querySelector('li:first-child').textContent.trim() === 'Candice van der Knijff', 900);
})
}).then(function () {
return test_utils.waitUntil(function () {
return _converse.rosterview.el.querySelector('li:first-child').textContent.trim() === 'Candice van der Knijff'
}, 900);
}).then(function () {
var i;
const contacts = _converse.rosterview.el.querySelectorAll('.current-xmpp-contact'); const contacts = _converse.rosterview.el.querySelectorAll('.current-xmpp-contact');
for (i=0; i<3; i++) { for (i=0; i<3; i++) {
expect(u.hasClass('online', contacts[i])).toBe(true); expect(u.hasClass('online', contacts[i])).toBe(true);
...@@ -1047,7 +1003,6 @@ ...@@ -1047,7 +1003,6 @@
expect(u.hasClass('unavailable', contacts[i])).toBe(false); expect(u.hasClass('unavailable', contacts[i])).toBe(false);
} }
done(); done();
});
})); }));
}); });
...@@ -1056,18 +1011,17 @@ ...@@ -1056,18 +1011,17 @@
it("can be added to the roster and they will be sorted alphabetically", it("can be added to the roster and they will be sorted alphabetically",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
var i, children; let names = [];
var names = []; const addName = function (item) {
var addName = function (item) {
if (!u.hasClass('request-actions', item)) { if (!u.hasClass('request-actions', item)) {
names.push(item.textContent.replace(/^\s+|\s+$/g, '')); names.push(item.textContent.replace(/^\s+|\s+$/g, ''));
} }
}; };
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
spyOn(_converse.controlboxtoggle, 'showControlBox').and.callThrough(); spyOn(_converse.controlboxtoggle, 'showControlBox').and.callThrough();
for (i=0; i<mock.req_names.length; i++) { for (let i=0; i<mock.req_names.length; i++) {
_converse.roster.create({ _converse.roster.create({
jid: mock.req_names[i].replace(/ /g,'.').toLowerCase() + '@localhost', jid: mock.req_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
subscription: 'none', subscription: 'none',
...@@ -1076,17 +1030,14 @@ ...@@ -1076,17 +1030,14 @@
fullname: mock.req_names[i] fullname: mock.req_names[i]
}); });
} }
test_utils.waitUntil(function () { await test_utils.waitUntil(() => _converse.rosterview.get('Contact requests').el.querySelectorAll('li').length, 700);
return _converse.rosterview.get('Contact requests').el.querySelectorAll('li').length;
}, 700).then(function () {
expect(_converse.rosterview.update).toHaveBeenCalled(); expect(_converse.rosterview.update).toHaveBeenCalled();
// Check that they are sorted alphabetically // Check that they are sorted alphabetically
children = _converse.rosterview.get('Contact requests').el.querySelectorAll('.requesting-xmpp-contact span'); const children = _converse.rosterview.get('Contact requests').el.querySelectorAll('.requesting-xmpp-contact span');
names = []; names = [];
_.each(children, addName); Array.from(children).forEach(addName);
expect(names.join('')).toEqual(mock.req_names.slice(0,mock.req_names.length+1).sort().join('')); expect(names.join('')).toEqual(mock.req_names.slice(0,mock.req_names.length+1).sort().join(''));
done(); done();
});
})); }));
it("do not have a header if there aren't any", it("do not have a header if there aren't any",
......
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