var assert = require('assert'); add_dependencies({ _: 'third/underscore/underscore.js' }); set_global('page_params', { alert_words: ['alertone', 'alerttwo', 'alertthree', 'al*rt.*s', '.+'], email: 'tester@zulip.com' }); set_global('feature_flags', { alert_words: true }); var alert_words = require('js/alert_words.js'); var regular_message = { sender_email: 'another@zulip.com', content: '

a message

', flags: [] }; var own_message = { sender_email: 'tester@zulip.com', content: '

hey this message alertone

', flags: ['has_alert_word'] }; var other_message = { sender_email: 'another@zulip.com', content: '

another alertone message

', flags: ['has_alert_word'] }; var caps_message = { sender_email: 'another@zulip.com', content: '

another ALERTtwo message

', flags: ['has_alert_word'] }; var alertwordboundary_message = { sender_email: 'another@zulip.com', content: '

another alertthreemessage

', flags: [] }; var multialert_message = { sender_email: 'another@zulip.com', content: '

another alertthreemessage alertone and then alerttwo

', flags: ['has_alert_word'] }; var unsafe_word_message = { sender_email: 'another@zulip.com', content: '

gotta al*rt.*s all

', flags: ['has_alert_word'] }; var alert_in_url_message = { sender_email: 'another@zulip.com', content: '

http://www.google.com/alertone/me

', flags: ['has_alert_word'] }; var question_word_message = { sender_email: 'another@zulip.com', content: '

still alertone? me

', flags: ['has_alert_word'] }; (function test_notifications() { assert.equal(alert_words.notifies(regular_message), false); assert.equal(alert_words.notifies(own_message), false); assert.equal(alert_words.notifies(other_message), true); assert.equal(alert_words.notifies(caps_message), true); assert.equal(alert_words.notifies(alertwordboundary_message), false); assert.equal(alert_words.notifies(multialert_message), true); assert.equal(alert_words.notifies(unsafe_word_message), true); }()); (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, "

another alertone message

"); alert_words.process_message(caps_message); assert.equal(caps_message.content, "

another ALERTtwo message

"); alert_words.process_message(multialert_message); assert.equal(multialert_message.content, "

another alertthreemessage alertone and then alerttwo

"); alert_words.process_message(unsafe_word_message); assert.equal(unsafe_word_message.content, "

gotta al*rt.*s all

"); alert_words.process_message(alert_in_url_message); assert.equal(alert_in_url_message.content, "

http://www.google.com/alertone/me

"); alert_words.process_message(question_word_message); assert.equal(question_word_message.content, "

still alertone? me

"); }());