2018-04-29 15:40:24 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
|
|
|
"jasmine",
|
|
|
|
"mock",
|
|
|
|
"test-utils"
|
|
|
|
], factory);
|
2019-03-27 09:33:15 +01:00
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2018-04-29 15:40:24 +02:00
|
|
|
"use strict";
|
2019-10-09 16:01:38 +02:00
|
|
|
const { Promise, Strophe, $msg, dayjs, sizzle, _ } = converse.env;
|
2018-07-06 00:43:47 +02:00
|
|
|
const u = converse.env.utils;
|
2018-04-29 15:40:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
describe("A Chat Message", function () {
|
|
|
|
|
2019-09-13 08:57:49 +02:00
|
|
|
it("is rejected if it's an unencapsulated forwarded message",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-09-13 08:57:49 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 2);
|
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
const forwarded_contact_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-11-01 16:04:55 +01:00
|
|
|
let models = await _converse.api.chats.get();
|
|
|
|
expect(models.length).toBe(1);
|
2019-09-13 08:57:49 +02:00
|
|
|
const received_stanza = u.toStanza(`
|
|
|
|
<message to='${_converse.jid}' from='${contact_jid}' type='chat' id='${_converse.connection.getUniqueId()}'>
|
|
|
|
<body>A most courteous exposition!</body>
|
|
|
|
<forwarded xmlns='urn:xmpp:forward:0'>
|
|
|
|
<delay xmlns='urn:xmpp:delay' stamp='2019-07-10T23:08:25Z'/>
|
|
|
|
<message from='${forwarded_contact_jid}'
|
|
|
|
id='0202197'
|
|
|
|
to='${_converse.bare_jid}'
|
|
|
|
type='chat'
|
|
|
|
xmlns='jabber:client'>
|
|
|
|
<body>Yet I should kill thee with much cherishing.</body>
|
|
|
|
<mood xmlns='http://jabber.org/protocol/mood'>
|
|
|
|
<amorous/>
|
|
|
|
</mood>
|
|
|
|
</message>
|
|
|
|
</forwarded>
|
|
|
|
</message>
|
|
|
|
`);
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(received_stanza));
|
|
|
|
const sent_stanzas = _converse.connection.sent_stanzas;
|
|
|
|
const sent_stanza = await u.waitUntil(() => sent_stanzas.filter(s => s.querySelector('error')).pop());
|
|
|
|
expect(Strophe.serialize(sent_stanza)).toBe(
|
|
|
|
`<message id="${received_stanza.getAttribute('id')}" to="${contact_jid}" type="error" xmlns="jabber:client">`+
|
|
|
|
'<error type="cancel">'+
|
|
|
|
'<not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>'+
|
|
|
|
'<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">'+
|
|
|
|
'Forwarded messages not part of an encapsulating protocol are not supported</text>'+
|
|
|
|
'</error>'+
|
|
|
|
'</message>');
|
2019-11-01 16:04:55 +01:00
|
|
|
models = await _converse.api.chats.get();
|
|
|
|
expect(models.length).toBe(1);
|
2019-09-13 08:57:49 +02:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2018-07-21 10:41:10 +02:00
|
|
|
it("can be sent as a correction by clicking the pencil icon",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-07-21 10:41:10 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
const textarea = view.el.querySelector('textarea.chat-textarea');
|
|
|
|
|
|
|
|
textarea.value = 'But soft, what light through yonder airlock breaks?';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2018-10-13 23:25:01 +02:00
|
|
|
keyCode: 13 // Enter
|
|
|
|
});
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(view.el.querySelector('.chat-msg__text').textContent)
|
|
|
|
.toBe('But soft, what light through yonder airlock breaks?');
|
|
|
|
expect(textarea.value).toBe('');
|
|
|
|
|
|
|
|
const first_msg = view.model.messages.findWhere({'message': 'But soft, what light through yonder airlock breaks?'});
|
2019-09-24 15:33:41 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg .chat-msg__action').length).toBe(2);
|
2018-10-13 23:25:01 +02:00
|
|
|
let action = view.el.querySelector('.chat-msg .chat-msg__action');
|
|
|
|
expect(action.getAttribute('title')).toBe('Edit this message');
|
|
|
|
|
|
|
|
action.style.opacity = 1;
|
|
|
|
action.click();
|
|
|
|
|
|
|
|
expect(textarea.value).toBe('But soft, what light through yonder airlock breaks?');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(true);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => u.hasClass('correcting', view.el.querySelector('.chat-msg')));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
textarea.value = 'But soft, what light through yonder window breaks?';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2018-10-13 23:25:01 +02:00
|
|
|
keyCode: 13 // Enter
|
2018-07-21 10:41:10 +02:00
|
|
|
});
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
const msg = _converse.connection.send.calls.all()[0].args[0];
|
|
|
|
expect(msg.toLocaleString())
|
2019-06-03 07:58:51 +02:00
|
|
|
.toBe(`<message from="romeo@montague.lit/orchard" id="${msg.nodeTree.getAttribute("id")}" `+
|
|
|
|
`to="mercutio@montague.lit" type="chat" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>But soft, what light through yonder window breaks?</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
2018-11-03 14:37:57 +01:00
|
|
|
`<request xmlns="urn:xmpp:receipts"/>`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`<replace id="${first_msg.get("msgid")}" xmlns="urn:xmpp:message-correct:0"/>`+
|
2019-02-07 14:15:49 +01:00
|
|
|
`<origin-id id="${msg.nodeTree.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`</message>`);
|
|
|
|
expect(view.model.messages.models.length).toBe(1);
|
|
|
|
const corrected_message = view.model.messages.at(0);
|
|
|
|
expect(corrected_message.get('msgid')).toBe(first_msg.get('msgid'));
|
|
|
|
expect(corrected_message.get('correcting')).toBe(false);
|
2019-05-21 16:18:14 +02:00
|
|
|
|
|
|
|
const older_versions = corrected_message.get('older_versions');
|
|
|
|
const keys = Object.keys(older_versions);
|
|
|
|
expect(keys.length).toBe(1);
|
|
|
|
expect(older_versions[keys[0]]).toBe('But soft, what light through yonder airlock breaks?');
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(u.hasClass('correcting', view.el.querySelector('.chat-msg'))).toBe(false);
|
|
|
|
|
|
|
|
// Test that clicking the pencil icon a second time cancels editing.
|
|
|
|
action = view.el.querySelector('.chat-msg .chat-msg__action');
|
|
|
|
action.style.opacity = 1;
|
|
|
|
action.click();
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(textarea.value).toBe('But soft, what light through yonder window breaks?');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(true);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.hasClass('correcting', view.el.querySelector('.chat-msg')) === true);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
action = view.el.querySelector('.chat-msg .chat-msg__action');
|
|
|
|
action.style.opacity = 1;
|
|
|
|
action.click();
|
|
|
|
expect(textarea.value).toBe('');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(false);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (u.hasClass('correcting', view.el.querySelector('.chat-msg')) === false), 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
// Test that messages from other users don't have the pencil icon
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(
|
2018-10-13 23:25:01 +02:00
|
|
|
$msg({
|
|
|
|
'from': contact_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': (new Date()).getTime()
|
|
|
|
}).c('body').t('Hello').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()
|
|
|
|
);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-09-24 15:33:41 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg .chat-msg__action').length).toBe(2);
|
2019-06-19 08:03:36 +02:00
|
|
|
|
|
|
|
// Test confirmation dialog
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
textarea.value = 'But soft, what light through yonder airlock breaks?';
|
|
|
|
action = view.el.querySelector('.chat-msg .chat-msg__action');
|
|
|
|
action.style.opacity = 1;
|
|
|
|
action.click();
|
|
|
|
expect(window.confirm).toHaveBeenCalledWith(
|
|
|
|
'You have an unsent message which will be lost if you continue. Are you sure?');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(true);
|
|
|
|
expect(textarea.value).toBe('But soft, what light through yonder window breaks?');
|
|
|
|
|
|
|
|
textarea.value = 'But soft, what light through yonder airlock breaks?'
|
|
|
|
action.click();
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(false);
|
|
|
|
expect(window.confirm.calls.count()).toBe(2);
|
|
|
|
expect(window.confirm.calls.argsFor(0)).toEqual(
|
|
|
|
['You have an unsent message which will be lost if you continue. Are you sure?']);
|
|
|
|
expect(window.confirm.calls.argsFor(1)).toEqual(
|
|
|
|
['You have an unsent message which will be lost if you continue. Are you sure?']);
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-07-21 10:41:10 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it("can be sent as a correction by using the up arrow",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-07-08 10:13:15 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
2019-10-24 14:29:15 +02:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
const textarea = view.el.querySelector('textarea.chat-textarea');
|
|
|
|
expect(textarea.value).toBe('');
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
|
|
|
keyCode: 38 // Up arrow
|
|
|
|
});
|
|
|
|
expect(textarea.value).toBe('');
|
2018-07-08 15:20:58 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
textarea.value = 'But soft, what light through yonder airlock breaks?';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2018-10-13 23:25:01 +02:00
|
|
|
keyCode: 13 // Enter
|
|
|
|
});
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(view.el.querySelector('.chat-msg__text').textContent)
|
|
|
|
.toBe('But soft, what light through yonder airlock breaks?');
|
|
|
|
|
|
|
|
const first_msg = view.model.messages.findWhere({'message': 'But soft, what light through yonder airlock breaks?'});
|
|
|
|
expect(textarea.value).toBe('');
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
|
|
|
keyCode: 38 // Up arrow
|
|
|
|
});
|
|
|
|
expect(textarea.value).toBe('But soft, what light through yonder airlock breaks?');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(true);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.hasClass('correcting', view.el.querySelector('.chat-msg')), 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
textarea.value = 'But soft, what light through yonder window breaks?';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2018-10-13 23:25:01 +02:00
|
|
|
keyCode: 13 // Enter
|
|
|
|
});
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
const msg = _converse.connection.send.calls.all()[0].args[0];
|
|
|
|
expect(msg.toLocaleString())
|
2019-06-03 07:58:51 +02:00
|
|
|
.toBe(`<message from="romeo@montague.lit/orchard" id="${msg.nodeTree.getAttribute("id")}" `+
|
|
|
|
`to="mercutio@montague.lit" type="chat" `+
|
2018-10-13 23:25:01 +02:00
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>But soft, what light through yonder window breaks?</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
2018-11-03 14:37:57 +01:00
|
|
|
`<request xmlns="urn:xmpp:receipts"/>`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`<replace id="${first_msg.get("msgid")}" xmlns="urn:xmpp:message-correct:0"/>`+
|
2019-02-07 14:15:49 +01:00
|
|
|
`<origin-id id="${msg.nodeTree.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
|
2018-10-13 23:25:01 +02:00
|
|
|
`</message>`);
|
|
|
|
expect(view.model.messages.models.length).toBe(1);
|
|
|
|
const corrected_message = view.model.messages.at(0);
|
|
|
|
expect(corrected_message.get('msgid')).toBe(first_msg.get('msgid'));
|
|
|
|
expect(corrected_message.get('correcting')).toBe(false);
|
2019-05-21 16:18:14 +02:00
|
|
|
|
|
|
|
const older_versions = corrected_message.get('older_versions');
|
|
|
|
const keys = Object.keys(older_versions);
|
|
|
|
expect(keys.length).toBe(1);
|
|
|
|
expect(older_versions[keys[0]]).toBe('But soft, what light through yonder airlock breaks?');
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (u.hasClass('correcting', view.el.querySelector('.chat-msg')) === false), 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
// Test that pressing the down arrow cancels message correction
|
|
|
|
expect(textarea.value).toBe('');
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
|
|
|
keyCode: 38 // Up arrow
|
|
|
|
});
|
|
|
|
expect(textarea.value).toBe('But soft, what light through yonder window breaks?');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(true);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.hasClass('correcting', view.el.querySelector('.chat-msg')), 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(textarea.value).toBe('But soft, what light through yonder window breaks?');
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
|
|
|
keyCode: 40 // Down arrow
|
|
|
|
});
|
|
|
|
expect(textarea.value).toBe('');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(false);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (u.hasClass('correcting', view.el.querySelector('.chat-msg')) === false), 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
textarea.value = 'It is the east, and Juliet is the one.';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2018-10-13 23:25:01 +02:00
|
|
|
keyCode: 13 // Enter
|
|
|
|
});
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(2);
|
|
|
|
|
|
|
|
textarea.value = 'Arise, fair sun, and kill the envious moon';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2018-10-13 23:25:01 +02:00
|
|
|
keyCode: 13 // Enter
|
|
|
|
});
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(3);
|
2018-07-08 15:20:58 +02:00
|
|
|
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
|
|
|
keyCode: 38 // Up arrow
|
|
|
|
});
|
|
|
|
expect(textarea.value).toBe('Arise, fair sun, and kill the envious moon');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBeFalsy();
|
|
|
|
expect(view.model.messages.at(1).get('correcting')).toBeFalsy();
|
|
|
|
expect(view.model.messages.at(2).get('correcting')).toBe(true);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.hasClass('correcting', sizzle('.chat-msg:last', view.el).pop()), 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
textarea.selectionEnd = 0; // Happens by pressing up,
|
|
|
|
// but for some reason not in tests, so we set it manually.
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
|
|
|
keyCode: 38 // Up arrow
|
|
|
|
});
|
|
|
|
expect(textarea.value).toBe('It is the east, and Juliet is the one.');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBeFalsy();
|
|
|
|
expect(view.model.messages.at(1).get('correcting')).toBe(true);
|
|
|
|
expect(view.model.messages.at(2).get('correcting')).toBeFalsy();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.hasClass('correcting', sizzle('.chat-msg', view.el)[1]), 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
textarea.value = 'It is the east, and Juliet is the sun.';
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-10-13 23:25:01 +02:00
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2018-10-13 23:25:01 +02:00
|
|
|
keyCode: 13 // Enter
|
2018-07-08 15:20:58 +02:00
|
|
|
});
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(textarea.value).toBe('');
|
|
|
|
const messages = view.el.querySelectorAll('.chat-msg');
|
|
|
|
expect(messages.length).toBe(3);
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(messages[0].querySelector('.chat-msg__text').textContent)
|
2018-10-13 23:25:01 +02:00
|
|
|
.toBe('But soft, what light through yonder window breaks?');
|
|
|
|
expect(messages[1].querySelector('.chat-msg__text').textContent)
|
|
|
|
.toBe('It is the east, and Juliet is the sun.');
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(messages[2].querySelector('.chat-msg__text').textContent)
|
2018-10-13 23:25:01 +02:00
|
|
|
.toBe('Arise, fair sun, and kill the envious moon');
|
|
|
|
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBeFalsy();
|
|
|
|
expect(view.model.messages.at(1).get('correcting')).toBeFalsy();
|
|
|
|
expect(view.model.messages.at(2).get('correcting')).toBeFalsy();
|
|
|
|
done();
|
2018-07-08 10:13:15 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("can be received out of order, and will still be displayed in the right order",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-07-21 10:41:10 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length)
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.filter_by_resource = true;
|
|
|
|
|
2019-09-13 08:57:49 +02:00
|
|
|
let msg = $msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'id': _converse.connection.getUniqueId(),
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('body').t("message").up()
|
|
|
|
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2018-01-02T13:08:25Z'})
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(sender_jid);
|
|
|
|
|
2019-09-13 08:57:49 +02:00
|
|
|
msg = $msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'id': _converse.connection.getUniqueId(),
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('body').t("Older message").up()
|
|
|
|
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2017-12-31T22:08:25Z'})
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-09-13 08:57:49 +02:00
|
|
|
msg = $msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'id': _converse.connection.getUniqueId(),
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('body').t("Inbetween message").up()
|
|
|
|
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2018-01-01T13:18:23Z'})
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2019-09-13 08:57:49 +02:00
|
|
|
msg = $msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'id': _converse.connection.getUniqueId(),
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('body').t("another inbetween message").up()
|
|
|
|
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2018-01-01T13:18:23Z'})
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2019-09-13 08:57:49 +02:00
|
|
|
msg = $msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'id': _converse.connection.getUniqueId(),
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('body').t("An earlier message on the next day").up()
|
|
|
|
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2018-01-02T12:18:23Z'})
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2019-09-13 08:57:49 +02:00
|
|
|
msg = $msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'id': _converse.connection.getUniqueId(),
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('body').t("newer message from the next day").up()
|
|
|
|
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':'2018-01-02T22:28:23Z'})
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
// Insert <composing> message, to also check that
|
|
|
|
// text messages are inserted correctly with
|
|
|
|
// temporary chat events in the chat contents.
|
|
|
|
msg = $msg({
|
2019-09-13 08:57:49 +02:00
|
|
|
'id': _converse.connection.getUniqueId(),
|
2018-10-13 23:25:01 +02:00
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
msg = $msg({
|
2019-09-13 08:57:49 +02:00
|
|
|
'id': _converse.connection.getUniqueId(),
|
2018-10-13 23:25:01 +02:00
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
|
|
|
|
.c('body').t("latest message")
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
view.clearSpinner(); //cleanup
|
|
|
|
expect(chat_content.querySelectorAll('.date-separator').length).toEqual(4);
|
2018-07-06 00:43:47 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
let day = sizzle('.date-separator:first', chat_content).pop();
|
2019-05-06 11:16:56 +02:00
|
|
|
expect(day.getAttribute('data-isodate')).toEqual(dayjs('2017-12-31T00:00:00').toISOString());
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
let time = sizzle('time:first', chat_content).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(time.textContent).toEqual('Sunday Dec 31st 2017')
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
day = sizzle('.date-separator:first', chat_content).pop();
|
|
|
|
expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('Older message');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
let el = sizzle('.chat-msg:first', chat_content).pop().querySelector('.chat-msg__text')
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', el)).toBe(false);
|
|
|
|
expect(el.textContent).toEqual('Older message');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
time = sizzle('time.separator-text:eq(1)', chat_content).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(time.textContent).toEqual("Monday Jan 1st 2018");
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
day = sizzle('.date-separator:eq(1)', chat_content).pop();
|
2019-05-06 11:16:56 +02:00
|
|
|
expect(day.getAttribute('data-isodate')).toEqual(dayjs('2018-01-01T00:00:00').toISOString());
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('Inbetween message');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
el = sizzle('.chat-msg:eq(1)', chat_content).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(el.querySelector('.chat-msg__text').textContent).toEqual('Inbetween message');
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(el.nextElementSibling.querySelector('.chat-msg__text').textContent).toEqual('another inbetween message');
|
|
|
|
el = sizzle('.chat-msg:eq(2)', chat_content).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(el.querySelector('.chat-msg__text').textContent)
|
|
|
|
.toEqual('another inbetween message');
|
|
|
|
expect(u.hasClass('chat-msg--followup', el)).toBe(true);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
time = sizzle('time.separator-text:nth(2)', chat_content).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(time.textContent).toEqual("Tuesday Jan 2nd 2018");
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
day = sizzle('.date-separator:nth(2)', chat_content).pop();
|
2019-05-06 11:16:56 +02:00
|
|
|
expect(day.getAttribute('data-isodate')).toEqual(dayjs('2018-01-02T00:00:00').toISOString());
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('An earlier message on the next day');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
el = sizzle('.chat-msg:eq(3)', chat_content).pop();
|
|
|
|
expect(el.querySelector('.chat-msg__text').textContent).toEqual('An earlier message on the next day');
|
|
|
|
expect(u.hasClass('chat-msg--followup', el)).toBe(false);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
el = sizzle('.chat-msg:eq(4)', chat_content).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(el.querySelector('.chat-msg__text').textContent).toEqual('message');
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(el.nextElementSibling.querySelector('.chat-msg__text').textContent).toEqual('newer message from the next day');
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', el)).toBe(false);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
day = sizzle('.date-separator:last', chat_content).pop();
|
2019-05-06 11:16:56 +02:00
|
|
|
expect(day.getAttribute('data-isodate')).toEqual(dayjs().startOf('day').toISOString());
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('latest message');
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', el)).toBe(false);
|
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("is ignored if it's a malformed headline message",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-01-25 11:53:07 +01:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
// Ideally we wouldn't have to filter out headline
|
|
|
|
// messages, but Prosody gives them the wrong 'type' :(
|
2019-11-06 11:01:34 +01:00
|
|
|
sinon.spy(converse.env.log, 'info');
|
2019-11-01 16:04:55 +01:00
|
|
|
sinon.spy(_converse.api.chatboxes, 'get');
|
2018-08-15 11:02:24 +02:00
|
|
|
sinon.spy(u, 'isHeadlineMessage');
|
|
|
|
const msg = $msg({
|
2019-06-03 07:58:51 +02:00
|
|
|
from: 'montague.lit',
|
2018-08-15 11:02:24 +02:00
|
|
|
to: _converse.bare_jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t("This headline message will not be shown").tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-11-06 11:01:34 +01:00
|
|
|
expect(converse.env.log.info.calledWith(
|
|
|
|
"onMessage: Ignoring incoming headline message from JID: montague.lit"
|
2018-08-15 11:02:24 +02:00
|
|
|
)).toBeTruthy();
|
|
|
|
expect(u.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(u.isHeadlineMessage.returned(true)).toBeTruthy();
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(_converse.api.chatboxes.get.called).toBeFalsy();
|
2018-08-15 11:02:24 +02:00
|
|
|
// Remove sinon spies
|
2019-11-06 11:01:34 +01:00
|
|
|
converse.env.log.info.restore();
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.api.chatboxes.get.restore();
|
2018-08-15 11:02:24 +02:00
|
|
|
u.isHeadlineMessage.restore();
|
|
|
|
done();
|
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("can be a carbon message, as defined in XEP-0280",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-14 16:37:16 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
const include_nick = false;
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 2, include_nick);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
// Send a message from a different resource
|
2018-08-18 11:28:51 +02:00
|
|
|
const msgtext = 'This is a carbon message';
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-08-18 11:28:51 +02:00
|
|
|
const msg = $msg({
|
2019-05-03 14:10:26 +02:00
|
|
|
'from': _converse.bare_jid,
|
2018-08-15 11:02:24 +02:00
|
|
|
'id': (new Date()).getTime(),
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'xmlns': 'jabber:client'
|
|
|
|
}).c('received', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.bare_jid+'/another-resource',
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t(msgtext).tree();
|
2019-02-24 11:44:34 +01:00
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2018-10-13 23:25:01 +02:00
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2019-05-03 14:10:26 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(view).toBeDefined();
|
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
const msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(msgtext);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(msg_obj.get('fullname')).toBeUndefined();
|
2019-07-11 22:50:30 +02:00
|
|
|
expect(msg_obj.get('nickname')).toBe(null);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('is_delayed')).toEqual(false);
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
2019-08-13 12:03:37 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
expect(chat_content.querySelector('.chat-msg .chat-msg__text').textContent).toEqual(msgtext);
|
|
|
|
expect(chat_content.querySelector('.chat-msg__time').textContent.match(/^[0-9][0-9]:[0-9][0-9]/)).toBeTruthy();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.vcard.get('fullname') === 'Juliet Capulet')
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(chat_content.querySelector('span.chat-msg__author').textContent.trim()).toBe('Juliet Capulet');
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("can be a carbon message that this user sent from a different client, as defined in XEP-0280",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'montague.lit', [], ['vcard-temp']);
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
// Send a message from a different resource
|
|
|
|
const msgtext = 'This is a sent carbon message';
|
2019-06-03 07:58:51 +02:00
|
|
|
const recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
const msg = $msg({
|
|
|
|
'from': _converse.bare_jid,
|
|
|
|
'id': (new Date()).getTime(),
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'xmlns': 'jabber:client'
|
|
|
|
}).c('sent', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': _converse.bare_jid+'/another-resource',
|
|
|
|
'to': recipient_jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t(msgtext).tree();
|
2019-10-24 14:29:15 +02:00
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2018-10-13 23:25:01 +02:00
|
|
|
// Check that the chatbox and its view now exist
|
2019-10-24 14:29:15 +02:00
|
|
|
const chatbox = await _converse.api.chats.get(recipient_jid);
|
|
|
|
const view = _converse.api.chatviews.get(recipient_jid);
|
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(view).toBeDefined();
|
2019-10-24 14:29:15 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
const msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(msgtext);
|
|
|
|
expect(msg_obj.get('fullname')).toEqual(_converse.xmppstatus.get('fullname'));
|
|
|
|
expect(msg_obj.get('sender')).toEqual('me');
|
|
|
|
expect(msg_obj.get('is_delayed')).toEqual(false);
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
|
|
|
const msg_txt = view.el.querySelector('.chat-content .chat-msg .chat-msg__text').textContent;
|
|
|
|
expect(msg_txt).toEqual(msgtext);
|
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will be discarded if it's a malicious message meant to look like a carbon copy",
|
2019-09-11 14:16:48 +02:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-09-11 14:16:48 +02:00
|
|
|
async function (done, _converse) {
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-08-15 11:02:24 +02:00
|
|
|
/* <message from="mallory@evil.example" to="b@xmpp.example">
|
2019-01-25 11:53:07 +01:00
|
|
|
* <received xmlns='urn:xmpp:carbons:2'>
|
|
|
|
* <forwarded xmlns='urn:xmpp:forward:0'>
|
|
|
|
* <message from="alice@xmpp.example" to="bob@xmpp.example/client1">
|
|
|
|
* <body>Please come to Creepy Valley tonight, alone!</body>
|
|
|
|
* </message>
|
|
|
|
* </forwarded>
|
|
|
|
* </received>
|
|
|
|
* </message>
|
|
|
|
*/
|
|
|
|
const msgtext = 'Please come to Creepy Valley tonight, alone!';
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
const impersonated_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-01-25 11:53:07 +01:00
|
|
|
const msg = $msg({
|
2018-08-15 11:02:24 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'id': (new Date()).getTime(),
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'xmlns': 'jabber:client'
|
|
|
|
}).c('received', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': impersonated_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t(msgtext).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
// Check that chatbox for impersonated user is not created.
|
2019-10-24 14:29:15 +02:00
|
|
|
let chatbox = await _converse.api.chats.get(impersonated_jid);
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(chatbox).toBe(null);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
// Check that the chatbox for the malicous user is not created
|
2019-10-24 14:29:15 +02:00
|
|
|
chatbox = await _converse.api.chats.get(sender_jid);
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(chatbox).toBe(null);
|
2018-08-15 11:02:24 +02:00
|
|
|
done();
|
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("received for a minimized chat box will increment a counter on its header",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-20 18:10:55 +01:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
if (_converse.view_mode === 'fullscreen') {
|
|
|
|
return done();
|
|
|
|
}
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2018-08-15 11:02:24 +02:00
|
|
|
const contact_name = mock.cur_names[0];
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-03-29 21:10:45 +01:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-11-20 18:10:55 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-02-22 21:43:49 +01:00
|
|
|
const chatview = _converse.api.chatviews.get(contact_jid);
|
2018-11-20 18:10:55 +01:00
|
|
|
expect(u.isVisible(chatview.el)).toBeTruthy();
|
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
chatview.el.querySelector('.toggle-chatbox-button').click();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
var message = 'This message is sent to a minimized chatbox';
|
2019-06-03 07:58:51 +02:00
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-20 18:10:55 +01:00
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2018-11-20 18:10:55 +01:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatview.model.messages.length);
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-11-20 18:10:55 +01:00
|
|
|
const trimmed_chatboxes = _converse.minimized_chats;
|
|
|
|
const trimmedview = trimmed_chatboxes.get(contact_jid);
|
|
|
|
let count = trimmedview.el.querySelector('.message-count');
|
|
|
|
expect(u.isVisible(chatview.el)).toBeFalsy();
|
|
|
|
expect(trimmedview.model.get('minimized')).toBeTruthy();
|
|
|
|
expect(u.isVisible(count)).toBeTruthy();
|
|
|
|
expect(count.textContent).toBe('1');
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(
|
2018-11-20 18:10:55 +01:00
|
|
|
$msg({
|
2019-06-03 07:58:51 +02:00
|
|
|
from: mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2018-08-15 11:02:24 +02:00
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
2018-11-20 18:10:55 +01:00
|
|
|
}).c('body').t('This message is also sent to a minimized chatbox').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()
|
|
|
|
);
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (chatview.model.messages.length > 1));
|
2018-11-20 18:10:55 +01:00
|
|
|
expect(u.isVisible(chatview.el)).toBeFalsy();
|
|
|
|
expect(trimmedview.model.get('minimized')).toBeTruthy();
|
|
|
|
count = trimmedview.el.querySelector('.message-count');
|
|
|
|
expect(u.isVisible(count)).toBeTruthy();
|
|
|
|
expect(count.textContent).toBe('2');
|
|
|
|
trimmedview.el.querySelector('.restore-chat').click();
|
|
|
|
expect(trimmed_chatboxes.keys().length).toBe(0);
|
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will indicate when it has a time difference of more than a day between it and its predecessor",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
const include_nick = false;
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 2, include_nick);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-08-15 11:02:24 +02:00
|
|
|
const contact_name = mock.cur_names[1];
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-08-18 11:28:51 +02:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.clearChatBoxMessages(_converse, contact_jid);
|
2019-05-06 11:16:56 +02:00
|
|
|
const one_day_ago = dayjs().subtract(1, 'day');
|
2018-10-13 23:25:01 +02:00
|
|
|
const chatbox = _converse.chatboxes.get(contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
|
|
|
|
let message = 'This is a day old message';
|
|
|
|
let msg = $msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
2019-05-06 11:16:56 +02:00
|
|
|
id: one_day_ago.toDate().getTime()
|
2018-10-13 23:25:01 +02:00
|
|
|
}).c('body').t(message).up()
|
2019-06-03 07:58:51 +02:00
|
|
|
.c('delay', { xmlns:'urn:xmpp:delay', from: 'montague.lit', stamp: one_day_ago.toISOString() })
|
2018-10-13 23:25:01 +02:00
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
let msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(message);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(msg_obj.get('fullname')).toBeUndefined();
|
2019-04-17 11:52:41 +02:00
|
|
|
expect(msg_obj.get('nickname')).toBe(null);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('is_delayed')).toEqual(true);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.vcard.get('fullname') === 'Juliet Capulet')
|
2018-10-13 23:25:01 +02:00
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
expect(chat_content.querySelector('.chat-msg .chat-msg__text').textContent).toEqual(message);
|
|
|
|
expect(chat_content.querySelector('.chat-msg__time').textContent.match(/^[0-9][0-9]:[0-9][0-9]/)).toBeTruthy();
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(chat_content.querySelector('span.chat-msg__author').textContent.trim()).toBe('Juliet Capulet');
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(chat_content.querySelectorAll('.date-separator').length).toEqual(1);
|
|
|
|
let day = chat_content.querySelector('.date-separator');
|
|
|
|
expect(day.getAttribute('class')).toEqual('message date-separator');
|
2019-05-06 11:16:56 +02:00
|
|
|
expect(day.getAttribute('data-isodate')).toEqual(dayjs(one_day_ago.startOf('day')).toISOString());
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
let time = chat_content.querySelector('time.separator-text');
|
2019-05-06 11:16:56 +02:00
|
|
|
expect(time.textContent).toEqual(dayjs(one_day_ago.startOf('day')).format("dddd MMM Do YYYY"));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
message = 'This is a current message';
|
|
|
|
msg = $msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: new Date().getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2019-05-06 11:16:56 +02:00
|
|
|
// Check that there is a <time> element, with the required props.
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chat_content.querySelectorAll('time.separator-text').length).toEqual(2); // There are now two time elements
|
|
|
|
|
|
|
|
const message_date = new Date();
|
2019-06-19 11:04:09 +02:00
|
|
|
day = sizzle('.date-separator:last', chat_content);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(day.length).toEqual(1);
|
|
|
|
expect(day[0].getAttribute('class')).toEqual('message date-separator');
|
2019-05-06 11:16:56 +02:00
|
|
|
expect(day[0].getAttribute('data-isodate')).toEqual(dayjs(message_date).startOf('day').toISOString());
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
time = sizzle('time.separator-text:last', chat_content).pop();
|
2019-05-06 11:16:56 +02:00
|
|
|
expect(time.textContent).toEqual(dayjs(message_date).startOf('day').format("dddd MMM Do YYYY"));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
// Normal checks for the 2nd message
|
|
|
|
expect(chatbox.messages.length).toEqual(2);
|
|
|
|
msg_obj = chatbox.messages.models[1];
|
|
|
|
expect(msg_obj.get('message')).toEqual(message);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(msg_obj.get('fullname')).toBeUndefined();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('is_delayed')).toEqual(false);
|
2019-06-19 11:04:09 +02:00
|
|
|
const msg_txt = sizzle('.chat-msg:last .chat-msg__text', chat_content).pop().textContent;
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(chat_content.querySelector('.chat-msg:last-child .chat-msg__text').textContent).toEqual(message);
|
|
|
|
expect(chat_content.querySelector('.chat-msg:last-child .chat-msg__time').textContent.match(/^[0-9][0-9]:[0-9][0-9]/)).toBeTruthy();
|
|
|
|
expect(chat_content.querySelector('.chat-msg:last-child .chat-msg__author').textContent.trim()).toBe('Juliet Capulet');
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
it("is sanitized to prevent Javascript injection attacks",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-08-15 11:02:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
2019-10-24 14:29:15 +02:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
const message = '<p>This message contains <em>some</em> <b>markup</b></p>';
|
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
|
|
|
await test_utils.sendMessage(view, message);
|
|
|
|
expect(view.model.sendMessage).toHaveBeenCalled();
|
2019-03-27 09:33:15 +01:00
|
|
|
const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
|
|
|
expect(msg.textContent).toEqual(message);
|
|
|
|
expect(msg.innerHTML).toEqual('<p>This message contains <em>some</em> <b>markup</b></p>');
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
it("can contain hyperlinks, which will be clickable",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
2019-10-24 14:29:15 +02:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
const message = 'This message contains a hyperlink: www.opkode.com';
|
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
expect(view.model.sendMessage).toHaveBeenCalled();
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-03-27 09:33:15 +01:00
|
|
|
const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
|
|
|
expect(msg.textContent).toEqual(message);
|
|
|
|
expect(msg.innerHTML)
|
2018-10-13 23:25:01 +02:00
|
|
|
.toEqual('This message contains a hyperlink: <a target="_blank" rel="noopener" href="http://www.opkode.com">www.opkode.com</a>');
|
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
it("will have properly escaped URLs",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
2019-10-24 14:29:15 +02:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
let message = "http://www.opkode.com/'onmouseover='alert(1)'whatever";
|
|
|
|
await test_utils.sendMessage(view, message);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-03-27 09:33:15 +01:00
|
|
|
let msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg.textContent).toEqual(message);
|
2019-03-27 09:33:15 +01:00
|
|
|
expect(msg.innerHTML)
|
2018-10-13 23:25:01 +02:00
|
|
|
.toEqual('<a target="_blank" rel="noopener" href="http://www.opkode.com/%27onmouseover=%27alert%281%29%27whatever">http://www.opkode.com/\'onmouseover=\'alert(1)\'whatever</a>');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
message = 'http://www.opkode.com/"onmouseover="alert(1)"whatever';
|
|
|
|
await test_utils.sendMessage(view, message);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg.textContent).toEqual(message);
|
2019-03-27 09:33:15 +01:00
|
|
|
expect(msg.innerHTML).toEqual('<a target="_blank" rel="noopener" href="http://www.opkode.com/%22onmouseover=%22alert%281%29%22whatever">http://www.opkode.com/"onmouseover="alert(1)"whatever</a>');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
message = "https://en.wikipedia.org/wiki/Ender's_Game";
|
|
|
|
await test_utils.sendMessage(view, message);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg.textContent).toEqual(message);
|
2019-03-27 09:33:15 +01:00
|
|
|
expect(msg.innerHTML).toEqual('<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">'+message+'</a>');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-03-27 10:56:09 +01:00
|
|
|
message = "<https://bugs.documentfoundation.org/show_bug.cgi?id=123737>";
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.sendMessage(view, message);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg.textContent).toEqual(message);
|
2019-03-27 10:56:09 +01:00
|
|
|
expect(msg.innerHTML).toEqual(
|
|
|
|
`<<a target="_blank" rel="noopener" href="https://bugs.documentfoundation.org/show_bug.cgi?id=123737">https://bugs.documentfoundation.org/show_bug.cgi?id=123737</a>>`);
|
|
|
|
|
|
|
|
message = '<http://www.opkode.com/"onmouseover="alert(1)"whatever>';
|
|
|
|
await test_utils.sendMessage(view, message);
|
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
2019-03-27 10:56:09 +01:00
|
|
|
expect(msg.textContent).toEqual(message);
|
|
|
|
expect(msg.innerHTML).toEqual(
|
|
|
|
'<<a target="_blank" rel="noopener" href="http://www.opkode.com/%22onmouseover=%22alert%281%29%22whatever">http://www.opkode.com/"onmouseover="alert(1)"whatever</a>>');
|
2019-03-27 11:00:53 +01:00
|
|
|
|
|
|
|
message = `https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=!3m6!1e1!3m4!1sQ7SdHo_bPLPlLlU8GSGWaQ!2e0!7i13312!8i6656!4m5!3m4!1s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08!8m2!3d52.3773668!4d4.5489388!5m1!1e2`
|
|
|
|
await test_utils.sendMessage(view, message);
|
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
2019-03-27 11:00:53 +01:00
|
|
|
expect(msg.textContent).toEqual(message);
|
|
|
|
expect(msg.innerHTML).toEqual(
|
|
|
|
`<a target="_blank" rel="noopener" href="https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=%213m6%211e1%213m4%211sQ7SdHo_bPLPlLlU8GSGWaQ%212e0%217i13312%218i6656%214m5%213m4%211s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08%218m2%213d52.3773668%214d4.5489388%215m1%211e2">https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=!3m6!1e1!3m4!1sQ7SdHo_bPLPlLlU8GSGWaQ!2e0!7i13312!8i6656!4m5!3m4!1s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08!8m2!3d52.3773668!4d4.5489388!5m1!1e2</a>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will render newlines",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-02-12 14:21:45 +01:00
|
|
|
let stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-02-12 14:21:45 +01:00
|
|
|
<body>Hey\nHave you heard the news?</body>
|
|
|
|
</message>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
expect(chat_content.querySelector('.chat-msg__text').innerHTML).toBe('Hey<br>Have you heard the news?');
|
2019-02-12 14:21:45 +01:00
|
|
|
stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-02-12 14:21:45 +01:00
|
|
|
<body>Hey\n\n\nHave you heard the news?</body>
|
|
|
|
</message>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(chat_content.querySelector('.message:last-child .chat-msg__text').innerHTML).toBe('Hey<br><br>Have you heard the news?');
|
2019-02-12 14:21:45 +01:00
|
|
|
stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-02-12 14:21:45 +01:00
|
|
|
<body>Hey\nHave you heard\nthe news?</body>
|
|
|
|
</message>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(chat_content.querySelector('.message:last-child .chat-msg__text').innerHTML).toBe('Hey<br>Have you heard<br>the news?');
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will render images from their URLs",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-18 15:24:34 +01:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
const base_url = 'https://conversejs.org';
|
2018-08-15 11:02:24 +02:00
|
|
|
let message = base_url+"/logo/conversejs-filled.svg";
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-18 15:24:34 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-10-24 14:29:15 +02:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-11-18 15:24:34 +01:00
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
|
|
|
test_utils.sendMessage(view, message);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length, 1000)
|
2018-11-18 15:24:34 +01:00
|
|
|
expect(view.model.sendMessage).toHaveBeenCalled();
|
2019-06-19 11:04:09 +02:00
|
|
|
let msg = sizzle('.chat-content .chat-msg:last .chat-msg__text').pop();
|
2019-03-27 09:33:15 +01:00
|
|
|
expect(msg.innerHTML.trim()).toEqual(
|
2018-11-18 15:24:34 +01:00
|
|
|
'<!-- src/templates/image.html -->\n'+
|
|
|
|
'<a href="'+base_url+'/logo/conversejs-filled.svg" target="_blank" rel="noopener"><img class="chat-image img-thumbnail"'+
|
|
|
|
' src="' + message + '"></a>');
|
|
|
|
message += "?param1=val1¶m2=val2";
|
|
|
|
test_utils.sendMessage(view, message);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length === 2, 1000);
|
2018-11-18 15:24:34 +01:00
|
|
|
expect(view.model.sendMessage).toHaveBeenCalled();
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text').pop();
|
2019-03-27 09:33:15 +01:00
|
|
|
expect(msg.innerHTML.trim()).toEqual(
|
2018-11-18 15:24:34 +01:00
|
|
|
'<!-- src/templates/image.html -->\n'+
|
|
|
|
'<a href="'+base_url+'/logo/conversejs-filled.svg?param1=val1&param2=val2" target="_blank" rel="noopener"><img'+
|
|
|
|
' class="chat-image img-thumbnail" src="'+message.replace(/&/g, '&')+'"></a>')
|
|
|
|
|
|
|
|
// Test now with two images in one message
|
|
|
|
message += ' hello world '+base_url+"/logo/conversejs-filled.svg";
|
|
|
|
test_utils.sendMessage(view, message);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length === 4, 1000);
|
2018-11-18 15:24:34 +01:00
|
|
|
expect(view.model.sendMessage).toHaveBeenCalled();
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text').pop();
|
2019-03-27 09:33:15 +01:00
|
|
|
expect(msg.textContent.trim()).toEqual('hello world');
|
|
|
|
expect(msg.querySelectorAll('img').length).toEqual(2);
|
2018-11-18 15:56:14 +01:00
|
|
|
|
|
|
|
// Non-https images aren't rendered
|
|
|
|
message = base_url+"/logo/conversejs-filled.svg";
|
2019-10-16 17:17:29 +02:00
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
expect(chat_content.querySelectorAll('img').length).toBe(4);
|
2018-11-18 15:56:14 +01:00
|
|
|
test_utils.sendMessage(view, message);
|
2019-10-16 17:17:29 +02:00
|
|
|
expect(chat_content.querySelectorAll('img').length).toBe(4);
|
2018-11-18 15:24:34 +01:00
|
|
|
done();
|
2018-04-29 15:40:24 +02:00
|
|
|
}));
|
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will render the message time as configured",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2018-08-15 11:02:24 +02:00
|
|
|
_converse.time_format = 'hh:mm';
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
const message = 'This message is sent from this chatbox';
|
|
|
|
await test_utils.sendMessage(view, message);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-10-04 18:26:33 +02:00
|
|
|
const chatbox = await _converse.api.chats.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chatbox.messages.models.length, 1);
|
|
|
|
const msg_object = chatbox.messages.models[0];
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
const msg_author = view.el.querySelector('.chat-content .chat-msg:last-child .chat-msg__author');
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(msg_author.textContent.trim()).toBe('Romeo Montague');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-19 11:04:09 +02:00
|
|
|
const msg_time = view.el.querySelector('.chat-content .chat-msg:last-child .chat-msg__time');
|
2019-05-06 11:16:56 +02:00
|
|
|
const time = dayjs(msg_object.get('time')).format(_converse.time_format);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_time.textContent).toBe(time);
|
|
|
|
done();
|
2018-04-29 15:40:24 +02:00
|
|
|
}));
|
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will be correctly identified and rendered as a followup message",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-18 11:28:51 +02:00
|
|
|
const base_time = new Date();
|
|
|
|
const ONE_MINUTE_LATER = 60000;
|
2018-08-15 11:02:24 +02:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 300);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.filter_by_resource = true;
|
2018-08-15 11:02:24 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
jasmine.clock().install();
|
|
|
|
jasmine.clock().mockDate(base_time);
|
2018-08-15 11:02:24 +02:00
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': (new Date()).getTime()
|
|
|
|
}).c('body').t('A message').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2019-05-16 11:40:30 +02:00
|
|
|
await new Promise(resolve => _converse.on('chatBoxInitialized', resolve));
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(sender_jid);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
jasmine.clock().tick(3*ONE_MINUTE_LATER);
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': (new Date()).getTime()
|
|
|
|
}).c('body').t("Another message 3 minutes later").up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
jasmine.clock().tick(11*ONE_MINUTE_LATER);
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': (new Date()).getTime()
|
|
|
|
}).c('body').t("Another message 14 minutes since we started").up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
jasmine.clock().tick(1000);
|
|
|
|
// Insert <composing> message, to also check that
|
|
|
|
// text messages are inserted correctly with
|
|
|
|
// temporary chat events in the chat contents.
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
'id': 'aeb219',
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
|
|
|
|
.tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
jasmine.clock().tick(1*ONE_MINUTE_LATER);
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
2019-09-13 08:57:49 +02:00
|
|
|
'id': _converse.connection.getUniqueId()
|
2018-10-13 23:25:01 +02:00
|
|
|
}).c('body').t("Another message 1 minute and 1 second since the previous one").up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
jasmine.clock().tick(1*ONE_MINUTE_LATER);
|
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
await test_utils.sendMessage(view, "Another message within 10 minutes, but from a different person");
|
|
|
|
|
|
|
|
expect(chat_content.querySelectorAll('.message').length).toBe(6);
|
|
|
|
expect(chat_content.querySelectorAll('.chat-msg').length).toBe(5);
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(2)'))).toBe(false);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(2) .chat-msg__text').textContent).toBe("A message");
|
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(3)'))).toBe(true);
|
2019-06-17 21:42:55 +02:00
|
|
|
expect(chat_content.querySelector('.message:nth-child(3) .chat-msg__text').textContent).toBe(
|
2019-06-19 11:04:09 +02:00
|
|
|
"Another message 3 minutes later");
|
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(4)'))).toBe(false);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(4) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message 14 minutes since we started");
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(5)'))).toBe(true);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(5) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message 1 minute and 1 second since the previous one");
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(6)'))).toBe(false);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(6) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message within 10 minutes, but from a different person");
|
|
|
|
|
|
|
|
// Let's add a delayed, inbetween message
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(
|
2019-09-13 08:57:49 +02:00
|
|
|
$msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'id': _converse.connection.getUniqueId(),
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t("A delayed message, sent 5 minutes since we started").up()
|
|
|
|
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp': dayjs(base_time).add(5, 'minutes').toISOString()})
|
|
|
|
.tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(chat_content.querySelectorAll('.message').length).toBe(7);
|
|
|
|
expect(chat_content.querySelectorAll('.chat-msg').length).toBe(6);
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(2)'))).toBe(false);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(2) .chat-msg__text').textContent).toBe("A message");
|
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(3)'))).toBe(true);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(3) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message 3 minutes later");
|
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(4)'))).toBe(true);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(4) .chat-msg__text').textContent).toBe(
|
|
|
|
"A delayed message, sent 5 minutes since we started");
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(5)'))).toBe(true);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(5) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message 14 minutes since we started");
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(6)'))).toBe(true);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(6) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message 1 minute and 1 second since the previous one");
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(7)'))).toBe(false);
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(
|
2019-09-13 08:57:49 +02:00
|
|
|
$msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'id': _converse.connection.getUniqueId(),
|
|
|
|
'to': sender_jid,
|
|
|
|
'from': _converse.bare_jid+"/some-other-resource",
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('body').t("A carbon message 4 minutes later").up()
|
|
|
|
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':dayjs(base_time).add(4, 'minutes').toISOString()})
|
|
|
|
.tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(chat_content.querySelectorAll('.message').length).toBe(8);
|
|
|
|
expect(chat_content.querySelectorAll('.chat-msg').length).toBe(7);
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(2)'))).toBe(false);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(2) .chat-msg__text').textContent).toBe("A message");
|
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(3)'))).toBe(true);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(3) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message 3 minutes later");
|
2019-06-17 21:42:55 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(4)'))).toBe(false);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(4) .chat-msg__text').textContent).toBe(
|
2019-06-19 11:04:09 +02:00
|
|
|
"A carbon message 4 minutes later");
|
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(5)'))).toBe(false);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(5) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"A delayed message, sent 5 minutes since we started");
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(6)'))).toBe(true);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(6) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message 14 minutes since we started");
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(7)'))).toBe(true);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(7) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message 1 minute and 1 second since the previous one");
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', chat_content.querySelector('.message:nth-child(8)'))).toBe(false);
|
|
|
|
expect(chat_content.querySelector('.message:nth-child(8) .chat-msg__text').textContent).toBe(
|
2018-10-13 23:25:01 +02:00
|
|
|
"Another message within 10 minutes, but from a different person");
|
|
|
|
|
|
|
|
jasmine.clock().uninstall();
|
|
|
|
done();
|
2018-04-29 15:40:24 +02:00
|
|
|
}));
|
|
|
|
|
2018-11-03 14:37:57 +01:00
|
|
|
it("received may emit a message delivery receipt",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-01-25 11:53:07 +01:00
|
|
|
async function (done, _converse) {
|
2019-02-24 11:44:34 +01:00
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-03 14:37:57 +01:00
|
|
|
const msg_id = u.getUniqueId();
|
|
|
|
const sent_stanzas = [];
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
|
|
|
sent_stanzas.push(stanza);
|
|
|
|
});
|
|
|
|
const msg = $msg({
|
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': msg_id,
|
|
|
|
}).c('body').t('Message!').up()
|
|
|
|
.c('request', {'xmlns': Strophe.NS.RECEIPTS}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-02-14 13:43:24 +01:00
|
|
|
const sent_messages = sent_stanzas.map(s => _.isElement(s) ? s : s.nodeTree).filter(s => s.nodeName === 'message');
|
|
|
|
expect(sent_messages.length).toBe(1);
|
|
|
|
const receipt = sizzle(`received[xmlns="${Strophe.NS.RECEIPTS}"]`, sent_messages[0]).pop();
|
2018-11-20 17:56:52 +01:00
|
|
|
expect(Strophe.serialize(receipt)).toBe(`<received id="${msg_id}" xmlns="${Strophe.NS.RECEIPTS}"/>`);
|
2018-11-03 14:37:57 +01:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2018-12-12 16:42:29 +01:00
|
|
|
it("carbon received does not emit a message delivery receipt",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-12-12 16:42:29 +01:00
|
|
|
async function (done, _converse) {
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-12-12 16:42:29 +01:00
|
|
|
const msg_id = u.getUniqueId();
|
2019-01-31 19:22:30 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
spyOn(view.model, 'sendReceiptStanza').and.callThrough();
|
2018-12-12 16:42:29 +01:00
|
|
|
const msg = $msg({
|
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': u.getUniqueId(),
|
|
|
|
}).c('received', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.bare_jid+'/another-resource',
|
|
|
|
'type': 'chat',
|
|
|
|
'id': msg_id
|
|
|
|
}).c('body').t('Message!').up()
|
|
|
|
.c('request', {'xmlns': Strophe.NS.RECEIPTS}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-01-31 19:22:30 +01:00
|
|
|
expect(view.model.sendReceiptStanza).not.toHaveBeenCalled();
|
2018-12-12 16:42:29 +01:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-06-26 11:09:07 +02:00
|
|
|
describe("when sent", function () {
|
2018-11-03 14:37:57 +01:00
|
|
|
|
2019-06-26 11:09:07 +02:00
|
|
|
it("can have its delivery acknowledged by a receipt",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-06-26 11:09:07 +02:00
|
|
|
async function (done, _converse) {
|
2018-12-16 10:58:48 +01:00
|
|
|
|
2019-06-26 11:09:07 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
const textarea = view.el.querySelector('textarea.chat-textarea');
|
|
|
|
textarea.value = 'But soft, what light through yonder airlock breaks?';
|
|
|
|
view.onKeyDown({
|
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2019-06-26 11:09:07 +02:00
|
|
|
keyCode: 13 // Enter
|
|
|
|
});
|
|
|
|
const chatbox = _converse.chatboxes.get(contact_jid);
|
|
|
|
expect(chatbox).toBeDefined();
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-06-26 11:09:07 +02:00
|
|
|
let msg_obj = chatbox.messages.models[0];
|
|
|
|
let msg_id = msg_obj.get('msgid');
|
|
|
|
let msg = $msg({
|
|
|
|
'from': contact_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'id': u.getUniqueId(),
|
|
|
|
}).c('received', {'id': msg_id, xmlns: Strophe.NS.RECEIPTS}).up().tree();
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2019-06-26 11:09:07 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(1);
|
|
|
|
|
|
|
|
// Also handle receipts with type 'chat'. See #1353
|
2019-11-01 16:04:55 +01:00
|
|
|
spyOn(_converse, 'handleMessageStanza').and.callThrough();
|
2019-06-26 11:09:07 +02:00
|
|
|
textarea.value = 'Another message';
|
|
|
|
view.onKeyDown({
|
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2019-06-26 11:09:07 +02:00
|
|
|
keyCode: 13 // Enter
|
|
|
|
});
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-06-26 11:09:07 +02:00
|
|
|
|
|
|
|
msg_obj = chatbox.messages.models[1];
|
|
|
|
msg_id = msg_obj.get('msgid');
|
|
|
|
msg = $msg({
|
|
|
|
'from': contact_jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'id': u.getUniqueId(),
|
|
|
|
}).c('received', {'id': msg_id, xmlns: Strophe.NS.RECEIPTS}).up().tree();
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2019-06-26 11:09:07 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(2);
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(_converse.handleMessageStanza.calls.count()).toBe(1);
|
2019-06-26 11:09:07 +02:00
|
|
|
done();
|
|
|
|
}));
|
2018-12-16 10:58:48 +01:00
|
|
|
|
2018-11-03 14:37:57 +01:00
|
|
|
|
2019-06-26 11:09:07 +02:00
|
|
|
it("will appear inside the chatbox it was sent from",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-06-26 11:09:07 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2019-06-26 11:09:07 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
const message = 'This message is sent from this chatbox';
|
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
|
|
|
await test_utils.sendMessage(view, message);
|
|
|
|
expect(view.model.sendMessage).toHaveBeenCalled();
|
|
|
|
expect(view.model.messages.length, 2);
|
|
|
|
expect(_converse.api.trigger.calls.mostRecent().args, ['messageSend', message]);
|
|
|
|
expect(sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop().textContent).toEqual(message);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-06-26 10:59:02 +02:00
|
|
|
|
|
|
|
it("will be trimmed of leading and trailing whitespace",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-06-26 10:59:02 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
const message = ' \nThis message is sent from this chatbox \n \n';
|
|
|
|
await test_utils.sendMessage(view, message);
|
|
|
|
expect(view.model.messages.at(0).get('message')).toEqual(message.trim());
|
|
|
|
const message_el = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
|
|
|
expect(message_el.textContent).toEqual(message.trim());
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2018-08-15 17:22:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
describe("when received from someone else", function () {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will open a chatbox and be displayed inside it",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
const include_nick = false;
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1, include_nick);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 300);
|
2019-03-29 21:10:45 +01:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-10-13 23:25:01 +02:00
|
|
|
const message = 'This is a received message';
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
// We don't already have an open chatbox for this user
|
|
|
|
expect(_converse.chatboxes.get(sender_jid)).not.toBeDefined();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(
|
2018-10-13 23:25:01 +02:00
|
|
|
$msg({
|
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()
|
|
|
|
);
|
2019-11-01 16:04:55 +01:00
|
|
|
const chatbox = await _converse.chatboxes.get(sender_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chatbox).toBeDefined();
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(sender_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view).toBeDefined();
|
|
|
|
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-10-13 23:25:01 +02:00
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
const msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(message);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(msg_obj.get('fullname')).toBeUndefined();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('is_delayed')).toEqual(false);
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
2019-11-01 16:04:55 +01:00
|
|
|
const mel = await u.waitUntil(() => chat_content.querySelector('.chat-msg .chat-msg__text'));
|
|
|
|
expect(mel.textContent).toEqual(message);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chat_content.querySelector('.chat-msg__time').textContent.match(/^[0-9][0-9]:[0-9][0-9]/)).toBeTruthy();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.vcard.get('fullname') === mock.cur_names[0]);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(chat_content.querySelector('span.chat-msg__author').textContent.trim()).toBe('Mercutio');
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-06-26 10:59:02 +02:00
|
|
|
it("will be trimmed of leading and trailing whitespace",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {},
|
2019-06-26 10:59:02 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1, false);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 300);
|
2019-06-26 10:59:02 +02:00
|
|
|
const message = '\n\n This is a received message \n\n';
|
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(
|
2019-06-26 10:59:02 +02:00
|
|
|
$msg({
|
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()
|
|
|
|
);
|
|
|
|
const view = _converse.api.chatviews.get(sender_jid);
|
|
|
|
expect(view.model.messages.length).toEqual(1);
|
|
|
|
const msg_obj = view.model.messages.at(0);
|
|
|
|
expect(msg_obj.get('message')).toEqual(message.trim());
|
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
2019-11-01 16:04:55 +01:00
|
|
|
const mel = await u.waitUntil(() => chat_content.querySelector('.chat-msg .chat-msg__text'));
|
|
|
|
expect(mel.textContent).toEqual(message.trim());
|
2019-06-26 10:59:02 +02:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("can be replaced with a correction",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-08-18 11:28:51 +02:00
|
|
|
const msg_id = u.getUniqueId();
|
2018-10-13 23:25:01 +02:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, sender_jid);
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': msg_id,
|
|
|
|
}).c('body').t('But soft, what light through yonder airlock breaks?').tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(view.el.querySelector('.chat-msg__text').textContent)
|
|
|
|
.toBe('But soft, what light through yonder airlock breaks?');
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': u.getUniqueId(),
|
|
|
|
}).c('body').t('But soft, what light through yonder chimney breaks?').up()
|
|
|
|
.c('replace', {'id': msg_id, 'xmlns': 'urn:xmpp:message-correct:0'}).tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.el.querySelector('.chat-msg__text').textContent)
|
|
|
|
.toBe('But soft, what light through yonder chimney breaks?');
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg__content .fa-edit').length).toBe(1);
|
2019-06-25 12:06:47 +02:00
|
|
|
expect(view.model.messages.models.length).toBe(1);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'id': u.getUniqueId(),
|
|
|
|
}).c('body').t('But soft, what light through yonder window breaks?').up()
|
|
|
|
.c('replace', {'id': msg_id, 'xmlns': 'urn:xmpp:message-correct:0'}).tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(view.el.querySelector('.chat-msg__text').textContent)
|
|
|
|
.toBe('But soft, what light through yonder window breaks?');
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg__content .fa-edit').length).toBe(1);
|
|
|
|
view.el.querySelector('.chat-msg__content .fa-edit').click();
|
|
|
|
const modal = view.model.messages.at(0).message_versions_modal;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2018-10-13 23:25:01 +02:00
|
|
|
const older_msgs = modal.el.querySelectorAll('.older-msg');
|
|
|
|
expect(older_msgs.length).toBe(2);
|
2019-05-21 16:18:14 +02:00
|
|
|
expect(older_msgs[0].childNodes[0].nodeName).toBe('TIME');
|
|
|
|
expect(older_msgs[0].childNodes[1].textContent).toBe(': But soft, what light through yonder airlock breaks?');
|
2019-06-25 12:06:47 +02:00
|
|
|
expect(view.model.messages.models.length).toBe(1);
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
describe("when a chatbox is opened for someone who is not in the roster", function () {
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("the VCard for that user is fetched and the chatbox updated with the results",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-24 14:29:15 +02:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {'allow_non_roster_messaging': true},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
2019-03-29 21:10:45 +01:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-08-15 11:02:24 +02:00
|
|
|
var vcard_fetched = false;
|
|
|
|
spyOn(_converse.api.vcard, "get").and.callFake(function () {
|
|
|
|
vcard_fetched = true;
|
|
|
|
return Promise.resolve({
|
|
|
|
'fullname': mock.cur_names[0],
|
2019-05-05 19:05:45 +02:00
|
|
|
'vcard_updated': (new Date()).toISOString(),
|
2018-08-15 11:02:24 +02:00
|
|
|
'jid': sender_jid
|
|
|
|
});
|
|
|
|
});
|
2018-10-13 23:25:01 +02:00
|
|
|
const message = 'This is a received message from someone not on the roster';
|
|
|
|
const msg = $msg({
|
2018-08-15 11:02:24 +02:00
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
// We don't already have an open chatbox for this user
|
|
|
|
expect(_converse.chatboxes.get(sender_jid)).not.toBeDefined();
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
// Check that the chatbox and its view now exist
|
2019-10-24 14:29:15 +02:00
|
|
|
const chatbox = await _converse.api.chats.get(sender_jid);
|
|
|
|
const view = _converse.api.chatviews.get(sender_jid);
|
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(view).toBeDefined();
|
|
|
|
expect(chatbox.get('fullname') === sender_jid);
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.chat-msg__author').textContent.trim() === 'Mercutio');
|
2018-10-13 23:25:01 +02:00
|
|
|
let author_el = view.el.querySelector('.chat-msg__author');
|
2019-06-03 07:58:51 +02:00
|
|
|
expect( _.includes(author_el.textContent.trim(), 'Mercutio')).toBeTruthy();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => vcard_fetched, 100);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(_converse.api.vcard.get).toHaveBeenCalled();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.vcard.get('fullname') === mock.cur_names[0])
|
2018-10-13 23:25:01 +02:00
|
|
|
author_el = view.el.querySelector('.chat-msg__author');
|
2019-06-03 07:58:51 +02:00
|
|
|
expect( _.includes(author_el.textContent.trim(), 'Mercutio')).toBeTruthy();
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
|
|
|
});
|
2018-06-30 15:07:30 +02:00
|
|
|
|
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
describe("who is not on the roster", function () {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will open a chatbox and be displayed inside it if allow_non_roster_messaging is true",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-24 14:29:15 +02:00
|
|
|
['rosterGroupsFetched'], {'allow_non_roster_messaging': false},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-10-13 23:25:01 +02:00
|
|
|
const message = 'This is a received message from someone not on the roster';
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
const msg = $msg({
|
2018-08-15 11:02:24 +02:00
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
// We don't already have an open chatbox for this user
|
|
|
|
expect(_converse.chatboxes.get(sender_jid)).not.toBeDefined();
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-22 21:43:49 +01:00
|
|
|
let chatbox = await _converse.api.chats.get(sender_jid);
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(chatbox).toBe(null);
|
2018-08-15 11:02:24 +02:00
|
|
|
// onMessage is a handler for received XMPP messages
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-02-13 15:24:24 +01:00
|
|
|
let view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
expect(view).not.toBeDefined();
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
// onMessage is a handler for received XMPP messages
|
2019-02-13 15:24:24 +01:00
|
|
|
_converse.allow_non_roster_messaging = true;
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-02-13 15:24:24 +01:00
|
|
|
view = _converse.chatboxviews.get(sender_jid);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-10-13 23:25:01 +02:00
|
|
|
// Check that the chatbox and its view now exist
|
2019-10-24 14:29:15 +02:00
|
|
|
chatbox = await _converse.api.chats.get(sender_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(view).toBeDefined();
|
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
const msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(message);
|
|
|
|
expect(msg_obj.get('fullname')).toEqual(undefined);
|
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('is_delayed')).toEqual(false);
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.chat-msg__author').textContent.trim() === 'Mercutio');
|
2018-10-13 23:25:01 +02:00
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
expect(chat_content.querySelector('.chat-msg .chat-msg__text').textContent).toEqual(message);
|
|
|
|
expect(chat_content.querySelector('.chat-msg__time').textContent.match(/^[0-9][0-9]:[0-9][0-9]/)).toBeTruthy();
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(chat_content.querySelector('span.chat-msg__author').textContent.trim()).toBe('Mercutio');
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-07-30 18:16:32 +02:00
|
|
|
});
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-04-30 12:15:26 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
describe("and for which then an error message is received from the server", function () {
|
2018-04-30 12:15:26 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will have the error message displayed after itself",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-30 12:15:26 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2018-04-30 12:15:26 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
// TODO: what could still be done for error
|
|
|
|
// messages... if the <error> element has type
|
|
|
|
// "cancel", then we know the messages wasn't sent,
|
|
|
|
// and can give the user a nicer indication of
|
|
|
|
// that.
|
|
|
|
/* <message from="scotty@enterprise.com/_converse.js-84843526"
|
|
|
|
* to="kirk@enterprise.com.com"
|
|
|
|
* type="chat"
|
|
|
|
* id="82bc02ce-9651-4336-baf0-fa04762ed8d2"
|
|
|
|
* xmlns="jabber:client">
|
|
|
|
* <body>yo</body>
|
|
|
|
* <active xmlns="http://jabber.org/protocol/chatstates"/>
|
|
|
|
* </message>
|
|
|
|
*/
|
2018-08-18 11:28:51 +02:00
|
|
|
const error_txt = 'Server-to-server connection failed: Connecting failed: connection timeout';
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-10-09 16:01:38 +02:00
|
|
|
let fullname = _converse.xmppstatus.get('fullname'); // eslint-disable-line no-unused-vars
|
|
|
|
fullname = _.isEmpty(fullname) ? _converse.bare_jid: fullname;
|
2018-10-13 23:25:01 +02:00
|
|
|
await _converse.api.chats.open(sender_jid)
|
2019-04-10 23:25:14 +02:00
|
|
|
let msg_text = 'This message will not be sent, due to an error';
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(sender_jid);
|
2019-09-12 19:15:13 +02:00
|
|
|
const message = await view.model.sendMessage(msg_text);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
let msg_txt = sizzle('.chat-msg:last .chat-msg__text', chat_content).pop().textContent;
|
|
|
|
expect(msg_txt).toEqual(msg_text);
|
|
|
|
|
|
|
|
// We send another message, for which an error will
|
|
|
|
// not be received, to test that errors appear
|
|
|
|
// after the relevant message.
|
|
|
|
msg_text = 'This message will be sent, and also receive an error';
|
2019-09-12 19:15:13 +02:00
|
|
|
const second_message = await view.model.sendMessage(msg_text);
|
|
|
|
await u.waitUntil(() => sizzle('.chat-msg .chat-msg__text', chat_content).length === 2, 1000);
|
2019-06-19 11:04:09 +02:00
|
|
|
msg_txt = sizzle('.chat-msg:last .chat-msg__text', chat_content).pop().textContent;
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_txt).toEqual(msg_text);
|
|
|
|
|
|
|
|
/* <message xmlns="jabber:client"
|
|
|
|
* to="scotty@enterprise.com/_converse.js-84843526"
|
|
|
|
* type="error"
|
|
|
|
* id="82bc02ce-9651-4336-baf0-fa04762ed8d2"
|
|
|
|
* from="kirk@enterprise.com.com">
|
|
|
|
* <error type="cancel">
|
|
|
|
* <remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
|
|
|
|
* <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Server-to-server connection failed: Connecting failed: connection timeout</text>
|
|
|
|
* </error>
|
|
|
|
* </message>
|
|
|
|
*/
|
|
|
|
let stanza = $msg({
|
|
|
|
'to': _converse.connection.jid,
|
2018-11-14 15:15:29 +01:00
|
|
|
'type': 'error',
|
2019-09-12 19:15:13 +02:00
|
|
|
'id': message.get('msgid'),
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid
|
|
|
|
})
|
|
|
|
.c('error', {'type': 'cancel'})
|
|
|
|
.c('remote-server-not-found', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" }).up()
|
|
|
|
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
|
|
|
|
.t('Server-to-server connection failed: Connecting failed: connection timeout');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-08-12 20:16:34 +02:00
|
|
|
expect(chat_content.querySelector('.chat-error').textContent.trim()).toEqual(error_txt);
|
2018-10-13 23:25:01 +02:00
|
|
|
stanza = $msg({
|
|
|
|
'to': _converse.connection.jid,
|
2018-11-14 15:15:29 +01:00
|
|
|
'type': 'error',
|
2019-09-12 19:15:13 +02:00
|
|
|
'id': second_message.get('id'),
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid
|
|
|
|
})
|
|
|
|
.c('error', {'type': 'cancel'})
|
|
|
|
.c('remote-server-not-found', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" }).up()
|
|
|
|
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
|
|
|
|
.t('Server-to-server connection failed: Connecting failed: connection timeout');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chat_content.querySelectorAll('.chat-error').length).toEqual(2);
|
|
|
|
|
2018-11-14 15:15:29 +01:00
|
|
|
// We don't render duplicates
|
2018-10-13 23:25:01 +02:00
|
|
|
stanza = $msg({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type':'error',
|
2018-11-14 15:15:29 +01:00
|
|
|
'id': '6fcdeee3-000f-4ce8-a17e-9ce28f0ae104',
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid
|
|
|
|
})
|
|
|
|
.c('error', {'type': 'cancel'})
|
|
|
|
.c('remote-server-not-found', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" }).up()
|
|
|
|
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
|
|
|
|
.t('Server-to-server connection failed: Connecting failed: connection timeout');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(chat_content.querySelectorAll('.chat-error').length).toEqual(2);
|
2018-11-14 15:15:29 +01:00
|
|
|
|
|
|
|
msg_text = 'This message will be sent, and also receive an error';
|
2019-09-12 19:15:13 +02:00
|
|
|
const third_message = await view.model.sendMessage(msg_text);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-06-19 11:04:09 +02:00
|
|
|
msg_txt = sizzle('.chat-msg:last .chat-msg__text', chat_content).pop().textContent;
|
2018-11-14 15:15:29 +01:00
|
|
|
expect(msg_txt).toEqual(msg_text);
|
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
// A different error message will however render
|
|
|
|
stanza = $msg({
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type':'error',
|
2019-09-12 19:15:13 +02:00
|
|
|
'id': third_message.get('id'),
|
2018-10-13 23:25:01 +02:00
|
|
|
'from': sender_jid
|
|
|
|
})
|
|
|
|
.c('error', {'type': 'cancel'})
|
2019-09-12 19:15:13 +02:00
|
|
|
.c('not-allowed', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" }).up()
|
2018-10-13 23:25:01 +02:00
|
|
|
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
|
|
|
|
.t('Something else went wrong as well');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-24 14:29:15 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length > 3);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(chat_content.querySelectorAll('.chat-error').length).toEqual(3);
|
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-11-14 14:33:07 +01:00
|
|
|
|
|
|
|
it("will not show to the user an error message for a CSI message",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-14 14:33:07 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
// See #1317
|
|
|
|
// https://github.com/conversejs/converse.js/issues/1317
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-11-14 14:33:07 +01:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-14 14:33:07 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
|
|
|
|
const messages = _converse.connection.sent_stanzas.filter(s => s.nodeName === 'message');
|
|
|
|
expect(messages.length).toBe(1);
|
|
|
|
expect(Strophe.serialize(messages[0])).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<message id="${messages[0].getAttribute('id')}" to="tybalt@montague.lit" type="chat" xmlns="jabber:client">`+
|
2018-11-14 14:33:07 +01:00
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<no-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`<no-permanent-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`</message>`);
|
|
|
|
|
|
|
|
const stanza = $msg({
|
|
|
|
'from': contact_jid,
|
|
|
|
'type': 'error',
|
|
|
|
'id': messages[0].getAttribute('id')
|
|
|
|
}).c('error', {'type': 'cancel', 'code': '503'})
|
|
|
|
.c('service-unavailable', { 'xmlns': 'urn:ietf:params:xml:ns:xmpp-stanzas' }).up()
|
|
|
|
.c('text', { 'xmlns': 'urn:ietf:params:xml:ns:xmpp-stanzas' })
|
|
|
|
.t('User session not found')
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
const chat_content = view.el.querySelector('.chat-content');
|
|
|
|
expect(chat_content.querySelectorAll('.chat-error').length).toEqual(0);
|
|
|
|
done();
|
|
|
|
}));
|
2018-08-15 11:02:24 +02:00
|
|
|
});
|
2018-04-30 12:15:26 +02:00
|
|
|
|
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("will cause the chat area to be scrolled down only if it was at the bottom originally",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-30 12:15:26 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid)
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(sender_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
// Create enough messages so that there's a scrollbar.
|
|
|
|
const promises = [];
|
|
|
|
for (let i=0; i<20; i++) {
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-08-15 11:02:24 +02:00
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
2018-10-13 23:25:01 +02:00
|
|
|
id: _converse.connection.getUniqueId(),
|
|
|
|
}).c('body').t('Message: '+i).up()
|
2018-08-15 11:02:24 +02:00
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
promises.push(new Promise(resolve => view.once('messageInserted', resolve)));
|
2018-10-13 23:25:01 +02:00
|
|
|
}
|
|
|
|
await Promise.all(promises);
|
2019-05-24 08:39:21 +02:00
|
|
|
// XXX Fails on Travis
|
2019-07-11 22:50:30 +02:00
|
|
|
// await u.waitUntil(() => view.content.scrollTop, 1000)
|
|
|
|
await u.waitUntil(() => !view.model.get('auto_scrolled'), 500);
|
2018-10-13 23:25:01 +02:00
|
|
|
view.content.scrollTop = 0;
|
2019-05-24 08:39:21 +02:00
|
|
|
// XXX Fails on Travis
|
2019-07-11 22:50:30 +02:00
|
|
|
// await u.waitUntil(() => view.model.get('scrolled'), 900);
|
2019-06-19 11:04:09 +02:00
|
|
|
view.model.set('scrolled', true);
|
2019-05-24 08:39:21 +02:00
|
|
|
|
|
|
|
const message = 'This message is received while the chat area is scrolled up';
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza($msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length > 20, 1000);
|
2018-10-13 23:25:01 +02:00
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
2019-06-19 11:04:09 +02:00
|
|
|
const msg_txt = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop().textContent;
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_txt).toEqual(message);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(view.el.querySelector('.new-msgs-indicator')), 900);
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(view.model.get('scrolled')).toBe(true);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.content.scrollTop).toBe(0);
|
|
|
|
expect(u.isVisible(view.el.querySelector('.new-msgs-indicator'))).toBeTruthy();
|
|
|
|
// Scroll down again
|
|
|
|
view.content.scrollTop = view.content.scrollHeight;
|
2019-05-24 08:39:21 +02:00
|
|
|
// XXX Fails on Travis
|
2019-07-11 22:50:30 +02:00
|
|
|
// await u.waitUntil(() => !u.isVisible(view.el.querySelector('.new-msgs-indicator')), 900);
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
2018-04-30 12:15:26 +02:00
|
|
|
|
2018-08-15 11:02:24 +02:00
|
|
|
it("is ignored if it's intended for a different resource and filter_by_resource is set to true",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-30 12:15:26 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length)
|
2018-10-13 23:25:01 +02:00
|
|
|
// Send a message from a different resource
|
2019-11-06 11:01:34 +01:00
|
|
|
spyOn(converse.env.log, 'info');
|
2019-11-01 16:04:55 +01:00
|
|
|
spyOn(_converse.api.chatboxes, 'create').and.callThrough();
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.filter_by_resource = true;
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
let msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.bare_jid+"/some-other-resource",
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t("This message will not be shown").up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
|
|
|
|
2019-11-06 11:01:34 +01:00
|
|
|
expect(converse.env.log.info).toHaveBeenCalledWith(
|
|
|
|
"onMessage: Ignoring incoming message intended for a different resource: romeo@montague.lit/some-other-resource",
|
|
|
|
);
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(_converse.api.chatboxes.create).not.toHaveBeenCalled();
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.filter_by_resource = false;
|
|
|
|
|
|
|
|
const message = "This message sent to a different resource will be shown";
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.bare_jid+"/some-other-resource",
|
|
|
|
type: 'chat',
|
|
|
|
id: '134234623462346'
|
|
|
|
}).c('body').t(message).up()
|
2019-10-24 14:29:15 +02:00
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxviews.keys().length > 1, 1000);
|
2018-10-13 23:25:01 +02:00
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length);
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(_converse.api.chatboxes.create).toHaveBeenCalled();
|
2019-07-11 12:30:51 +02:00
|
|
|
const last_message = await u.waitUntil(() => sizzle('.chat-content:last .chat-msg__text', view.el).pop());
|
|
|
|
const msg_txt = last_message.textContent;
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
done();
|
2018-08-15 11:02:24 +02:00
|
|
|
}));
|
|
|
|
});
|
2018-04-30 12:15:26 +02:00
|
|
|
|
|
|
|
|
2018-07-30 18:16:32 +02:00
|
|
|
describe("which contains an OOB URL", function () {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
|
|
|
it("will render audio from oob mp3 URLs",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
let stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-02-12 14:21:45 +01:00
|
|
|
<body>Have you heard this funny audio?</body>
|
2019-06-03 07:58:51 +02:00
|
|
|
<x xmlns="jabber:x:oob"><url>https://montague.lit/audio.mp3</url></x>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`)
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-msg audio').length, 1000);
|
2018-10-13 23:25:01 +02:00
|
|
|
let msg = view.el.querySelector('.chat-msg .chat-msg__text');
|
2019-02-27 10:34:47 +01:00
|
|
|
expect(msg.classList.length).toEqual(1);
|
|
|
|
expect(u.hasClass('chat-msg__text', msg)).toBe(true);
|
|
|
|
expect(msg.textContent).toEqual('Have you heard this funny audio?');
|
2018-10-13 23:25:01 +02:00
|
|
|
let media = view.el.querySelector('.chat-msg .chat-msg__media');
|
|
|
|
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
|
|
|
|
'<!-- src/templates/audio.html -->'+
|
2019-06-03 07:58:51 +02:00
|
|
|
'<audio controls="" src="https://montague.lit/audio.mp3"></audio>'+
|
|
|
|
'<a target="_blank" rel="noopener" href="https://montague.lit/audio.mp3">Download audio file "audio.mp3"</a>');
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
// If the <url> and <body> contents is the same, don't duplicate.
|
2019-02-12 14:21:45 +01:00
|
|
|
stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
|
|
|
<body>https://montague.lit/audio.mp3</body>
|
|
|
|
<x xmlns="jabber:x:oob"><url>https://montague.lit/audio.mp3</url></x>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = view.el.querySelector('.chat-msg:last-child .chat-msg__text');
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg.innerHTML).toEqual('<!-- message gets added here via renderMessage -->'); // Emtpy
|
2019-06-19 11:04:09 +02:00
|
|
|
media = view.el.querySelector('.chat-msg:last-child .chat-msg__media');
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
|
|
|
|
'<!-- src/templates/audio.html -->'+
|
2019-06-03 07:58:51 +02:00
|
|
|
'<audio controls="" src="https://montague.lit/audio.mp3"></audio>'+
|
|
|
|
'<a target="_blank" rel="noopener" href="https://montague.lit/audio.mp3">Download audio file "audio.mp3"</a>'
|
2018-10-13 23:25:01 +02:00
|
|
|
);
|
|
|
|
done();
|
2018-04-29 15:40:24 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("will render video from oob mp4 URLs",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
let stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-02-12 14:21:45 +01:00
|
|
|
<body>Have you seen this funny video?</body>
|
2019-06-03 07:58:51 +02:00
|
|
|
<x xmlns="jabber:x:oob"><url>https://montague.lit/video.mp4</url></x>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-msg video').length, 2000)
|
2018-10-13 23:25:01 +02:00
|
|
|
let msg = view.el.querySelector('.chat-msg .chat-msg__text');
|
2019-02-27 10:34:47 +01:00
|
|
|
expect(msg.classList.length).toBe(1);
|
|
|
|
expect(msg.textContent).toEqual('Have you seen this funny video?');
|
2018-10-13 23:25:01 +02:00
|
|
|
let media = view.el.querySelector('.chat-msg .chat-msg__media');
|
|
|
|
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
|
|
|
|
'<!-- src/templates/video.html -->'+
|
2019-06-03 07:58:51 +02:00
|
|
|
'<video controls="" src="https://montague.lit/video.mp4" style="max-height: 50vh"></video>'+
|
|
|
|
'<a target="_blank" rel="noopener" href="https://montague.lit/video.mp4">Download video file "video.mp4"</a>');
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
// If the <url> and <body> contents is the same, don't duplicate.
|
2019-02-12 14:21:45 +01:00
|
|
|
stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
|
|
|
<body>https://montague.lit/video.mp4</body>
|
|
|
|
<x xmlns="jabber:x:oob"><url>https://montague.lit/video.mp4</url></x>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-06-19 11:04:09 +02:00
|
|
|
msg = view.el.querySelector('.chat-msg:last-child .chat-msg__text');
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(msg.innerHTML).toEqual('<!-- message gets added here via renderMessage -->'); // Emtpy
|
2019-06-19 11:04:09 +02:00
|
|
|
media = view.el.querySelector('.chat-msg:last-child .chat-msg__media');
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
|
|
|
|
'<!-- src/templates/video.html -->'+
|
2019-06-03 07:58:51 +02:00
|
|
|
'<video controls="" src="https://montague.lit/video.mp4" style="max-height: 50vh"></video>'+
|
|
|
|
'<a target="_blank" rel="noopener" href="https://montague.lit/video.mp4">Download video file "video.mp4"</a>');
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-04-29 15:40:24 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("will render download links for files from oob URLs",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
2019-02-12 14:21:45 +01:00
|
|
|
const stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-02-12 14:21:45 +01:00
|
|
|
<body>Have you downloaded this funny file?</body>
|
2019-06-03 07:58:51 +02:00
|
|
|
<x xmlns="jabber:x:oob"><url>https://montague.lit/funny.pdf</url></x>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`);
|
2018-10-13 23:25:01 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-msg a').length, 1000);
|
2018-10-13 23:25:01 +02:00
|
|
|
const msg = view.el.querySelector('.chat-msg .chat-msg__text');
|
2019-02-27 10:34:47 +01:00
|
|
|
expect(u.hasClass('chat-msg__text', msg)).toBe(true);
|
|
|
|
expect(msg.textContent).toEqual('Have you downloaded this funny file?');
|
2018-10-13 23:25:01 +02:00
|
|
|
const media = view.el.querySelector('.chat-msg .chat-msg__media');
|
|
|
|
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
|
|
|
|
'<!-- src/templates/file.html -->'+
|
2019-06-03 07:58:51 +02:00
|
|
|
'<a target="_blank" rel="noopener" href="https://montague.lit/funny.pdf">Download file "funny.pdf"</a>');
|
2018-10-13 23:25:01 +02:00
|
|
|
done();
|
2018-04-29 15:40:24 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("will render images from oob URLs",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-20 18:10:55 +01:00
|
|
|
async function (done, _converse) {
|
2018-04-29 15:40:24 +02:00
|
|
|
|
2018-11-18 15:56:14 +01:00
|
|
|
const base_url = 'https://conversejs.org';
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-20 18:10:55 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid)
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-11-20 18:10:55 +01:00
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
|
|
|
const url = base_url+"/logo/conversejs-filled.svg";
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
const stanza = u.toStanza(`
|
|
|
|
<message from="${contact_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-02-12 14:21:45 +01:00
|
|
|
<body>Have you seen this funny image?</body>
|
|
|
|
<x xmlns="jabber:x:oob"><url>${url}</url></x>
|
|
|
|
</message>`);
|
2018-11-20 18:10:55 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-msg img').length, 2000);
|
2018-11-20 18:10:55 +01:00
|
|
|
|
|
|
|
const msg = view.el.querySelector('.chat-msg .chat-msg__text');
|
2019-02-27 10:34:47 +01:00
|
|
|
expect(u.hasClass('chat-msg__text', msg)).toBe(true);
|
|
|
|
expect(msg.textContent).toEqual('Have you seen this funny image?');
|
2018-11-20 18:10:55 +01:00
|
|
|
const media = view.el.querySelector('.chat-msg .chat-msg__media');
|
|
|
|
expect(media.innerHTML.replace(/(\r\n|\n|\r)/gm, "")).toEqual(
|
|
|
|
`<!-- src/templates/image.html -->`+
|
|
|
|
`<a href="${base_url}/logo/conversejs-filled.svg" target="_blank" rel="noopener">`+
|
|
|
|
`<img class="chat-image img-thumbnail" src="${base_url}/logo/conversejs-filled.svg">`+
|
|
|
|
`</a>`);
|
|
|
|
done();
|
2018-04-29 15:40:24 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2018-07-07 14:20:49 +02:00
|
|
|
|
2019-01-31 19:22:30 +01:00
|
|
|
describe("A XEP-0333 Chat Marker", function () {
|
|
|
|
|
2019-02-13 19:31:05 +01:00
|
|
|
it("is sent when a markable message is received from a roster contact",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-01-31 19:22:30 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-01-31 19:22:30 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2019-01-31 19:22:30 +01:00
|
|
|
const msgid = u.getUniqueId();
|
2019-02-12 14:21:45 +01:00
|
|
|
const stanza = u.toStanza(`
|
2019-01-31 19:22:30 +01:00
|
|
|
<message from='${contact_jid}'
|
|
|
|
id='${msgid}'
|
|
|
|
type="chat"
|
|
|
|
to='${_converse.jid}'>
|
|
|
|
<body>My lord, dispatch; read o'er these articles.</body>
|
|
|
|
<markable xmlns='urn:xmpp:chat-markers:0'/>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`);
|
2019-01-31 19:22:30 +01:00
|
|
|
|
|
|
|
const sent_stanzas = [];
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(s => sent_stanzas.push(s));
|
|
|
|
spyOn(view.model, 'sendMarker').and.callThrough();
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.sendMarker.calls.count() === 1);
|
2019-01-31 19:22:30 +01:00
|
|
|
expect(Strophe.serialize(sent_stanzas[0])).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<message from="romeo@montague.lit/orchard" `+
|
2019-01-31 19:22:30 +01:00
|
|
|
`id="${sent_stanzas[0].nodeTree.getAttribute('id')}" `+
|
|
|
|
`to="${contact_jid}" type="chat" xmlns="jabber:client">`+
|
|
|
|
`<received id="${msgid}" xmlns="urn:xmpp:chat-markers:0"/>`+
|
|
|
|
`</message>`);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-02-13 19:31:05 +01:00
|
|
|
it("is not sent when a markable message is received from someone not on the roster",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {'allow_non_roster_messaging': true},
|
2019-02-13 19:31:05 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = 'someone@montague.lit';
|
2019-02-13 19:31:05 +01:00
|
|
|
const msgid = u.getUniqueId();
|
|
|
|
const stanza = u.toStanza(`
|
|
|
|
<message from='${contact_jid}'
|
|
|
|
id='${msgid}'
|
|
|
|
type="chat"
|
|
|
|
to='${_converse.jid}'>
|
|
|
|
<body>My lord, dispatch; read o'er these articles.</body>
|
|
|
|
<markable xmlns='urn:xmpp:chat-markers:0'/>
|
|
|
|
</message>`);
|
|
|
|
|
|
|
|
const sent_stanzas = [];
|
|
|
|
spyOn(_converse.connection, 'send').and.callFake(s => sent_stanzas.push(s));
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(stanza);
|
2019-02-13 19:31:05 +01:00
|
|
|
const sent_messages = sent_stanzas
|
|
|
|
.map(s => _.isElement(s) ? s : s.nodeTree)
|
|
|
|
.filter(e => e.nodeName === 'message');
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(sent_messages.length).toBe(0);
|
2019-02-13 19:31:05 +01:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-01-31 19:22:30 +01:00
|
|
|
it("is ignored if it's a carbon copy of one that I sent from a different client",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-01-31 19:22:30 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-02-14 13:43:24 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], [Strophe.NS.SID]);
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-01-31 19:22:30 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-02-22 21:43:49 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2019-01-31 19:22:30 +01:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
let stanza = u.toStanza(`
|
2019-01-31 19:22:30 +01:00
|
|
|
<message xmlns="jabber:client"
|
|
|
|
to="${_converse.bare_jid}"
|
|
|
|
type="chat"
|
|
|
|
id="2e972ea0-0050-44b7-a830-f6638a2595b3"
|
|
|
|
from="${contact_jid}">
|
|
|
|
<body>😊</body>
|
|
|
|
<markable xmlns="urn:xmpp:chat-markers:0"/>
|
|
|
|
<origin-id xmlns="urn:xmpp:sid:0" id="2e972ea0-0050-44b7-a830-f6638a2595b3"/>
|
|
|
|
<stanza-id xmlns="urn:xmpp:sid:0" id="IxVDLJ0RYbWcWvqC" by="${_converse.bare_jid}"/>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`);
|
2019-01-31 19:22:30 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-01-31 19:22:30 +01:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(view.model.messages.length).toBe(1);
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
stanza = u.toStanza(
|
2019-01-31 19:22:30 +01:00
|
|
|
`<message xmlns="jabber:client" to="${_converse.bare_jid}" type="chat" from="${contact_jid}">
|
|
|
|
<sent xmlns="urn:xmpp:carbons:2">
|
|
|
|
<forwarded xmlns="urn:xmpp:forward:0">
|
|
|
|
<message xmlns="jabber:client" to="${contact_jid}" type="chat" from="${_converse.bare_jid}/other-resource">
|
|
|
|
<received xmlns="urn:xmpp:chat-markers:0" id="2e972ea0-0050-44b7-a830-f6638a2595b3"/>
|
|
|
|
<store xmlns="urn:xmpp:hints"/>
|
2019-07-03 14:18:46 +02:00
|
|
|
<stanza-id xmlns="urn:xmpp:sid:0" id="F4TC6CvHwzqRbeHb" by="${_converse.bare_jid}"/>
|
2019-01-31 19:22:30 +01:00
|
|
|
</message>
|
|
|
|
</forwarded>
|
|
|
|
</sent>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`);
|
2019-03-29 21:10:45 +01:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2019-01-31 19:22:30 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.api.trigger.calls.count(), 500);
|
2019-01-31 19:22:30 +01:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
expect(view.model.messages.length).toBe(1);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
});
|
2018-04-29 15:40:24 +02:00
|
|
|
}));
|