Fix failing tests

Handle missing message model (happens during tests)
This commit is contained in:
JC Brand 2021-06-28 13:53:33 +02:00
parent dff5f485c9
commit 6665bef76c
9 changed files with 35 additions and 5 deletions

1
package-lock.json generated
View File

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

View File

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

View File

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

View File

@ -452,6 +452,7 @@ describe("XEP-0363: HTTP File Upload", function () {
</slot> </slot>
</iq>`); </iq>`);
const promise = u.getOpenPromise();
spyOn(XMLHttpRequest.prototype, 'send').and.callFake(async () => { spyOn(XMLHttpRequest.prototype, 'send').and.callFake(async () => {
const message = view.model.messages.at(0); const message = view.model.messages.at(0);
const el = await u.waitUntil(() => view.querySelector('.chat-content progress')); 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); message.set('progress', 1);
await u.waitUntil(() => view.querySelector('.chat-content progress').getAttribute('value') === '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'); 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)); _converse.connection._dataRecv(mock.createRequest(stanza));
return promise;
})); }));
}); });
}); });

View File

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

View File

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

View File

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

View File

@ -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 ogp_metadata = this.model.get('ogp_metadata') || [];
const chatbox = this.model.collection.chatbox; const chatbox = this.model.collection.chatbox;
if (chatbox.get('type') === _converse.CHATROOMS_TYPE && if (chatbox.get('type') === _converse.CHATROOMS_TYPE &&

View File

@ -6,6 +6,7 @@ import MessageVersionsModal from 'modals/message-versions.js';
import OccupantModal from 'modals/occupant.js'; import OccupantModal from 'modals/occupant.js';
import UserDetailsModal from 'modals/user-details.js'; import UserDetailsModal from 'modals/user-details.js';
import filesize from 'filesize'; import filesize from 'filesize';
import log from '@converse/headless/log';
import tpl_message from './templates/message.js'; import tpl_message from './templates/message.js';
import tpl_spinner from 'templates/spinner.js'; import tpl_spinner from 'templates/spinner.js';
import { CustomElement } from 'shared/components/element.js'; import { CustomElement } from 'shared/components/element.js';
@ -35,6 +36,12 @@ export default class Message extends CustomElement {
async initialize () { async initialize () {
await this.setModels(); 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.chatbox, 'change:first_unread_id', this.requestUpdate);
this.listenTo(this.model, 'change', this.requestUpdate); this.listenTo(this.model, 'change', this.requestUpdate);
this.model.vcard && this.listenTo(this.model.vcard, '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 () { async setModels () {
this.chatbox = await api.chatboxes.get(this.jid); this.chatbox = await api.chatboxes.get(this.jid);
await this.chatbox.initialized; await this.chatbox.initialized;
await this.chatbox.messages.fetched;
this.model = this.chatbox.messages.get(this.mid); this.model = this.chatbox.messages.get(this.mid);
this.requestUpdate(); this.model && this.requestUpdate();
} }
render () { render () {