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