2016-06-08 05:54:07 +02:00
add _dependencies ( {
2016-12-03 23:17:57 +01:00
util : 'js/util.js' ,
2016-06-08 05:54:07 +02:00
} ) ;
2013-08-29 21:33:26 +02:00
set _global ( 'page_params' , {
alert _words : [ 'alertone' , 'alerttwo' , 'alertthree' , 'al*rt.*s' , '.+' ] ,
2016-12-03 23:17:57 +01:00
email : 'tester@zulip.com' ,
2013-08-29 21:33:26 +02:00
} ) ;
2013-09-03 15:16:00 +02:00
set _global ( 'feature_flags' , {
2016-12-03 23:17:57 +01:00
alert _words : true ,
2013-09-03 15:16:00 +02:00
} ) ;
2013-08-29 21:33:26 +02:00
var alert _words = require ( 'js/alert_words.js' ) ;
2014-01-08 00:04:52 +01:00
var regular _message = { sender _email : 'another@zulip.com' , content : '<p>a message</p>' } ;
2013-08-29 21:33:26 +02:00
var own _message = { sender _email : 'tester@zulip.com' , content : '<p>hey this message alertone</p>' ,
2014-01-08 00:04:52 +01:00
alerted : true } ;
2013-08-29 21:33:26 +02:00
var other _message = { sender _email : 'another@zulip.com' , content : '<p>another alertone message</p>' ,
2014-01-08 00:04:52 +01:00
alerted : true } ;
2013-08-29 21:33:26 +02:00
var caps _message = { sender _email : 'another@zulip.com' , content : '<p>another ALERTtwo message</p>' ,
2014-01-08 00:04:52 +01:00
alerted : true } ;
2013-08-29 21:33:26 +02:00
var alertwordboundary _message = { sender _email : 'another@zulip.com' ,
2014-01-08 00:04:52 +01:00
content : '<p>another alertthreemessage</p>' , alerted : false } ;
2013-08-29 21:33:26 +02:00
var multialert _message = { sender _email : 'another@zulip.com' , content :
'<p>another alertthreemessage alertone and then alerttwo</p>' ,
2014-01-08 00:04:52 +01:00
alerted : true } ;
2013-08-29 21:33:26 +02:00
var unsafe _word _message = { sender _email : 'another@zulip.com' , content : '<p>gotta al*rt.*s all</p>' ,
2014-01-08 00:04:52 +01:00
alerted : true } ;
2013-10-09 20:09:48 +02:00
var alert _in _url _message = { sender _email : 'another@zulip.com' , content : '<p>http://www.google.com/alertone/me</p>' ,
2014-01-08 00:04:52 +01:00
alerted : true } ;
2013-10-09 20:09:48 +02:00
var question _word _message = { sender _email : 'another@zulip.com' , content : '<p>still alertone? me</p>' ,
2014-01-08 00:04:52 +01:00
alerted : true } ;
2013-08-29 21:33:26 +02:00
2014-03-04 22:55:36 +01:00
var alert _domain _message = { sender _email : 'another@zulip.com' , content : '<p>now with link <a href="http://www.alerttwo.us/foo/bar" target="_blank" title="http://www.alerttwo.us/foo/bar">www.alerttwo.us/foo/bar</a></p>' ,
alerted : true } ;
2013-08-29 21:33:26 +02:00
( function test _notifications ( ) {
2014-01-08 00:04:52 +01:00
assert ( ! alert _words . notifies ( regular _message ) ) ;
assert ( ! alert _words . notifies ( own _message ) ) ;
assert ( alert _words . notifies ( other _message ) ) ;
assert ( alert _words . notifies ( caps _message ) ) ;
assert ( ! alert _words . notifies ( alertwordboundary _message ) ) ;
assert ( alert _words . notifies ( multialert _message ) ) ;
assert ( alert _words . notifies ( unsafe _word _message ) ) ;
2014-03-04 22:55:36 +01:00
assert ( alert _words . notifies ( alert _domain _message ) ) ;
2013-08-29 21:33:26 +02:00
} ( ) ) ;
( function test _munging ( ) {
var saved _content = regular _message . content ;
alert _words . process _message ( regular _message ) ;
assert . equal ( saved _content , regular _message . content ) ;
saved _content = alertwordboundary _message . content ;
alert _words . process _message ( alertwordboundary _message ) ;
assert . equal ( alertwordboundary _message . content , saved _content ) ;
alert _words . process _message ( other _message ) ;
assert . equal ( other _message . content , "<p>another <span class='alert-word'>alertone</span> message</p>" ) ;
alert _words . process _message ( caps _message ) ;
assert . equal ( caps _message . content , "<p>another <span class='alert-word'>ALERTtwo</span> message</p>" ) ;
alert _words . process _message ( multialert _message ) ;
assert . equal ( multialert _message . content , "<p>another alertthreemessage <span class='alert-word'>alertone</span> and then <span class='alert-word'>alerttwo</span></p>" ) ;
alert _words . process _message ( unsafe _word _message ) ;
assert . equal ( unsafe _word _message . content , "<p>gotta <span class='alert-word'>al*rt.*s</span> all</p>" ) ;
2013-10-09 20:09:48 +02:00
alert _words . process _message ( alert _in _url _message ) ;
assert . equal ( alert _in _url _message . content , "<p>http://www.google.com/alertone/me</p>" ) ;
alert _words . process _message ( question _word _message ) ;
assert . equal ( question _word _message . content , "<p>still <span class='alert-word'>alertone</span>? me</p>" ) ;
2014-03-04 22:55:36 +01:00
alert _words . process _message ( alert _domain _message ) ;
2014-03-04 23:51:49 +01:00
assert . equal ( alert _domain _message . content , '<p>now with link <a href="http://www.alerttwo.us/foo/bar" target="_blank" title="http://www.alerttwo.us/foo/bar">www.<span class=\'alert-word\'>alerttwo</span>.us/foo/bar</a></p>' ) ;
2014-01-08 00:04:52 +01:00
} ( ) ) ;