Просмотр исходного кода

Update jquery and sizzle and fix/improve some tests

Fixes #825
JC Brand 7 лет назад
Родитель
Сommit
ee751ec58e
5 измененных файлов с 41 добавлено и 30 удалено
  1. 1 0
      CHANGES.md
  2. 9 9
      package-lock.json
  3. 2 1
      package.json
  4. 28 19
      spec/chatroom.js
  5. 1 1
      src/config.js

+ 1 - 0
CHANGES.md

@@ -63,6 +63,7 @@
   be available. See the [locales_url](https://conversejs.org/docs/html/configurations.html#locales-url)
   configuration setting for more info.
 - The translation machinery has now been moved to a separate module in `src/i18n.js`.
+- jQuery has been completely removed as a dependency (still used in tests though).
 
 ## 3.2.1 (2017-08-29)
 

+ 9 - 9
package-lock.json

@@ -4142,15 +4142,9 @@
       "dev": true
     },
     "jquery": {
-      "version": "2.2.3",
-      "resolved": "https://registry.npmjs.org/jquery/-/jquery-2.2.3.tgz",
-      "integrity": "sha1-ReB+QZAzTeNsnhpktDsfE3PZF1g=",
-      "dev": true
-    },
-    "jquery.browser": {
-      "version": "0.1.0",
-      "resolved": "https://registry.npmjs.org/jquery.browser/-/jquery.browser-0.1.0.tgz",
-      "integrity": "sha1-nHKmCV/SgUtER26o9xZne3Kmors=",
+      "version": "3.2.1",
+      "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.2.1.tgz",
+      "integrity": "sha1-XE2d5lKvbNCncBVKYxu6ErAVx4c=",
       "dev": true
     },
     "js-tokens": {
@@ -8137,6 +8131,12 @@
         "type-detect": "4.0.3"
       }
     },
+    "sizzle": {
+      "version": "2.3.3",
+      "resolved": "https://registry.npmjs.org/sizzle/-/sizzle-2.3.3.tgz",
+      "integrity": "sha1-TrB4w3IxpWtS5Bk/cB5++JN+YGs=",
+      "dev": true
+    },
     "slash": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz",

+ 2 - 1
package.json

@@ -52,7 +52,7 @@
     "install": "^0.8.5",
     "jasmine-core": "2.6.4",
     "jed": "0.5.4",
-    "jquery": "2.2.3",
+    "jquery": "3.2.1",
     "jshint": "^2.9.4",
     "lodash": "4.17.4",
     "lodash-template-loader": "^2.0.0",
@@ -64,6 +64,7 @@
     "requirejs": "2.3.3",
     "run-headless-chromium": "^0.1.1",
     "sinon": "^2.1.0",
+    "sizzle": "^2.3.3",
     "snabbdom": "jcbrand/snabbdom",
     "snyk": "^1.21.2",
     "strophe.js": "1.2.14",

+ 28 - 19
spec/chatroom.js

@@ -8,6 +8,7 @@
     var Strophe = converse.env.Strophe;
     var Promise = converse.env.Promise;
     var moment = converse.env.moment;
+    var sizzle = converse.env.sizzle;
     var u = converse.env.utils;
 
     return describe("ChatRooms", function () {
@@ -150,6 +151,7 @@
                     expect(room.is_chatroom).toBeTruthy();
                     chatroomview = _converse.chatboxviews.get(jid);
                     expect(u.isVisible(chatroomview.el)).toBeTruthy();
+                    chatroomview.close();
 
                     // Test with mixed case in JID
                     jid = 'Leisure@localhost';
@@ -172,10 +174,11 @@
                     chatroomview.close();
 
                     _converse.muc_instant_rooms = false;
-                    var sent_IQ, IQ_id;
+                    var sent_IQ, IQ_id, sent_IQ_els = [];
                     var sendIQ = _converse.connection.sendIQ;
                     spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
                         sent_IQ = iq;
+                        sent_IQ_els.push(iq.nodeTree);
                         IQ_id = sendIQ.bind(this)(iq, callback, errback);
                     });
                     // Test with configuration
@@ -191,6 +194,7 @@
                             'whois': 'anyone'
                         }
                     });
+                    chatroomview = _converse.chatboxviews.get('room@conference.example.org');
 
                     // We pretend this is a new room, so no disco info is returned.
                     var features_stanza = $iq({
@@ -228,7 +232,7 @@
                         "<iq to='room@conference.example.org' type='get' xmlns='jabber:client' id='"+IQ_id+
                         "'><query xmlns='http://jabber.org/protocol/muc#owner'/></iq>"
                     );
-                    _converse.connection._dataRecv(test_utils.createRequest($(
+                    var node = Strophe.xmlHtmlNode(
                        '<iq xmlns="jabber:client"'+
                        '     type="result"'+
                        '     to="dummy@localhost/pda"'+
@@ -257,22 +261,27 @@
                        '        <value>20</value></field>'+
                        '     </x>'+
                        ' </query>'+
-                       ' </iq>')[0]));
+                       ' </iq>');
+
+                    spyOn(chatroomview, 'sendConfiguration').and.callThrough();
+                    _converse.connection._dataRecv(test_utils.createRequest(node.firstElementChild));
+
 
                     return test_utils.waitUntil(function () {
-                        return sent_IQ.toLocaleString() !==
-                            "<iq to='room@conference.example.org' type='get' xmlns='jabber:client' id='"+IQ_id+
-                            "'><query xmlns='http://jabber.org/protocol/muc#owner'/></iq>";
+                        return chatroomview.sendConfiguration.calls.count() === 1;
                     }, 300).then(function () {
-                        var $sent_stanza = $(sent_IQ.toLocaleString());
-                        expect($sent_stanza.find('field[var="muc#roomconfig_roomname"] value').text()).toBe('Room');
-                        expect($sent_stanza.find('field[var="muc#roomconfig_roomdesc"] value').text()).toBe('Welcome to this room');
-                        expect($sent_stanza.find('field[var="muc#roomconfig_persistentroom"] value').text()).toBe('1');
-                        expect($sent_stanza.find('field[var="muc#roomconfig_publicroom"] value ').text()).toBe('1');
-                        expect($sent_stanza.find('field[var="muc#roomconfig_changesubject"] value').text()).toBe('0');
-                        expect($sent_stanza.find('field[var="muc#roomconfig_whois"] value ').text()).toBe('anyone');
-                        expect($sent_stanza.find('field[var="muc#roomconfig_membersonly"] value').text()).toBe('1');
-                        expect($sent_stanza.find('field[var="muc#roomconfig_historylength"] value').text()).toBe('20');
+                        var sent_stanza = sent_IQ_els.pop();
+                        while (sent_stanza.getAttribute('type') !== 'set') {
+                            sent_stanza = sent_IQ_els.pop();
+                        }
+                        expect(sizzle('field[var="muc#roomconfig_roomname"] value', sent_stanza).pop().textContent).toBe('Room');
+                        expect(sizzle('field[var="muc#roomconfig_roomdesc"] value', sent_stanza).pop().textContent).toBe('Welcome to this room');
+                        expect(sizzle('field[var="muc#roomconfig_persistentroom"] value', sent_stanza).pop().textContent).toBe('1');
+                        expect(sizzle('field[var="muc#roomconfig_publicroom"] value ', sent_stanza).pop().textContent).toBe('1');
+                        expect(sizzle('field[var="muc#roomconfig_changesubject"] value', sent_stanza).pop().textContent).toBe('0');
+                        expect(sizzle('field[var="muc#roomconfig_whois"] value ', sent_stanza).pop().textContent).toBe('anyone');
+                        expect(sizzle('field[var="muc#roomconfig_membersonly"] value', sent_stanza).pop().textContent).toBe('1');
+                        expect(sizzle('field[var="muc#roomconfig_historylength"] value', sent_stanza).pop().textContent).toBe('20');
                         done();
                     });
                 });
@@ -376,15 +385,15 @@
                     .c('status').attrs({code:'201'}).nodeTree;
 
                     _converse.connection._dataRecv(test_utils.createRequest(presence));
-                    var info_text = $(view.el).find('.chat-content .chat-info').text();
+                    var info_text = view.el.querySelector('.chat-content .chat-info').textContent;
                     expect(info_text).toBe('A new room has been created');
 
                     // An instant room is created by saving the default configuratoin.
                     //
                     /* <iq to="myroom@conference.chat.example.org" type="set" xmlns="jabber:client" id="5025e055-036c-4bc5-a227-706e7e352053:sendIQ">
-                    *   <query xmlns="http://jabber.org/protocol/muc#owner"><x xmlns="jabber:x:data" type="submit"/></query>
-                    * </iq>
-                    */
+                     *   <query xmlns="http://jabber.org/protocol/muc#owner"><x xmlns="jabber:x:data" type="submit"/></query>
+                     * </iq>
+                     */
                     expect(sent_IQ.toLocaleString()).toBe(
                         "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
                             "<query xmlns='http://jabber.org/protocol/muc#owner'><x xmlns='jabber:x:data' type='submit'/>"+

+ 1 - 1
src/config.js

@@ -38,7 +38,7 @@ require.config({
         "lodash.noconflict":        "src/lodash.noconflict",
         "pluggable":                "node_modules/pluggable.js/dist/pluggable",
         "polyfill":                 "src/polyfill",
-        "sizzle":                   "node_modules/jquery/sizzle/dist/sizzle",
+        "sizzle":                   "node_modules/sizzle/dist/sizzle",
         "strophe":                  "node_modules/strophe.js/strophe",
         "strophe.disco":            "node_modules/strophejs-plugin-disco/strophe.disco",
         "strophe.ping":             "node_modules/strophejs-plugin-ping/strophe.ping",