2016-03-20 00:03:00 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
|
|
|
"jquery",
|
2016-03-28 12:49:52 +02:00
|
|
|
"utils",
|
2016-03-20 00:03:00 +01:00
|
|
|
"mock",
|
|
|
|
"test_utils"
|
2016-03-28 12:49:52 +02:00
|
|
|
], factory);
|
|
|
|
} (this, function ($, utils, mock, test_utils) {
|
2016-03-20 00:03:00 +01:00
|
|
|
"use strict";
|
|
|
|
var $msg = converse_api.env.$msg,
|
|
|
|
_ = converse_api.env._;
|
|
|
|
|
2016-04-07 15:09:20 +02:00
|
|
|
describe("A headlines box", function () {
|
2016-03-20 00:03:00 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
afterEach(function () {
|
|
|
|
converse_api.user.logout();
|
|
|
|
test_utils.clearBrowserStorage();
|
2016-04-13 17:11:04 +02:00
|
|
|
});
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
it("will not open nor display non-headline messages", mock.initConverse(function (converse) {
|
2016-04-07 15:09:20 +02:00
|
|
|
/* XMPP spam message:
|
|
|
|
*
|
|
|
|
* <message xmlns="jabber:client"
|
|
|
|
* to="dummy@localhost"
|
|
|
|
* type="chat"
|
|
|
|
* from="gapowa20102106@rds-rostov.ru/Adium">
|
|
|
|
* <nick xmlns="http://jabber.org/protocol/nick">-wwdmz</nick>
|
|
|
|
* <body>SORRY FOR THIS ADVERT</body
|
|
|
|
* </message
|
|
|
|
*/
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
|
|
|
test_utils.openContactsPanel(converse);
|
2016-04-07 15:09:20 +02:00
|
|
|
sinon.spy(utils, 'isHeadlineMessage');
|
|
|
|
runs(function () {
|
|
|
|
var stanza = $msg({
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'to': 'dummy@localhost',
|
|
|
|
'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));
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(utils.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(utils.isHeadlineMessage.returned(false)).toBeTruthy();
|
|
|
|
utils.isHeadlineMessage.restore();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-04-07 15:09:20 +02:00
|
|
|
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
it("will open and display headline messages", mock.initConverse(function (converse) {
|
2016-03-20 00:03:00 +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>
|
|
|
|
*/
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
|
|
|
test_utils.openContactsPanel(converse);
|
2016-03-28 12:49:52 +02:00
|
|
|
sinon.spy(utils, 'isHeadlineMessage');
|
2016-03-20 00:03:00 +01:00
|
|
|
runs(function () {
|
|
|
|
var stanza = $msg({
|
|
|
|
'type': 'headline',
|
|
|
|
'from': 'notify.example.com',
|
|
|
|
'to': 'dummy@localhost',
|
|
|
|
'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));
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(
|
|
|
|
_.contains(
|
|
|
|
converse.chatboxviews.keys(),
|
|
|
|
'notify.example.com')
|
|
|
|
).toBeTruthy();
|
2016-03-28 12:49:52 +02:00
|
|
|
expect(utils.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
|
|
|
|
utils.isHeadlineMessage.restore(); // unwraps
|
2016-03-20 00:03:00 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-03-20 00:03:00 +01:00
|
|
|
});
|
|
|
|
}));
|