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

Modernize some roster tests

By ditching jquery and using async/await
parent df7d663b
...@@ -376,7 +376,7 @@ ...@@ -376,7 +376,7 @@
it("can be used to organize existing contacts", it("can be used to organize existing contacts",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_converse.roster_groups = true; _converse.roster_groups = true;
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
...@@ -387,36 +387,34 @@ ...@@ -387,36 +387,34 @@
test_utils.createGroupedContacts(_converse); test_utils.createGroupedContacts(_converse);
// Check that the groups appear alphabetically and that // Check that the groups appear alphabetically and that
// requesting and pending contacts are last. // requesting and pending contacts are last.
test_utils.waitUntil(function () { await test_utils.waitUntil(() => sizzle('.roster-group a.group-toggle', _converse.rosterview.el).length);
return $(_converse.rosterview.el).find('.roster-group:visible a.group-toggle').length; const group_titles = _.map(
}, 500).then(function () { sizzle('.roster-group a.group-toggle', _converse.rosterview.el),
var group_titles = $.map( o => o.textContent.trim()
$(_converse.rosterview.el).find('.roster-group:visible a.group-toggle'), );
function (o) { return $(o).text().trim(); } expect(group_titles).toEqual([
); "Contact requests",
expect(group_titles).toEqual([ "colleagues",
"Contact requests", "Family",
"colleagues", "friends & acquaintences",
"Family", "ænemies",
"friends & acquaintences", "Ungrouped",
"ænemies", "Pending contacts"
"Ungrouped", ]);
"Pending contacts" // Check that usernames appear alphabetically per group
]); let names;
// Check that usernames appear alphabetically per group _.each(_.keys(mock.groups), function (name) {
_.each(_.keys(mock.groups), function (name) { const contacts = sizzle('.roster-group[data-group="'+name+'"] ul', _converse.rosterview.el);
var $contacts = $(_converse.rosterview.el).find('.roster-group[data-group="'+name+'"] ul'); const names = _.map(contacts, o => o.textContent.trim());
var names = $.map($contacts, function (o) { return $(o).text().trim(); }); expect(names).toEqual(_.clone(names).sort());
expect(names).toEqual(_.clone(names).sort());
});
done();
}); });
done();
})); }));
it("gets created when a contact's \"groups\" attribute changes", it("gets created when a contact's \"groups\" attribute changes",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_converse.roster_groups = true; _converse.roster_groups = true;
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
...@@ -434,28 +432,28 @@ ...@@ -434,28 +432,28 @@
// Check that the groups appear alphabetically and that // Check that the groups appear alphabetically and that
// requesting and pending contacts are last. // requesting and pending contacts are last.
test_utils.waitUntil(function () { let group_titles = await test_utils.waitUntil(() => {
return $(_converse.rosterview.el).find('.roster-group:visible a.group-toggle').length; const toggles = sizzle('.roster-group a.group-toggle', _converse.rosterview.el);
}, 500).then(function () { if (_.reduce(toggles, (result, t) => result && u.isVisible(t), true)) {
var group_titles = $.map( return _.map(toggles, o => o.textContent.trim());
$(_converse.rosterview.el).find('.roster-group:visible a.group-toggle'), } else {
function (o) { return $(o).text().trim(); } return false;
); }
expect(group_titles).toEqual(['firstgroup']); }, 1000);
expect(group_titles).toEqual(['firstgroup']);
var contact = _converse.roster.get('groupchanger@localhost');
contact.set({'groups': ['secondgroup']}); const contact = _converse.roster.get('groupchanger@localhost');
return test_utils.waitUntil(function () { contact.set({'groups': ['secondgroup']});
return $(_converse.rosterview.el).find('.roster-group[data-group="secondgroup"]:visible a.group-toggle').length; group_titles = await test_utils.waitUntil(() => {
}, 500); const toggles = sizzle('.roster-group[data-group="secondgroup"] a.group-toggle', _converse.rosterview.el);
}).then(function () { if (_.reduce(toggles, (result, t) => result && u.isVisible(t), true)) {
var group_titles = $.map( return _.map(toggles, o => o.textContent.trim());
$(_converse.rosterview.el).find('.roster-group:visible a.group-toggle'), } else {
function (o) { return $(o).text().trim(); } return false;
); }
expect(group_titles).toEqual(['secondgroup']); }, 1000);
done(); expect(group_titles).toEqual(['secondgroup']);
}); done();
})); }));
it("can share contacts with other roster groups", it("can share contacts with other roster groups",
...@@ -570,21 +568,18 @@ ...@@ -570,21 +568,18 @@
it("are shown in the roster when show_only_online_users", it("are shown in the roster when show_only_online_users",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
_converse.show_only_online_users = true; _converse.show_only_online_users = true;
test_utils.openControlBox(); test_utils.openControlBox();
spyOn(_converse.rosterview, 'update').and.callThrough(); spyOn(_converse.rosterview, 'update').and.callThrough();
_addContacts(_converse); _addContacts(_converse);
test_utils.waitUntil(function () { await test_utils.waitUntil(() => _.reduce(_converse.rosterview.el.querySelectorAll('li'), (result, el) => result && u.isVisible(el), true), 500);
return $(_converse.rosterview.el).find('li:visible').length; expect(u.isVisible(_converse.rosterview.el)).toEqual(true);
}, 700).then(function () { expect(_converse.rosterview.update).toHaveBeenCalled();
expect($(_converse.rosterview.el).is(':visible')).toEqual(true); expect(_converse.rosterview.el.querySelectorAll('li').length).toBe(3);
expect(_converse.rosterview.update).toHaveBeenCalled(); expect(_.filter(_converse.rosterview.el.querySelectorAll('ul.roster-group-contacts'), u.isVisible).length).toBe(1);
expect($(_converse.rosterview.el).find('li:visible').length).toBe(3); done();
expect($(_converse.rosterview.el).find('ul.roster-group-contacts:visible').length).toBe(1);
done();
});
})); }));
it("are shown in the roster when hide_offline_users", it("are shown in the roster when hide_offline_users",
......
...@@ -247,8 +247,7 @@ converse.plugins.add('converse-notification', { ...@@ -247,8 +247,7 @@ converse.plugins.add('converse-notification', {
* Will show an HTML5 notification to indicate that the chat * Will show an HTML5 notification to indicate that the chat
* status has changed. * status has changed.
*/ */
if (_converse.areDesktopNotificationsEnabled() && if (_converse.areDesktopNotificationsEnabled() && _converse.show_chatstate_notifications) {
_converse.show_chatstate_notifications) {
_converse.showChatStateNotification(contact); _converse.showChatStateNotification(contact);
} }
}; };
......
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