فهرست منبع

Fix failing tests

Handle missing message model (happens during tests)
JC Brand 4 سال پیش
والد
کامیت
6665bef76c

+ 0 - 1
package-lock.json

@@ -27451,7 +27451,6 @@
 		},
 		"@converse/skeletor": {
 			"version": "git+ssh://git@github.com/conversejs/skeletor.git#f354bc530493a17d031f6f9c524cc34e073908e3",
-			"integrity": "sha512-BqifISxYDtkQeJxSkxOgUl/Z0vFT9+ePYKFVzwXQLjxjBQp05xdw1+WkE+t8BnEiAXkoGKAEOv04Ezg3D3jgIw==",
 			"from": "@converse/skeletor@conversejs/skeletor#f354bc530493a17d031f6f9c524cc34e073908e3",
 			"requires": {
 				"lit-html": "^2.0.0-rc.2",

+ 1 - 1
src/headless/plugins/chat/tests/api.js

@@ -28,7 +28,7 @@ describe("The \"chats\" API", function() {
         expect(chat.get('box_id')).toBe(`box-${jid}`);
 
         // Test for multiple JIDs
-        mock.openChatBoxFor(_converse, jid2);
+        await mock.openChatBoxFor(_converse, jid2);
         await u.waitUntil(() => _converse.chatboxes.length == 3);
         const list = await _converse.api.chats.get([jid, jid2]);
         expect(Array.isArray(list)).toBeTruthy();

+ 6 - 1
src/headless/plugins/muc/muc.js

@@ -438,10 +438,14 @@ const ChatRoomMixin = {
             };
             if (attrs.msgid === message.get('retraction_id')) {
                 // The error message refers to a retraction
+                new_attrs.retracted = undefined;
                 new_attrs.retraction_id = undefined;
+                new_attrs.retracted_id = undefined;
+
                 if (!attrs.error) {
                     if (attrs.error_condition === 'forbidden') {
                         new_attrs.error = __("You're not allowed to retract your message.");
+
                     } else if (attrs.error_condition === 'not-acceptable') {
                         new_attrs.error = __(
                             "Your retraction was not delivered because you're not present in the groupchat."
@@ -737,7 +741,8 @@ const ChatRoomMixin = {
                 'error_type': 'timeout',
                 'error': __('A timeout happened while while trying to retract your message.'),
                 'retracted': undefined,
-                'retracted_id': undefined
+                'retracted_id': undefined,
+                'retraction_id': undefined
             });
         }
     },

+ 3 - 0
src/plugins/chatview/tests/http-file-upload.js

@@ -452,6 +452,7 @@ describe("XEP-0363: HTTP File Upload", function () {
                     </slot>
                     </iq>`);
 
+                const promise = u.getOpenPromise();
                 spyOn(XMLHttpRequest.prototype, 'send').and.callFake(async () => {
                     const message = view.model.messages.at(0);
                     const el = await u.waitUntil(() => view.querySelector('.chat-content progress'));
@@ -461,8 +462,10 @@ describe("XEP-0363: HTTP File Upload", function () {
                     message.set('progress', 1);
                     await u.waitUntil(() => view.querySelector('.chat-content progress').getAttribute('value') === '1');
                     expect(view.querySelector('.chat-content .chat-msg__text').textContent).toBe('Uploading file: my-juliet.jpg, 22.91 KB');
+                    promise.resolve();
                 });
                 _converse.connection._dataRecv(mock.createRequest(stanza));
+                return promise;
             }));
         });
     });

+ 3 - 1
src/plugins/minimize/tests/minchats.js

@@ -299,11 +299,13 @@ describe("The Minimized Chats Widget", function () {
         const unread_el = minimized_chats.querySelector('.unread-message-count');
         expect(u.isVisible(unread_el)).toBe(false);
 
+        const promises = [];
         let i, contact_jid;
         for (i=0; i<3; i++) {
             contact_jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
-            mock.openChatBoxFor(_converse, contact_jid);
+            promises.push(mock.openChatBoxFor(_converse, contact_jid));
         }
+        await Promise.all(promises);
         await u.waitUntil(() => _converse.chatboxes.length == 4);
 
         const chatview = _converse.chatboxviews.get(contact_jid);

+ 5 - 0
src/plugins/muc-views/tests/muc.js

@@ -1922,6 +1922,8 @@ describe("Groupchats", function () {
                 );
             }
             await Promise.all(promises);
+            const promise = u.getOpenPromise();
+
             // Give enough time for `markScrolled` to have been called
             setTimeout(async () => {
                 const content = view.querySelector('.chat-content');
@@ -1938,7 +1940,10 @@ describe("Groupchats", function () {
                 const msg_txt = sizzle('.chat-msg:last .chat-msg__text', content).pop().textContent;
                 expect(msg_txt).toEqual(message);
                 expect(content.scrollTop).toBe(0);
+                promise.resolve();
             }, 500);
+
+            return promise;
         }));
 
         it("reconnects when no-acceptable error is returned when sending a message",

+ 3 - 0
src/plugins/notifications/tests/notification.js

@@ -273,11 +273,14 @@ describe("Notifications", function () {
                   .c('active', {'xmlns': Strophe.NS.CHATSTATES}).tree();
             await _converse.handleMessageStanza(msg);
 
+            const promise = u.getOpenPromise();
             setTimeout(() => {
                 const view = _converse.chatboxviews.get(sender_jid);
                 expect(view.model.get('num_unread')).toBe(0);
                 expect(favico.badge.calls.count()).toBe(0);
+                promise.resolve();
             }, 500);
+            return promise;
         }));
 
         it("is incremented from zero when chatbox was closed after viewing previously received messages and the window is not focused now",

+ 5 - 0
src/shared/chat/message-actions.js

@@ -194,6 +194,11 @@ class MessageActions extends CustomElement {
             });
         }
 
+        if (!this.model.collection) {
+            // While we were awaiting, this model got removed from the
+            // collection (happens during tests)
+            return [];
+        }
         const ogp_metadata = this.model.get('ogp_metadata') || [];
         const chatbox = this.model.collection.chatbox;
         if (chatbox.get('type') === _converse.CHATROOMS_TYPE &&

+ 9 - 1
src/shared/chat/message.js

@@ -6,6 +6,7 @@ import MessageVersionsModal from 'modals/message-versions.js';
 import OccupantModal from 'modals/occupant.js';
 import UserDetailsModal from 'modals/user-details.js';
 import filesize from 'filesize';
+import log from '@converse/headless/log';
 import tpl_message from './templates/message.js';
 import tpl_spinner from 'templates/spinner.js';
 import { CustomElement } from 'shared/components/element.js';
@@ -35,6 +36,12 @@ export default class Message extends CustomElement {
 
     async initialize () {
         await this.setModels();
+        if (!this.model) {
+            // Happen during tests due to a race condition
+            log.error('Could not find module for converse-chat-message');
+            return;
+        }
+
         this.listenTo(this.chatbox, 'change:first_unread_id', this.requestUpdate);
         this.listenTo(this.model, 'change', this.requestUpdate);
         this.model.vcard && this.listenTo(this.model.vcard, 'change', this.requestUpdate);
@@ -53,8 +60,9 @@ export default class Message extends CustomElement {
     async setModels () {
         this.chatbox = await api.chatboxes.get(this.jid);
         await this.chatbox.initialized;
+        await this.chatbox.messages.fetched;
         this.model = this.chatbox.messages.get(this.mid);
-        this.requestUpdate();
+        this.model && this.requestUpdate();
     }
 
     render () {