2016-03-20 00:03:00 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2017-06-19 11:08:57 +02:00
|
|
|
"jasmine",
|
2016-03-20 00:03:00 +01:00
|
|
|
"mock",
|
2017-04-05 11:01:31 +02:00
|
|
|
"test-utils"
|
2016-03-28 12:49:52 +02:00
|
|
|
], factory);
|
2019-04-06 16:31:42 +02:00
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2016-03-20 00:03:00 +01:00
|
|
|
"use strict";
|
2019-10-24 14:29:15 +02:00
|
|
|
const $msg = converse.env.$msg,
|
|
|
|
_ = converse.env._,
|
|
|
|
u = converse.env.utils;
|
2016-03-20 00:03:00 +01:00
|
|
|
|
2016-04-07 15:09:20 +02:00
|
|
|
describe("A headlines box", function () {
|
2016-03-20 00:03:00 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
it("will not open nor display non-headline messages",
|
|
|
|
mock.initConverse(
|
2019-11-01 16:04:55 +01:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {}, function (done, _converse) {
|
2019-10-24 14:29:15 +02:00
|
|
|
|
2016-04-07 15:09:20 +02:00
|
|
|
/* XMPP spam message:
|
|
|
|
*
|
|
|
|
* <message xmlns="jabber:client"
|
2019-06-03 07:58:51 +02:00
|
|
|
* to="romeo@montague.lit"
|
2016-04-07 15:09:20 +02:00
|
|
|
* type="chat"
|
|
|
|
* from="gapowa20102106@rds-rostov.ru/Adium">
|
|
|
|
* <nick xmlns="http://jabber.org/protocol/nick">-wwdmz</nick>
|
|
|
|
* <body>SORRY FOR THIS ADVERT</body
|
|
|
|
* </message
|
|
|
|
*/
|
2019-10-24 14:29:15 +02:00
|
|
|
sinon.spy(u, 'isHeadlineMessage');
|
2019-05-29 13:00:45 +02:00
|
|
|
const stanza = $msg({
|
2017-04-05 11:01:31 +02:00
|
|
|
'xmlns': 'jabber:client',
|
2019-06-03 07:58:51 +02:00
|
|
|
'to': 'romeo@montague.lit',
|
2017-04-05 11:01:31 +02:00
|
|
|
'type': 'chat',
|
|
|
|
'from': 'gapowa20102106@rds-rostov.ru/Adium',
|
|
|
|
})
|
|
|
|
.c('nick', {'xmlns': "http://jabber.org/protocol/nick"}).t("-wwdmz").up()
|
|
|
|
.c('body').t('SORRY FOR THIS ADVERT');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(u.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(u.isHeadlineMessage.returned(false)).toBeTruthy();
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(_converse.api.headlines.get().length === 0);
|
2019-10-24 14:29:15 +02:00
|
|
|
u.isHeadlineMessage.restore();
|
2019-02-12 14:21:45 +01:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-04-07 15:09:20 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("will open and display headline messages", mock.initConverse(
|
2020-01-30 19:57:04 +01:00
|
|
|
['rosterGroupsFetched'], {}, async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2017-02-24 15:03:26 +01:00
|
|
|
/* <message from='notify.example.com'
|
2016-03-20 00:03:00 +01:00
|
|
|
* to='romeo@im.example.com'
|
|
|
|
* type='headline'
|
|
|
|
* xml:lang='en'>
|
|
|
|
* <subject>SIEVE</subject>
|
|
|
|
* <body><juliet@example.com> You got mail.</body>
|
|
|
|
* <x xmlns='jabber:x:oob'>
|
|
|
|
* <url>
|
|
|
|
* imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
|
|
|
|
* </url>
|
|
|
|
* </x>
|
|
|
|
* </message>
|
|
|
|
*/
|
2019-10-24 14:29:15 +02:00
|
|
|
sinon.spy(u, 'isHeadlineMessage');
|
2019-05-29 13:00:45 +02:00
|
|
|
const stanza = $msg({
|
2017-04-05 11:01:31 +02:00
|
|
|
'type': 'headline',
|
|
|
|
'from': 'notify.example.com',
|
2019-06-03 07:58:51 +02:00
|
|
|
'to': 'romeo@montague.lit',
|
2017-04-05 11:01:31 +02:00
|
|
|
'xml:lang': 'en'
|
|
|
|
})
|
|
|
|
.c('subject').t('SIEVE').up()
|
|
|
|
.c('body').t('<juliet@example.com> You got mail.').up()
|
|
|
|
.c('x', {'xmlns': 'jabber:x:oob'})
|
2018-04-27 13:47:44 +02:00
|
|
|
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2020-01-30 19:57:04 +01:00
|
|
|
await u.waitUntil(() => _converse.chatboxviews.keys().includes('notify.example.com'));
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(u.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(u.isHeadlineMessage.returned(true)).toBeTruthy();
|
|
|
|
u.isHeadlineMessage.restore(); // unwraps
|
2019-05-29 13:00:45 +02:00
|
|
|
const view = _converse.chatboxviews.get('notify.example.com');
|
2017-12-07 06:35:28 +01:00
|
|
|
expect(view.model.get('show_avatar')).toBeFalsy();
|
|
|
|
expect(view.el.querySelector('img.avatar')).toBe(null);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2017-02-24 15:03:26 +01:00
|
|
|
|
2020-01-22 09:22:38 +01:00
|
|
|
it("will show headline messages in the controlbox", mock.initConverse(
|
|
|
|
['rosterGroupsFetched'], {}, async function (done, _converse) {
|
|
|
|
|
|
|
|
/* <message from='notify.example.com'
|
|
|
|
* to='romeo@im.example.com'
|
|
|
|
* type='headline'
|
|
|
|
* xml:lang='en'>
|
|
|
|
* <subject>SIEVE</subject>
|
|
|
|
* <body><juliet@example.com> You got mail.</body>
|
|
|
|
* <x xmlns='jabber:x:oob'>
|
|
|
|
* <url>
|
|
|
|
* imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
|
|
|
|
* </url>
|
|
|
|
* </x>
|
|
|
|
* </message>
|
|
|
|
*/
|
|
|
|
const stanza = $msg({
|
|
|
|
'type': 'headline',
|
|
|
|
'from': 'notify.example.com',
|
|
|
|
'to': 'romeo@montague.lit',
|
|
|
|
'xml:lang': 'en'
|
|
|
|
})
|
|
|
|
.c('subject').t('SIEVE').up()
|
|
|
|
.c('body').t('<juliet@example.com> You got mail.').up()
|
|
|
|
.c('x', {'xmlns': 'jabber:x:oob'})
|
|
|
|
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
|
|
|
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
const view = _converse.chatboxviews.get('controlbox');
|
|
|
|
await u.waitUntil(() => view.el.querySelectorAll(".open-headline").length);
|
|
|
|
expect(view.el.querySelectorAll('.open-headline').length).toBe(1);
|
|
|
|
expect(view.el.querySelector('.open-headline').text).toBe('notify.example.com');
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("will remove headline messages from the controlbox if closed", mock.initConverse(
|
|
|
|
['rosterGroupsFetched'], {}, async function (done, _converse) {
|
|
|
|
|
2020-01-30 17:56:07 +01:00
|
|
|
await test_utils.openControlBox(_converse);
|
2020-01-22 09:22:38 +01:00
|
|
|
/* <message from='notify.example.com'
|
|
|
|
* to='romeo@im.example.com'
|
|
|
|
* type='headline'
|
|
|
|
* xml:lang='en'>
|
|
|
|
* <subject>SIEVE</subject>
|
|
|
|
* <body><juliet@example.com> You got mail.</body>
|
|
|
|
* <x xmlns='jabber:x:oob'>
|
|
|
|
* <url>
|
|
|
|
* imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
|
|
|
|
* </url>
|
|
|
|
* </x>
|
|
|
|
* </message>
|
|
|
|
*/
|
|
|
|
const stanza = $msg({
|
|
|
|
'type': 'headline',
|
|
|
|
'from': 'notify.example.com',
|
|
|
|
'to': 'romeo@montague.lit',
|
|
|
|
'xml:lang': 'en'
|
|
|
|
})
|
|
|
|
.c('subject').t('SIEVE').up()
|
|
|
|
.c('body').t('<juliet@example.com> You got mail.').up()
|
|
|
|
.c('x', {'xmlns': 'jabber:x:oob'})
|
|
|
|
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
|
|
|
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
await u.waitUntil(() => cbview.el.querySelectorAll(".open-headline").length);
|
|
|
|
const hlview = _converse.chatboxviews.get('notify.example.com');
|
2020-02-10 11:23:55 +01:00
|
|
|
await u.isVisible(hlview.el);
|
2020-04-06 17:21:38 +02:00
|
|
|
const close_el = await u.waitUntil(() => hlview.el.querySelector('.close-chatbox-button'));
|
2020-01-22 09:22:38 +01:00
|
|
|
close_el.click();
|
|
|
|
await u.waitUntil(() => cbview.el.querySelectorAll(".open-headline").length === 0);
|
|
|
|
expect(cbview.el.querySelectorAll('.open-headline').length).toBe(0);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will not show a headline messages from a full JID if allow_non_roster_messaging is false",
|
2019-10-24 14:29:15 +02:00
|
|
|
mock.initConverse(
|
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {}, function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2017-02-24 15:03:26 +01:00
|
|
|
_converse.allow_non_roster_messaging = false;
|
2019-10-24 14:29:15 +02:00
|
|
|
sinon.spy(u, 'isHeadlineMessage');
|
|
|
|
const stanza = $msg({
|
2017-04-05 11:01:31 +02:00
|
|
|
'type': 'headline',
|
|
|
|
'from': 'andre5114@jabber.snc.ru/Spark',
|
2019-06-03 07:58:51 +02:00
|
|
|
'to': 'romeo@montague.lit',
|
2017-04-05 11:01:31 +02:00
|
|
|
'xml:lang': 'en'
|
|
|
|
})
|
|
|
|
.c('nick').t('gpocy').up()
|
|
|
|
.c('body').t('Здравствуйте друзья');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(_.without('controlbox', _converse.chatboxviews.keys()).length).toBe(0);
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(u.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(u.isHeadlineMessage.returned(true)).toBeTruthy();
|
|
|
|
u.isHeadlineMessage.restore(); // unwraps
|
2019-02-12 14:21:45 +01:00
|
|
|
done();
|
2017-02-24 15:03:26 +01:00
|
|
|
}));
|
2016-03-20 00:03:00 +01:00
|
|
|
});
|
|
|
|
}));
|