2020-09-26 21:42:57 +02:00
|
|
|
/* global mock, converse */
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-05-15 14:33:31 +02:00
|
|
|
const original_timeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
describe("A spoiler message", function () {
|
|
|
|
|
2020-05-15 14:33:31 +02:00
|
|
|
beforeEach(() => (jasmine.DEFAULT_TIMEOUT_INTERVAL = 7000));
|
|
|
|
afterEach(() => (jasmine.DEFAULT_TIMEOUT_INTERVAL = original_timeout));
|
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("can be received with a hint",
|
2021-01-26 14:01:37 +01:00
|
|
|
mock.initConverse(['chatBoxesFetched'], {}, async (done, _converse) => {
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
await mock.waitForRoster(_converse, 'current');
|
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
|
|
|
|
/* <message to='romeo@montague.net/orchard' from='juliet@capulet.net/balcony' id='spoiler2'>
|
2020-06-08 12:12:49 +02:00
|
|
|
* <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>
|
|
|
|
*/
|
2020-04-22 13:11:48 +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 = converse.env.$msg;
|
|
|
|
const u = converse.env.utils;
|
|
|
|
const msg = $msg({
|
|
|
|
'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();
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(msg));
|
|
|
|
await new Promise(resolve => _converse.api.listen.once('chatBoxViewInitialized', resolve));
|
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2020-05-15 14:33:31 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => view.model.vcard.get('fullname') === 'Mercutio')
|
2020-12-08 12:54:14 +01:00
|
|
|
expect(view.querySelector('.chat-msg__author').textContent.trim()).toBe('Mercutio');
|
|
|
|
const message_content = view.querySelector('.chat-msg__text');
|
2020-05-15 14:33:31 +02:00
|
|
|
await u.waitUntil(() => message_content.textContent === spoiler);
|
2020-12-08 12:54:14 +01:00
|
|
|
const spoiler_hint_el = view.querySelector('.spoiler-hint');
|
2020-04-22 13:11:48 +02:00
|
|
|
expect(spoiler_hint_el.textContent).toBe(spoiler_hint);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be received without a hint",
|
2021-01-26 14:01:37 +01:00
|
|
|
mock.initConverse(['chatBoxesFetched'], {}, async (done, _converse) => {
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
await mock.waitForRoster(_converse, 'current');
|
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
/* <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>
|
|
|
|
*/
|
|
|
|
const $msg = converse.env.$msg;
|
|
|
|
const u = converse.env.utils;
|
|
|
|
const spoiler = "And at the end of the story, both of them die! It is so tragic!";
|
|
|
|
const msg = $msg({
|
|
|
|
'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();
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(msg));
|
|
|
|
await new Promise(resolve => _converse.api.listen.once('chatBoxViewInitialized', resolve));
|
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => u.isVisible(view));
|
2020-04-22 13:11:48 +02:00
|
|
|
await u.waitUntil(() => view.model.vcard.get('fullname') === 'Mercutio')
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => u.isVisible(view.querySelector('.chat-msg__author')));
|
|
|
|
expect(view.querySelector('.chat-msg__author').textContent.includes('Mercutio')).toBeTruthy();
|
|
|
|
const message_content = view.querySelector('.chat-msg__text');
|
2020-05-15 14:33:31 +02:00
|
|
|
await u.waitUntil(() => message_content.textContent === spoiler);
|
2020-12-08 12:54:14 +01:00
|
|
|
const spoiler_hint_el = view.querySelector('.spoiler-hint');
|
2020-04-22 13:11:48 +02:00
|
|
|
expect(spoiler_hint_el.textContent).toBe('');
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be sent without a hint",
|
2021-01-26 14:01:37 +01:00
|
|
|
mock.initConverse(['chatBoxesFetched'], {}, async (done, _converse) => {
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
await mock.waitForRoster(_converse, 'current', 1);
|
|
|
|
mock.openControlBox(_converse);
|
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
|
|
|
|
const { $pres, Strophe} = converse.env;
|
|
|
|
const u = converse.env.utils;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
const presence = $pres({
|
|
|
|
'from': contact_jid+'/phone',
|
|
|
|
'to': 'romeo@montague.lit'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(presence));
|
|
|
|
await mock.openChatBoxFor(_converse, contact_jid);
|
|
|
|
await mock.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]);
|
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => view.querySelector('.toggle-compose-spoiler'));
|
|
|
|
let spoiler_toggle = view.querySelector('.toggle-compose-spoiler');
|
2020-04-22 13:11:48 +02:00
|
|
|
spoiler_toggle.click();
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
const textarea = view.querySelector('.chat-textarea');
|
2020-04-22 13:11:48 +02:00
|
|
|
textarea.value = 'This is the spoiler';
|
|
|
|
view.onKeyDown({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: function preventDefault () {},
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2020-05-15 14:33:31 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
/* Test the XML stanza
|
2020-06-26 15:47:32 +02:00
|
|
|
*
|
|
|
|
* <message from="romeo@montague.lit/orchard"
|
|
|
|
* to="max.frankfurter@montague.lit"
|
|
|
|
* 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>"
|
|
|
|
*/
|
2020-04-22 13:11:48 +02:00
|
|
|
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
|
|
|
const spoiler_el = stanza.querySelector('spoiler[xmlns="urn:xmpp:spoiler:0"]');
|
|
|
|
expect(spoiler_el === null).toBeFalsy();
|
|
|
|
expect(spoiler_el.textContent).toBe('');
|
|
|
|
|
2020-05-15 14:33:31 +02:00
|
|
|
const spoiler = 'This is the spoiler';
|
2020-04-22 13:11:48 +02:00
|
|
|
const body_el = stanza.querySelector('body');
|
2020-05-15 14:33:31 +02:00
|
|
|
expect(body_el.textContent).toBe(spoiler);
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
/* Test the HTML spoiler message */
|
2020-12-08 12:54:14 +01:00
|
|
|
expect(view.querySelector('.chat-msg__author').textContent.trim()).toBe('Romeo Montague');
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
const message_content = view.querySelector('.chat-msg__text');
|
2020-05-15 14:33:31 +02:00
|
|
|
await u.waitUntil(() => message_content.textContent === spoiler);
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
const spoiler_msg_el = view.querySelector('.chat-msg__text.spoiler');
|
2020-07-08 10:22:20 +02:00
|
|
|
expect(Array.from(spoiler_msg_el.classList).includes('hidden')).toBeTruthy();
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
spoiler_toggle = view.querySelector('.spoiler-toggle');
|
2020-05-15 14:33:31 +02:00
|
|
|
expect(spoiler_toggle.textContent.trim()).toBe('Show more');
|
2020-04-22 13:11:48 +02:00
|
|
|
spoiler_toggle.click();
|
2020-07-08 10:22:20 +02:00
|
|
|
await u.waitUntil(() => !Array.from(spoiler_msg_el.classList).includes('hidden'));
|
2020-05-15 14:33:31 +02:00
|
|
|
expect(spoiler_toggle.textContent.trim()).toBe('Show less');
|
2020-04-22 13:11:48 +02:00
|
|
|
spoiler_toggle.click();
|
2020-07-08 10:22:20 +02:00
|
|
|
await u.waitUntil(() => Array.from(spoiler_msg_el.classList).includes('hidden'));
|
2020-04-22 13:11:48 +02:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be sent with a hint",
|
2021-01-26 14:01:37 +01:00
|
|
|
mock.initConverse(['chatBoxesFetched'], {}, async (done, _converse) => {
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
await mock.waitForRoster(_converse, 'current', 1);
|
|
|
|
mock.openControlBox(_converse);
|
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
|
|
|
|
const { $pres, Strophe} = converse.env;
|
|
|
|
const u = converse.env.utils;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
const presence = $pres({
|
|
|
|
'from': contact_jid+'/phone',
|
|
|
|
'to': 'romeo@montague.lit'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(presence));
|
|
|
|
await mock.openChatBoxFor(_converse, contact_jid);
|
|
|
|
await mock.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]);
|
|
|
|
const view = _converse.api.chatviews.get(contact_jid);
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => view.querySelector('.toggle-compose-spoiler'));
|
|
|
|
let spoiler_toggle = view.querySelector('.toggle-compose-spoiler');
|
2020-04-22 13:11:48 +02:00
|
|
|
spoiler_toggle.click();
|
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
const textarea = view.querySelector('.chat-textarea');
|
2020-04-22 13:11:48 +02:00
|
|
|
textarea.value = 'This is the spoiler';
|
2020-12-08 12:54:14 +01:00
|
|
|
const hint_input = view.querySelector('.spoiler-hint');
|
2020-04-22 13:11:48 +02:00
|
|
|
hint_input.value = 'This is the hint';
|
|
|
|
|
|
|
|
view.onKeyDown({
|
|
|
|
target: textarea,
|
|
|
|
preventDefault: function preventDefault () {},
|
|
|
|
keyCode: 13
|
|
|
|
});
|
2020-05-15 14:33:31 +02:00
|
|
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
2020-06-28 02:43:35 +02:00
|
|
|
expect(Strophe.serialize(stanza)).toBe(
|
|
|
|
`<message from="romeo@montague.lit/orchard" ` +
|
|
|
|
`id="${stanza.getAttribute('id')}" `+
|
|
|
|
`to="mercutio@montague.lit" `+
|
|
|
|
`type="chat" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>This is the spoiler</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<request xmlns="urn:xmpp:receipts"/>`+
|
|
|
|
`<spoiler xmlns="urn:xmpp:spoiler:0">This is the hint</spoiler>`+
|
|
|
|
`<origin-id id="${stanza.querySelector('origin-id').getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>`+
|
|
|
|
`</message>`
|
|
|
|
);
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-06-08 12:12:49 +02:00
|
|
|
await u.waitUntil(() => stanza.querySelector('spoiler[xmlns="urn:xmpp:spoiler:0"]')?.textContent === 'This is the hint');
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-05-15 14:33:31 +02:00
|
|
|
const spoiler = 'This is the spoiler'
|
2020-04-22 13:11:48 +02:00
|
|
|
const body_el = stanza.querySelector('body');
|
2020-05-15 14:33:31 +02:00
|
|
|
expect(body_el.textContent).toBe(spoiler);
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
expect(view.querySelector('.chat-msg__author').textContent.trim()).toBe('Romeo Montague');
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
const message_content = view.querySelector('.chat-msg__text');
|
2020-05-15 14:33:31 +02:00
|
|
|
await u.waitUntil(() => message_content.textContent === spoiler);
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
const spoiler_msg_el = view.querySelector('.chat-msg__text.spoiler');
|
2020-07-08 10:22:20 +02:00
|
|
|
expect(Array.from(spoiler_msg_el.classList).includes('hidden')).toBeTruthy();
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
spoiler_toggle = view.querySelector('.spoiler-toggle');
|
2020-05-15 14:33:31 +02:00
|
|
|
expect(spoiler_toggle.textContent.trim()).toBe('Show more');
|
2020-04-22 13:11:48 +02:00
|
|
|
spoiler_toggle.click();
|
2020-07-08 10:22:20 +02:00
|
|
|
await u.waitUntil(() => !Array.from(spoiler_msg_el.classList).includes('hidden'));
|
2020-05-15 14:33:31 +02:00
|
|
|
expect(spoiler_toggle.textContent.trim()).toBe('Show less');
|
2020-04-22 13:11:48 +02:00
|
|
|
spoiler_toggle.click();
|
2020-07-08 10:22:20 +02:00
|
|
|
await u.waitUntil(() => Array.from(spoiler_msg_el.classList).includes('hidden'));
|
2020-04-22 13:11:48 +02:00
|
|
|
done();
|
|
|
|
}));
|
2020-04-22 12:10:39 +02:00
|
|
|
});
|