2020-12-29 12:52:53 +01:00
|
|
|
/*global mock, converse, _ */
|
2016-03-20 00:03:00 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
describe("A headlines box", function () {
|
2016-03-20 00:03:00 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("will not open nor display non-headline messages",
|
2021-01-26 14:01:37 +01:00
|
|
|
mock.initConverse(['chatBoxesFetched'], {}, async function (done, _converse) {
|
2019-10-24 14:29:15 +02:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
await mock.waitForRoster(_converse, 'current', 0);
|
2020-04-24 17:33:32 +02:00
|
|
|
const { $msg } = converse.env;
|
2020-04-22 13:11:48 +02:00
|
|
|
/* XMPP spam message:
|
|
|
|
*
|
|
|
|
* <message xmlns="jabber:client"
|
|
|
|
* to="romeo@montague.lit"
|
|
|
|
* type="chat"
|
|
|
|
* from="gapowa20102106@rds-rostov.ru/Adium">
|
|
|
|
* <nick xmlns="http://jabber.org/protocol/nick">-wwdmz</nick>
|
|
|
|
* <body>SORRY FOR THIS ADVERT</body
|
|
|
|
* </message
|
|
|
|
*/
|
|
|
|
const stanza = $msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'to': 'romeo@montague.lit',
|
|
|
|
'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(mock.createRequest(stanza));
|
|
|
|
expect(_converse.api.headlines.get().length === 0);
|
|
|
|
done();
|
|
|
|
}));
|
2016-04-07 15:09:20 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("will open and display headline messages", mock.initConverse(
|
2021-01-26 14:01:37 +01:00
|
|
|
[], {}, async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
await mock.waitForRoster(_converse, 'current', 0);
|
2020-04-22 13:11:48 +02:00
|
|
|
const { u, $msg} = converse.env;
|
|
|
|
/* <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');
|
2018-04-27 13:47:44 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
await u.waitUntil(() => _converse.chatboxviews.keys().includes('notify.example.com'));
|
|
|
|
const view = _converse.chatboxviews.get('notify.example.com');
|
|
|
|
expect(view.model.get('show_avatar')).toBeFalsy();
|
2020-12-08 12:54:14 +01:00
|
|
|
expect(view.querySelector('img.avatar')).toBe(null);
|
2020-04-22 13:11:48 +02:00
|
|
|
done();
|
|
|
|
}));
|
2017-02-24 15:03:26 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("will show headline messages in the controlbox", mock.initConverse(
|
2021-01-26 14:01:37 +01:00
|
|
|
[], {}, async function (done, _converse) {
|
2020-01-22 09:22:38 +01:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
await mock.waitForRoster(_converse, 'current', 0);
|
2020-04-22 13:11:48 +02:00
|
|
|
const { u, $msg} = converse.env;
|
|
|
|
/* <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');
|
2020-01-22 09:22:38 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
const view = _converse.chatboxviews.get('controlbox');
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => view.querySelectorAll(".open-headline").length);
|
|
|
|
expect(view.querySelectorAll('.open-headline').length).toBe(1);
|
|
|
|
expect(view.querySelector('.open-headline').text).toBe('notify.example.com');
|
2020-04-22 13:11:48 +02:00
|
|
|
done();
|
|
|
|
}));
|
2020-01-22 09:22:38 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("will remove headline messages from the controlbox if closed", mock.initConverse(
|
2021-01-26 14:01:37 +01:00
|
|
|
[], {}, async function (done, _converse) {
|
2020-01-22 09:22:38 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
const { u, $msg} = converse.env;
|
2021-01-26 14:01:37 +01:00
|
|
|
await mock.waitForRoster(_converse, 'current', 0);
|
2020-04-22 13:11:48 +02:00
|
|
|
await mock.openControlBox(_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');
|
2020-01-22 09:22:38 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => cbview.querySelectorAll(".open-headline").length);
|
2020-04-22 13:11:48 +02:00
|
|
|
const hlview = _converse.chatboxviews.get('notify.example.com');
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.isVisible(hlview);
|
|
|
|
const close_el = await u.waitUntil(() => hlview.querySelector('.close-chatbox-button'));
|
2020-04-22 13:11:48 +02:00
|
|
|
close_el.click();
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => cbview.querySelectorAll(".open-headline").length === 0);
|
|
|
|
expect(cbview.querySelectorAll('.open-headline').length).toBe(0);
|
2020-04-22 13:11:48 +02:00
|
|
|
done();
|
|
|
|
}));
|
2020-01-22 09:22:38 +01:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("will not show a headline messages from a full JID if allow_non_roster_messaging is false",
|
|
|
|
mock.initConverse(
|
2021-01-26 14:01:37 +01:00
|
|
|
['chatBoxesFetched'], {}, async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2021-01-26 14:01:37 +01:00
|
|
|
await mock.waitForRoster(_converse, 'current', 0);
|
2020-12-29 12:52:53 +01:00
|
|
|
const { $msg } = converse.env;
|
2020-04-22 13:11:48 +02:00
|
|
|
_converse.allow_non_roster_messaging = false;
|
|
|
|
const stanza = $msg({
|
|
|
|
'type': 'headline',
|
|
|
|
'from': 'andre5114@jabber.snc.ru/Spark',
|
|
|
|
'to': 'romeo@montague.lit',
|
|
|
|
'xml:lang': 'en'
|
|
|
|
})
|
|
|
|
.c('nick').t('gpocy').up()
|
|
|
|
.c('body').t('Здравствуйте друзья');
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(stanza));
|
|
|
|
expect(_.without('controlbox', _converse.chatboxviews.keys()).length).toBe(0);
|
|
|
|
done();
|
|
|
|
}));
|
2020-04-22 12:10:39 +02:00
|
|
|
});
|