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";
|
2016-12-20 10:30:20 +01:00
|
|
|
var $msg = converse.env.$msg,
|
2018-06-03 16:40:20 +02:00
|
|
|
_ = converse.env._,
|
|
|
|
utils = 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-02-12 14:21:45 +01:00
|
|
|
it("will not open nor display non-headline messages", mock.initConverse((done, _converse) => {
|
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
|
|
|
|
*/
|
|
|
|
sinon.spy(utils, '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));
|
|
|
|
expect(utils.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(utils.isHeadlineMessage.returned(false)).toBeTruthy();
|
|
|
|
utils.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(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {}, 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>
|
|
|
|
*/
|
2016-03-28 12:49:52 +02:00
|
|
|
sinon.spy(utils, '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));
|
|
|
|
expect(
|
|
|
|
_.includes(
|
|
|
|
_converse.chatboxviews.keys(),
|
|
|
|
'notify.example.com')
|
|
|
|
).toBeTruthy();
|
|
|
|
expect(utils.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
|
|
|
|
utils.isHeadlineMessage.restore(); // unwraps
|
2017-12-07 06:35:28 +01:00
|
|
|
// Headlines boxes don't show an avatar
|
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
|
|
|
|
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-02-12 14:21:45 +01:00
|
|
|
mock.initConverse((done, _converse) => {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2017-02-24 15:03:26 +01:00
|
|
|
_converse.allow_non_roster_messaging = false;
|
|
|
|
sinon.spy(utils, 'isHeadlineMessage');
|
2017-04-05 11:01:31 +02:00
|
|
|
var stanza = $msg({
|
|
|
|
'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);
|
|
|
|
expect(utils.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
|
|
|
|
utils.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
|
|
|
});
|
|
|
|
}));
|