瀏覽代碼

Remove lodash dependency in tests

JC Brand 4 年之前
父節點
當前提交
4047d619a1
共有 2 個文件被更改,包括 12 次插入16 次删除
  1. 5 7
      spec/push.js
  2. 7 9
      src/plugins/omemo/tests/omemo.js

+ 5 - 7
spec/push.js

@@ -1,4 +1,4 @@
-/*global mock, converse, _ */
+/*global mock, converse */
 
 
 const $iq = converse.env.$iq;
 const $iq = converse.env.$iq;
 const Strophe = converse.env.Strophe;
 const Strophe = converse.env.Strophe;
@@ -33,7 +33,7 @@ describe("XEP-0357 Push Notifications", function () {
                 [{'category': 'account', 'type':'registered'}],
                 [{'category': 'account', 'type':'registered'}],
                 ['urn:xmpp:push:0'], [], 'info');
                 ['urn:xmpp:push:0'], [], 'info');
         const stanza = await u.waitUntil(() =>
         const stanza = await u.waitUntil(() =>
-            _.filter(IQ_stanzas, iq => iq.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
+            IQ_stanzas.filter(iq => iq.querySelector('iq[type="set"] enable[xmlns="urn:xmpp:push:0"]')).pop()
         );
         );
         expect(Strophe.serialize(stanza)).toEqual(
         expect(Strophe.serialize(stanza)).toEqual(
             `<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
             `<iq id="${stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
@@ -79,16 +79,14 @@ describe("XEP-0357 Push Notifications", function () {
 
 
         await u.waitUntil(() => _converse.session.get('push_enabled'));
         await u.waitUntil(() => _converse.session.get('push_enabled'));
         expect(_converse.session.get('push_enabled').length).toBe(1);
         expect(_converse.session.get('push_enabled').length).toBe(1);
-        expect(_.includes(_converse.session.get('push_enabled'), 'romeo@montague.lit')).toBe(true);
+        expect(_converse.session.get('push_enabled').includes('romeo@montague.lit')).toBe(true);
 
 
         mock.openAndEnterChatRoom(_converse, 'coven@chat.shakespeare.lit', 'oldhag');
         mock.openAndEnterChatRoom(_converse, 'coven@chat.shakespeare.lit', 'oldhag');
         await mock.waitUntilDiscoConfirmed(
         await mock.waitUntilDiscoConfirmed(
             _converse, 'chat.shakespeare.lit',
             _converse, 'chat.shakespeare.lit',
             [{'category': 'account', 'type':'registered'}],
             [{'category': 'account', 'type':'registered'}],
             ['urn:xmpp:push:0'], [], 'info');
             ['urn:xmpp:push:0'], [], 'info');
-        iq = await u.waitUntil(() => _.filter(
-            IQ_stanzas,
-            iq => sizzle(`iq[type="set"][to="chat.shakespeare.lit"] enable[xmlns="${Strophe.NS.PUSH}"]`, iq).length
+        iq = await u.waitUntil(() => IQ_stanzas.filter(iq => sizzle(`iq[type="set"][to="chat.shakespeare.lit"] enable[xmlns="${Strophe.NS.PUSH}"]`, iq).length
         ).pop());
         ).pop());
 
 
         expect(Strophe.serialize(iq)).toEqual(
         expect(Strophe.serialize(iq)).toEqual(
@@ -101,7 +99,7 @@ describe("XEP-0357 Push Notifications", function () {
             'type': 'result',
             'type': 'result',
             'id': iq.getAttribute('id')
             'id': iq.getAttribute('id')
         })));
         })));
-        await u.waitUntil(() => _.includes(_converse.session.get('push_enabled'), 'chat.shakespeare.lit'));
+        await u.waitUntil(() => _converse.session.get('push_enabled').includes('chat.shakespeare.lit'));
     }));
     }));
 
 
     it("can be disabled",
     it("can be disabled",

+ 7 - 9
src/plugins/omemo/tests/omemo.js

@@ -1,4 +1,4 @@
-/*global mock, converse, _ */
+/*global mock, converse */
 
 
 const { $iq, $pres, $msg, omemo, Strophe } = converse.env;
 const { $iq, $pres, $msg, omemo, Strophe } = converse.env;
 const u = converse.env.utils;
 const u = converse.env.utils;
@@ -13,8 +13,7 @@ async function deviceListFetched (_converse, jid) {
 }
 }
 
 
 function ownDeviceHasBeenPublished (_converse) {
 function ownDeviceHasBeenPublished (_converse) {
-    return _.filter(
-        Array.from(_converse.connection.IQ_stanzas),
+    return Array.from(_converse.connection.IQ_stanzas).filter(
         iq => iq.querySelector('iq[from="'+_converse.bare_jid+'"] publish[node="eu.siacs.conversations.axolotl.devicelist"]')
         iq => iq.querySelector('iq[from="'+_converse.bare_jid+'"] publish[node="eu.siacs.conversations.axolotl.devicelist"]')
     ).pop();
     ).pop();
 }
 }
@@ -25,8 +24,7 @@ function bundleHasBeenPublished (_converse) {
 }
 }
 
 
 function bundleFetched (_converse, jid, device_id) {
 function bundleFetched (_converse, jid, device_id) {
-    return _.filter(
-        Array.from(_converse.connection.IQ_stanzas),
+    return Array.from(_converse.connection.IQ_stanzas).filter(
         iq => iq.querySelector(`iq[to="${jid}"] items[node="eu.siacs.conversations.axolotl.bundles:${device_id}"]`)
         iq => iq.querySelector(`iq[to="${jid}"] items[node="eu.siacs.conversations.axolotl.bundles:${device_id}"]`)
     ).pop();
     ).pop();
 }
 }
@@ -764,7 +762,7 @@ describe("The OMEMO module", function() {
         expect(_converse.devicelists.length).toBe(2);
         expect(_converse.devicelists.length).toBe(2);
         let devices = _converse.devicelists.get(contact_jid).devices;
         let devices = _converse.devicelists.get(contact_jid).devices;
         expect(devices.length).toBe(2);
         expect(devices.length).toBe(2);
-        expect(_.map(devices.models, 'attributes.id').sort().join()).toBe('1234,4223');
+        expect(devices.models.map(d => d.attributes.id).sort().join()).toBe('1234,4223');
 
 
         stanza = $msg({
         stanza = $msg({
             'from': contact_jid,
             'from': contact_jid,
@@ -781,7 +779,7 @@ describe("The OMEMO module", function() {
 
 
         expect(_converse.devicelists.length).toBe(2);
         expect(_converse.devicelists.length).toBe(2);
         expect(devices.length).toBe(3);
         expect(devices.length).toBe(3);
-        expect(_.map(devices.models, 'attributes.id').sort().join()).toBe('1234,4223,4224');
+        expect(devices.models.map(d => d.attributes.id).sort().join()).toBe('1234,4223,4224');
         expect(devices.get('1234').get('active')).toBe(false);
         expect(devices.get('1234').get('active')).toBe(false);
         expect(devices.get('4223').get('active')).toBe(true);
         expect(devices.get('4223').get('active')).toBe(true);
         expect(devices.get('4224').get('active')).toBe(true);
         expect(devices.get('4224').get('active')).toBe(true);
@@ -804,7 +802,7 @@ describe("The OMEMO module", function() {
         expect(_converse.devicelists.length).toBe(2);
         expect(_converse.devicelists.length).toBe(2);
         devices = _converse.devicelists.get(_converse.bare_jid).devices;
         devices = _converse.devicelists.get(_converse.bare_jid).devices;
         expect(devices.length).toBe(3);
         expect(devices.length).toBe(3);
-        expect(_.map(devices.models, 'attributes.id').sort().join()).toBe('123456789,555,777');
+        expect(devices.models.map(d => d.attributes.id).sort().join()).toBe('123456789,555,777');
         expect(devices.get('123456789').get('active')).toBe(true);
         expect(devices.get('123456789').get('active')).toBe(true);
         expect(devices.get('555').get('active')).toBe(true);
         expect(devices.get('555').get('active')).toBe(true);
         expect(devices.get('777').get('active')).toBe(true);
         expect(devices.get('777').get('active')).toBe(true);
@@ -855,7 +853,7 @@ describe("The OMEMO module", function() {
         // The device id for this device (123456789) was also generated and added to the list,
         // The device id for this device (123456789) was also generated and added to the list,
         // which is why we have 2 devices now.
         // which is why we have 2 devices now.
         expect(devices.length).toBe(4);
         expect(devices.length).toBe(4);
-        expect(_.map(devices.models, 'attributes.id').sort().join()).toBe('123456789,444,555,777');
+        expect(devices.models.map(d => d.attributes.id).sort().join()).toBe('123456789,444,555,777');
         expect(devices.get('123456789').get('active')).toBe(true);
         expect(devices.get('123456789').get('active')).toBe(true);
         expect(devices.get('444').get('active')).toBe(true);
         expect(devices.get('444').get('active')).toBe(true);
         expect(devices.get('555').get('active')).toBe(false);
         expect(devices.get('555').get('active')).toBe(false);