2018-02-02 19:33:19 +01:00
|
|
|
(function (root, factory) {
|
2018-06-03 16:40:20 +02:00
|
|
|
define(["jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2018-10-13 23:25:01 +02:00
|
|
|
const _ = converse.env._;
|
|
|
|
const Strophe = converse.env.Strophe;
|
|
|
|
const $msg = converse.env.$msg;
|
|
|
|
const $pres = converse.env.$pres;
|
|
|
|
const u = converse.env.utils;
|
2018-02-02 19:33:19 +01:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
describe("A spoiler message", function () {
|
2018-02-02 19:33:19 +01:00
|
|
|
|
2018-02-02 21:54:06 +01:00
|
|
|
it("can be received with a hint",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-02-12 14:21:45 +01:00
|
|
|
async (done, _converse) => {
|
2018-02-02 21:54:06 +01: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-02-02 21:54:06 +01:00
|
|
|
|
|
|
|
/* <message to='romeo@montague.net/orchard' from='juliet@capulet.net/balcony' id='spoiler2'>
|
|
|
|
* <body>And at the end of the story, both of them die! It is so tragic!</body>
|
|
|
|
* <spoiler xmlns='urn:xmpp:spoiler:0'>Love story end</spoiler>
|
|
|
|
* </message>
|
|
|
|
*/
|
2018-10-13 23:25:01 +02:00
|
|
|
const spoiler_hint = "Love story end"
|
|
|
|
const spoiler = "And at the end of the story, both of them die! It is so tragic!";
|
|
|
|
const msg = $msg({
|
2018-02-02 21:54:06 +01:00
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t(spoiler).up()
|
|
|
|
.c('spoiler', {
|
|
|
|
'xmlns': 'urn:xmpp:spoiler:0',
|
|
|
|
}).t(spoiler_hint)
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg));
|
2019-12-18 12:42:40 +01:00
|
|
|
await new Promise(resolve => _converse.api.listen.once('chatBoxViewInitialized', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
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.vcard.get('fullname') === 'Mercutio')
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(view.el.querySelector('.chat-msg__author').textContent.trim()).toBe('Mercutio');
|
2018-10-13 23:25:01 +02:00
|
|
|
const message_content = view.el.querySelector('.chat-msg__text');
|
|
|
|
expect(message_content.textContent).toBe(spoiler);
|
|
|
|
const spoiler_hint_el = view.el.querySelector('.spoiler-hint');
|
|
|
|
expect(spoiler_hint_el.textContent).toBe(spoiler_hint);
|
|
|
|
done();
|
2018-02-06 21:21:21 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be received without a hint",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-02-12 14:21:45 +01:00
|
|
|
async (done, _converse) => {
|
2018-02-06 21:21:21 +01: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-02-06 21:21:21 +01:00
|
|
|
/* <message to='romeo@montague.net/orchard' from='juliet@capulet.net/balcony' id='spoiler2'>
|
|
|
|
* <body>And at the end of the story, both of them die! It is so tragic!</body>
|
|
|
|
* <spoiler xmlns='urn:xmpp:spoiler:0'>Love story end</spoiler>
|
|
|
|
* </message>
|
|
|
|
*/
|
2018-10-13 23:25:01 +02:00
|
|
|
const spoiler = "And at the end of the story, both of them die! It is so tragic!";
|
|
|
|
const msg = $msg({
|
2018-02-06 21:21:21 +01:00
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t(spoiler).up()
|
|
|
|
.c('spoiler', {
|
|
|
|
'xmlns': 'urn:xmpp:spoiler:0',
|
|
|
|
}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg));
|
2019-12-18 12:42:40 +01:00
|
|
|
await new Promise(resolve => _converse.api.listen.once('chatBoxViewInitialized', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2020-02-02 15:38:37 +01:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2019-11-01 16:04:55 +01:00
|
|
|
await u.waitUntil(() => u.isVisible(view.el));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.vcard.get('fullname') === 'Mercutio')
|
2019-09-19 16:54:55 +02:00
|
|
|
expect(view.el.querySelector('.chat-msg__author').textContent.includes('Mercutio')).toBeTruthy();
|
2018-10-13 23:25:01 +02:00
|
|
|
const message_content = view.el.querySelector('.chat-msg__text');
|
|
|
|
expect(message_content.textContent).toBe(spoiler);
|
|
|
|
const spoiler_hint_el = view.el.querySelector('.spoiler-hint');
|
|
|
|
expect(spoiler_hint_el.textContent).toBe('');
|
|
|
|
done();
|
2018-02-02 21:54:06 +01:00
|
|
|
}));
|
|
|
|
|
2018-02-02 19:33:19 +01:00
|
|
|
it("can be sent without a hint",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-02-12 14:21:45 +01:00
|
|
|
async (done, _converse) => {
|
2018-02-02 19:33:19 +01:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-10-24 14:29:15 +02:00
|
|
|
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-02-02 19:33:19 +01:00
|
|
|
|
2018-02-08 17:06:53 +01:00
|
|
|
// XXX: We need to send a presence from the contact, so that we
|
|
|
|
// have a resource, that resource is then queried to see
|
|
|
|
// whether Strophe.NS.SPOILER is supported, in which case
|
|
|
|
// the spoiler button will appear.
|
2018-10-13 23:25:01 +02:00
|
|
|
const presence = $pres({
|
2018-02-08 17:06:53 +01:00
|
|
|
'from': contact_jid+'/phone',
|
2019-06-03 07:58:51 +02:00
|
|
|
'to': 'romeo@montague.lit'
|
2018-02-08 17:06:53 +01:00
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]);
|
2019-02-24 11:44:34 +01:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
|
2018-10-13 23:25:01 +02:00
|
|
|
let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
|
|
|
|
spoiler_toggle.click();
|
|
|
|
|
|
|
|
const textarea = view.el.querySelector('.chat-textarea');
|
|
|
|
textarea.value = 'This is the spoiler';
|
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
|
|
|
|
});
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2018-05-29 12:00:23 +02:00
|
|
|
/* Test the XML stanza
|
2018-10-13 23:25:01 +02:00
|
|
|
*
|
2019-06-03 07:58:51 +02:00
|
|
|
* <message from="romeo@montague.lit/orchard"
|
|
|
|
* to="max.frankfurter@montague.lit"
|
2018-10-13 23:25:01 +02:00
|
|
|
* type="chat"
|
|
|
|
* id="4547c38b-d98b-45a5-8f44-b4004dbc335e"
|
|
|
|
* xmlns="jabber:client">
|
|
|
|
* <body>This is the spoiler</body>
|
|
|
|
* <active xmlns="http://jabber.org/protocol/chatstates"/>
|
|
|
|
* <spoiler xmlns="urn:xmpp:spoiler:0"/>
|
|
|
|
* </message>"
|
|
|
|
*/
|
|
|
|
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
|
|
|
const spoiler_el = stanza.querySelector('spoiler[xmlns="urn:xmpp:spoiler:0"]');
|
2019-08-05 01:39:57 +02:00
|
|
|
expect(spoiler_el === null).toBeFalsy();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(spoiler_el.textContent).toBe('');
|
|
|
|
|
|
|
|
const body_el = stanza.querySelector('body');
|
|
|
|
expect(body_el.textContent).toBe('This is the spoiler');
|
|
|
|
|
|
|
|
/* Test the HTML spoiler message */
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(view.el.querySelector('.chat-msg__author').textContent.trim()).toBe('Romeo Montague');
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
const spoiler_msg_el = view.el.querySelector('.chat-msg__text.spoiler');
|
|
|
|
expect(spoiler_msg_el.textContent).toBe('This is the spoiler');
|
|
|
|
expect(_.includes(spoiler_msg_el.classList, 'collapsed')).toBeTruthy();
|
|
|
|
|
|
|
|
spoiler_toggle = view.el.querySelector('.spoiler-toggle');
|
|
|
|
expect(spoiler_toggle.textContent).toBe('Show more');
|
|
|
|
spoiler_toggle.click();
|
|
|
|
expect(_.includes(spoiler_msg_el.classList, 'collapsed')).toBeFalsy();
|
|
|
|
expect(spoiler_toggle.textContent).toBe('Show less');
|
|
|
|
spoiler_toggle.click();
|
|
|
|
expect(_.includes(spoiler_msg_el.classList, 'collapsed')).toBeTruthy();
|
|
|
|
done();
|
2018-02-02 19:33:19 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be sent with a hint",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-02-12 14:21:45 +01:00
|
|
|
async (done, _converse) => {
|
2018-02-02 19:33:19 +01:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-10-24 14:29:15 +02:00
|
|
|
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-02-02 19:33:19 +01:00
|
|
|
|
2018-02-08 17:06:53 +01:00
|
|
|
// XXX: We need to send a presence from the contact, so that we
|
|
|
|
// have a resource, that resource is then queried to see
|
|
|
|
// whether Strophe.NS.SPOILER is supported, in which case
|
|
|
|
// the spoiler button will appear.
|
2018-10-13 23:25:01 +02:00
|
|
|
const presence = $pres({
|
2018-02-08 17:06:53 +01:00
|
|
|
'from': contact_jid+'/phone',
|
2019-06-03 07:58:51 +02:00
|
|
|
'to': 'romeo@montague.lit'
|
2018-02-08 17:06:53 +01:00
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-10-13 23:25:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]);
|
2019-10-24 14:29:15 +02:00
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
2018-10-26 10:15:01 +02:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
|
2018-10-13 23:25:01 +02:00
|
|
|
let spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
|
|
|
|
spoiler_toggle.click();
|
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
|
|
|
|
const textarea = view.el.querySelector('.chat-textarea');
|
|
|
|
textarea.value = 'This is the spoiler';
|
|
|
|
const hint_input = view.el.querySelector('.spoiler-hint');
|
|
|
|
hint_input.value = 'This is the hint';
|
|
|
|
|
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
|
2018-02-06 21:21:21 +01:00
|
|
|
});
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
|
2018-05-29 12:00:23 +02:00
|
|
|
/* Test the XML stanza
|
2018-10-13 23:25:01 +02:00
|
|
|
*
|
2019-06-03 07:58:51 +02:00
|
|
|
* <message from="romeo@montague.lit/orchard"
|
|
|
|
* to="max.frankfurter@montague.lit"
|
2018-10-13 23:25:01 +02:00
|
|
|
* type="chat"
|
|
|
|
* id="4547c38b-d98b-45a5-8f44-b4004dbc335e"
|
|
|
|
* xmlns="jabber:client">
|
|
|
|
* <body>This is the spoiler</body>
|
|
|
|
* <active xmlns="http://jabber.org/protocol/chatstates"/>
|
|
|
|
* <spoiler xmlns="urn:xmpp:spoiler:0">This is the hint</spoiler>
|
|
|
|
* </message>"
|
|
|
|
*/
|
|
|
|
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
|
|
|
const spoiler_el = stanza.querySelector('spoiler[xmlns="urn:xmpp:spoiler:0"]');
|
|
|
|
|
2019-08-05 01:39:57 +02:00
|
|
|
expect(spoiler_el === null).toBeFalsy();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(spoiler_el.textContent).toBe('This is the hint');
|
|
|
|
|
|
|
|
const body_el = stanza.querySelector('body');
|
|
|
|
expect(body_el.textContent).toBe('This is the spoiler');
|
|
|
|
|
|
|
|
/* Test the HTML spoiler message */
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(view.el.querySelector('.chat-msg__author').textContent.trim()).toBe('Romeo Montague');
|
2018-10-13 23:25:01 +02:00
|
|
|
|
|
|
|
const spoiler_msg_el = view.el.querySelector('.chat-msg__text.spoiler');
|
|
|
|
expect(spoiler_msg_el.textContent).toBe('This is the spoiler');
|
|
|
|
expect(_.includes(spoiler_msg_el.classList, 'collapsed')).toBeTruthy();
|
|
|
|
|
|
|
|
spoiler_toggle = view.el.querySelector('.spoiler-toggle');
|
|
|
|
expect(spoiler_toggle.textContent).toBe('Show more');
|
|
|
|
spoiler_toggle.click();
|
|
|
|
expect(_.includes(spoiler_msg_el.classList, 'collapsed')).toBeFalsy();
|
|
|
|
expect(spoiler_toggle.textContent).toBe('Show less');
|
|
|
|
spoiler_toggle.click();
|
|
|
|
expect(_.includes(spoiler_msg_el.classList, 'collapsed')).toBeTruthy();
|
|
|
|
done();
|
2018-02-02 19:33:19 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
}));
|