Skip to content

Commit

Permalink
Remove lodash from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Mar 23, 2024
1 parent b5868a9 commit 07b4e4a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
1 change: 0 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = function(config) {
{ pattern: 'dist/*.css.map', included: false },
{ pattern: "dist/emojis.js", served: true },
"src/shared/tests/tests.css",
"node_modules/lodash/lodash.min.js",
"dist/converse.js",
"dist/converse.css",
{ pattern: "dist/images/**/*.*", included: false },
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/chatview/tests/receipts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ describe("A delivery receipt", function () {
}).c('body').t('Message!').up()
.c('request', {'xmlns': Strophe.NS.RECEIPTS}).tree();
await _converse.handleMessageStanza(msg);
const sent_messages = sent_stanzas.map(s => _.isElement(s) ? s : s.nodeTree).filter(s => s.nodeName === 'message');
const sent_messages = sent_stanzas
.map(s => u.isElement(s) ? s : s.nodeTree)
.filter(s => s.nodeName === 'message');

// A chat state message is also included
expect(sent_messages.length).toBe(2);
const receipt = sizzle(`received[xmlns="${Strophe.NS.RECEIPTS}"]`, sent_messages[1]).pop();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/headlines-view/tests/headline.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ describe("A headlines box", function () {
.c('nick').t('gpocy').up()
.c('body').t('Здравствуйте друзья');
_converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
expect(_.without('controlbox', _converse.chatboxviews.keys()).length).toBe(0);
expect(_converse.chatboxviews.keys().filter(k => k !== 'controlbox').length).toBe(0);
}));
});
9 changes: 6 additions & 3 deletions src/plugins/muc-views/tests/modtools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*global mock, converse, _ */


const $iq = converse.env.$iq;
const $pres = converse.env.$pres;
const sizzle = converse.env.sizzle;
Expand Down Expand Up @@ -322,9 +323,11 @@ describe("The groupchat moderator tool", function () {
const button = modal.querySelector('.btn-primary[name="users_with_affiliation"]');
button.click();

const iq_query = await u.waitUntil(() => _.filter(
IQ_stanzas,
s => sizzle(`iq[to="${muc_jid}"] query[xmlns="${Strophe.NS.MUC_ADMIN}"] item[affiliation="outcast"]`, s).length
const iq_query = await u.waitUntil(() => IQ_stanzas.filter(
s => sizzle(
`iq[to="${muc_jid}"] query[xmlns="${Strophe.NS.MUC_ADMIN}"] item[affiliation="outcast"]`,
s
).length
).pop());

const error = u.toStanza(
Expand Down
18 changes: 12 additions & 6 deletions src/plugins/rosterview/tests/roster.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const checkHeaderToggling = async function (group) {
expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeTruthy();
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeFalsy();
toggle.click();
await u.waitUntil(() => group.querySelectorAll('li').length === _.filter(group.querySelectorAll('li'), u.isVisible).length);
await u.waitUntil(() => group.querySelectorAll('li').length ===
Array.from(group.querySelectorAll('li')).filter(u.isVisible).length);

expect(u.hasClass('fa-caret-right', toggle.firstElementChild)).toBeFalsy();
expect(u.hasClass('fa-caret-down', toggle.firstElementChild)).toBeTruthy();
};
Expand Down Expand Up @@ -63,7 +65,7 @@ describe("The Contacts Roster", function () {
it("is populated once we have registered a presence handler", mock.initConverse([], {}, async function (_converse) {
const IQs = _converse.api.connection.get().IQ_stanzas;
const stanza = await u.waitUntil(
() => _.filter(IQs, iq => iq.querySelector('iq query[xmlns="jabber:iq:roster"]')).pop());
() => IQs.filter(iq => iq.querySelector('iq query[xmlns="jabber:iq:roster"]')).pop());

expect(Strophe.serialize(stanza)).toBe(
`<iq id="${stanza.getAttribute('id')}" type="get" xmlns="jabber:client">`+
Expand All @@ -84,7 +86,7 @@ describe("The Contacts Roster", function () {
it("supports roster versioning", mock.initConverse([], {}, async function (_converse) {
const IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
let stanza = await u.waitUntil(
() => _.filter(IQ_stanzas, iq => iq.querySelector('iq query[xmlns="jabber:iq:roster"]')).pop()
() => IQ_stanzas.filter(iq => iq.querySelector('iq query[xmlns="jabber:iq:roster"]')).pop()
);
expect(_converse.roster.data.get('version')).toBeUndefined();
expect(Strophe.serialize(stanza)).toBe(
Expand Down Expand Up @@ -404,7 +406,7 @@ describe("The Contacts Roster", function () {
const filter = await u.waitUntil(() => rosterview.querySelector('.items-filter'));
filter.value = "xxx";
u.triggerEvent(filter, "keydown", "KeyboardEvent");
expect(_.includes(filter.classList, "x")).toBeFalsy();
expect(filter.classList.contains("x")).toBeFalsy();
expect(u.hasClass('hidden', rosterview.querySelector('.items-filter-form .clear-input'))).toBeTruthy();

const isHidden = (el) => u.hasClass('hidden', el);
Expand Down Expand Up @@ -544,7 +546,9 @@ describe("The Contacts Roster", function () {
Object.keys(mock.groups).forEach(name => {
const contacts = sizzle('.roster-group[data-group="'+name+'"] ul', rosterview);
const names = contacts.map(o => o.textContent.trim());
expect(names).toEqual(_.clone(names).sort());
const sorted_names = [...names];
sorted_names.sort();
expect(names).toEqual(sorted_names);
});
}));

Expand Down Expand Up @@ -609,7 +613,9 @@ describe("The Contacts Roster", function () {
groups.forEach(name => {
const contacts = sizzle('.roster-group[data-group="'+name+'"] ul li', rosterview);
const names = contacts.map(o => o.textContent.trim());
expect(names).toEqual(_.clone(names).sort());
const sorted_names = [...names];
sorted_names.sort();
expect(names).toEqual(sorted_names);
expect(names.length).toEqual(mock.cur_names.length);
});
}));
Expand Down

0 comments on commit 07b4e4a

Please sign in to comment.