xmpp.chapril.org-conversejs/spec/headline.js

186 lines
8.0 KiB
JavaScript
Raw Normal View History

2016-03-20 00:03:00 +01:00
(function (root, factory) {
define([
"jasmine",
2016-03-20 00:03:00 +01:00
"mock",
2017-04-05 11:01:31 +02:00
"test-utils"
], 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";
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
it("will not open nor display non-headline messages",
mock.initConverse(
['rosterGroupsFetched', 'chatBoxesFetched'], {}, function (done, _converse) {
2016-04-07 15:09:20 +02:00
/* XMPP spam message:
*
* <message xmlns="jabber:client"
* 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(u, 'isHeadlineMessage');
const stanza = $msg({
2017-04-05 11:01:31 +02:00
'xmlns': 'jabber:client',
'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(u.isHeadlineMessage.called).toBeTruthy();
expect(u.isHeadlineMessage.returned(false)).toBeTruthy();
expect(_converse.api.headlines.get().length === 0);
u.isHeadlineMessage.restore();
done();
}));
2016-04-07 15:09:20 +02:00
it("will open and display headline messages", mock.initConverse(
['rosterGroupsFetched'], {}, function (done, _converse) {
/* <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>&lt;juliet@example.com&gt; You got mail.</body>
* <x xmlns='jabber:x:oob'>
* <url>
* imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
* </url>
* </x>
* </message>
*/
sinon.spy(u, 'isHeadlineMessage');
const stanza = $msg({
2017-04-05 11:01:31 +02:00
'type': 'headline',
'from': 'notify.example.com',
'to': 'romeo@montague.lit',
2017-04-05 11:01:31 +02:00
'xml:lang': 'en'
})
.c('subject').t('SIEVE').up()
.c('body').t('&lt;juliet@example.com&gt; You got mail.').up()
.c('x', {'xmlns': 'jabber:x:oob'})
.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(u.isHeadlineMessage.called).toBeTruthy();
expect(u.isHeadlineMessage.returned(true)).toBeTruthy();
u.isHeadlineMessage.restore(); // unwraps
// Headlines boxes don't show an avatar
const view = _converse.chatboxviews.get('notify.example.com');
expect(view.model.get('show_avatar')).toBeFalsy();
expect(view.el.querySelector('img.avatar')).toBe(null);
done();
}));
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>&lt;juliet@example.com&gt; 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('&lt;juliet@example.com&gt; 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) {
/* <message from='notify.example.com'
* to='romeo@im.example.com'
* type='headline'
* xml:lang='en'>
* <subject>SIEVE</subject>
* <body>&lt;juliet@example.com&gt; 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('&lt;juliet@example.com&gt; 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');
const close_el = hlview.el.querySelector('.close-chatbox-button');
close_el.click();
await u.waitUntil(() => cbview.el.querySelectorAll(".open-headline").length === 0);
expect(cbview.el.querySelectorAll('.open-headline').length).toBe(0);
done();
}));
it("will not show a headline messages from a full JID if allow_non_roster_messaging is false",
mock.initConverse(
['rosterGroupsFetched', 'chatBoxesFetched'], {}, function (done, _converse) {
_converse.allow_non_roster_messaging = false;
sinon.spy(u, 'isHeadlineMessage');
const stanza = $msg({
2017-04-05 11:01:31 +02:00
'type': 'headline',
'from': 'andre5114@jabber.snc.ru/Spark',
'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(u.isHeadlineMessage.called).toBeTruthy();
expect(u.isHeadlineMessage.returned(true)).toBeTruthy();
u.isHeadlineMessage.restore(); // unwraps
done();
}));
2016-03-20 00:03:00 +01:00
});
}));