소스 검색

Fix failing test by making sure notifications are cleared

JC Brand 6 년 전
부모
커밋
6ebf6f6ecc
3개의 변경된 파일39개의 추가작업 그리고 39개의 파일을 삭제
  1. 4 2
      dist/converse.js
  2. 28 34
      spec/chatbox.js
  3. 7 3
      src/converse-chatview.js

+ 4 - 2
dist/converse.js

@@ -59465,12 +59465,14 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
           'model': message
         });
         await view.render();
+        this.clearChatStateNotification(message);
 
         if (!view.el.innerHTML) {
-          return _converse.log("showMessage: message's view element is empty", Strophe.LogLevel.ERROR);
+          // An "inactive" CSN message (for example) will have an
+          // empty body. No need to then continue.
+          return _converse.log("Not inserting a message with empty element", Strophe.LogLevel.INFO);
         }
 
-        this.clearChatStateNotification(message);
         this.insertMessage(view);
         this.insertDayIndicator(view.el);
         this.setScrollPosition(view.el);

+ 28 - 34
spec/chatbox.js

@@ -1020,47 +1020,41 @@
                     it("will clear any other chat status notifications",
                         mock.initConverseWithPromises(
                             null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
-                            function (done, _converse) {
+                            async function (done, _converse) {
 
                         test_utils.createContacts(_converse, 'current');
                         _converse.emit('rosterContactsFetched');
                         test_utils.openControlBox();
                         const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
-                        let view;
-
                         // See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
                         spyOn(_converse, 'emit');
-                        test_utils.openChatBoxFor(_converse, sender_jid)
-                        .then(() => {
-                            view = _converse.chatboxviews.get(sender_jid);
-                            expect(view.el.querySelectorAll('.chat-event').length).toBe(0);
-                            // Insert <composing> message, to also check that
-                            // text messages are inserted correctly with
-                            // temporary chat events in the chat contents.
-                            const msg = $msg({
-                                    'to': _converse.bare_jid,
-                                    'xmlns': 'jabber:client',
-                                    'from': sender_jid,
-                                    'type': 'chat'})
-                                .c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
-                                .tree();
-                            _converse.chatboxes.onMessage(msg);
-                            return test_utils.waitUntil(() => view.model.messages.length);
-                        }).then(() => {
-                            expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(1);
-                            const msg = $msg({
-                                    from: sender_jid,
-                                    to: _converse.connection.jid,
-                                    type: 'chat',
-                                    id: (new Date()).getTime()
-                                }).c('body').c('inactive', {'xmlns': Strophe.NS.CHATSTATES}).tree();
-                            _converse.chatboxes.onMessage(msg);
-                            return test_utils.waitUntil(() => (view.model.messages.length > 1));
-                        }).then(() => {
-                            expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
-                            expect($(view.el).find('.chat-state-notification').length).toBe(0);
-                            done();
-                        });
+                        await test_utils.openChatBoxFor(_converse, sender_jid);
+                        const view = _converse.chatboxviews.get(sender_jid);
+                        expect(view.el.querySelectorAll('.chat-event').length).toBe(0);
+                        // Insert <composing> message, to also check that
+                        // text messages are inserted correctly with
+                        // temporary chat events in the chat contents.
+                        let msg = $msg({
+                                'to': _converse.bare_jid,
+                                'xmlns': 'jabber:client',
+                                'from': sender_jid,
+                                'type': 'chat'})
+                            .c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
+                            .tree();
+                        _converse.chatboxes.onMessage(msg);
+                        await test_utils.waitUntil(() => view.model.messages.length);
+                        expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(1);
+                        msg = $msg({
+                                from: sender_jid,
+                                to: _converse.connection.jid,
+                                type: 'chat',
+                                id: (new Date()).getTime()
+                            }).c('body').c('inactive', {'xmlns': Strophe.NS.CHATSTATES}).tree();
+                        _converse.chatboxes.onMessage(msg);
+                        await test_utils.waitUntil(() => (view.model.messages.length > 1));
+                        expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
+                        expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(0);
+                        done();
                     }));
                 });
 

+ 7 - 3
src/converse-chatview.js

@@ -728,11 +728,15 @@ converse.plugins.add('converse-chatview', {
                  */
                 const view = new _converse.MessageView({'model': message});
                 await view.render();
-
+                this.clearChatStateNotification(message);
                 if (!view.el.innerHTML) {
-                    return _converse.log("showMessage: message's view element is empty", Strophe.LogLevel.ERROR);
+                    // An "inactive" CSN message (for example) will have an
+                    // empty body. No need to then continue.
+                    return _converse.log(
+                        "Not inserting a message with empty element",
+                        Strophe.LogLevel.INFO
+                    );
                 }
-                this.clearChatStateNotification(message);
                 this.insertMessage(view);
                 this.insertDayIndicator(view.el);
                 this.setScrollPosition(view.el);