2017-03-13 23:02:03 +01:00
|
|
|
set_global('page_params', {});
|
2016-03-24 13:51:14 +01:00
|
|
|
add_dependencies({
|
2016-12-03 23:17:57 +01:00
|
|
|
unread: 'js/unread.js',
|
2016-03-24 13:51:14 +01:00
|
|
|
});
|
2013-08-20 22:05:56 +02:00
|
|
|
|
|
|
|
var muting = require('js/muting.js');
|
|
|
|
|
2013-09-10 22:42:48 +02:00
|
|
|
(function test_edge_cases() {
|
|
|
|
// private messages
|
|
|
|
assert(!muting.is_topic_muted(undefined, undefined));
|
|
|
|
|
|
|
|
// defensive
|
|
|
|
assert(!muting.is_topic_muted('nonexistent', undefined));
|
|
|
|
}());
|
|
|
|
|
2013-08-20 22:05:56 +02:00
|
|
|
(function test_basics() {
|
|
|
|
assert(!muting.is_topic_muted('devel', 'java'));
|
2017-02-11 09:17:19 +01:00
|
|
|
muting.add_muted_topic('devel', 'java');
|
2013-08-20 22:05:56 +02:00
|
|
|
assert(muting.is_topic_muted('devel', 'java'));
|
2013-08-27 19:36:31 +02:00
|
|
|
|
|
|
|
// test idempotentcy
|
2017-02-11 09:17:19 +01:00
|
|
|
muting.add_muted_topic('devel', 'java');
|
2013-08-27 19:36:31 +02:00
|
|
|
assert(muting.is_topic_muted('devel', 'java'));
|
2013-09-09 20:33:25 +02:00
|
|
|
|
2017-02-11 09:17:19 +01:00
|
|
|
muting.remove_muted_topic('devel', 'java');
|
2013-09-09 20:33:25 +02:00
|
|
|
assert(!muting.is_topic_muted('devel', 'java'));
|
|
|
|
|
|
|
|
// test idempotentcy
|
2017-02-11 09:17:19 +01:00
|
|
|
muting.remove_muted_topic('devel', 'java');
|
2013-09-09 20:33:25 +02:00
|
|
|
assert(!muting.is_topic_muted('devel', 'java'));
|
|
|
|
|
|
|
|
// test unknown stream is harmless too
|
2017-02-11 09:17:19 +01:00
|
|
|
muting.remove_muted_topic('unknown', 'java');
|
2013-09-09 20:33:25 +02:00
|
|
|
assert(!muting.is_topic_muted('unknown', 'java'));
|
2013-09-10 17:01:38 +02:00
|
|
|
}());
|
2013-09-09 20:33:25 +02:00
|
|
|
|
2013-09-10 20:34:41 +02:00
|
|
|
(function test_get_and_set_muted_topics() {
|
2013-09-10 17:01:38 +02:00
|
|
|
assert.deepEqual(muting.get_muted_topics(), []);
|
2017-02-11 09:17:19 +01:00
|
|
|
muting.add_muted_topic('office', 'gossip');
|
|
|
|
muting.add_muted_topic('devel', 'java');
|
2013-09-10 17:01:38 +02:00
|
|
|
assert.deepEqual(muting.get_muted_topics().sort(), [
|
|
|
|
['devel', 'java'],
|
2016-12-03 23:17:57 +01:00
|
|
|
['office', 'gossip'],
|
2013-09-10 17:01:38 +02:00
|
|
|
]);
|
2013-09-10 20:34:41 +02:00
|
|
|
|
|
|
|
muting.set_muted_topics([
|
|
|
|
['social', 'breakfast'],
|
2016-12-03 23:17:57 +01:00
|
|
|
['design', 'typography'],
|
2013-09-10 20:34:41 +02:00
|
|
|
]);
|
|
|
|
assert.deepEqual(muting.get_muted_topics().sort(), [
|
|
|
|
['design', 'typography'],
|
2016-12-03 23:17:57 +01:00
|
|
|
['social', 'breakfast'],
|
2013-09-10 20:34:41 +02:00
|
|
|
]);
|
2013-08-20 22:05:56 +02:00
|
|
|
}());
|
2013-09-10 21:33:59 +02:00
|
|
|
|
|
|
|
(function test_case_insensitivity() {
|
|
|
|
muting.set_muted_topics([]);
|
|
|
|
assert(!muting.is_topic_muted('SOCial', 'breakfast'));
|
|
|
|
muting.set_muted_topics([
|
2016-12-03 23:17:57 +01:00
|
|
|
['SOCial', 'breakfast'],
|
2013-09-10 21:33:59 +02:00
|
|
|
]);
|
|
|
|
assert(muting.is_topic_muted('SOCial', 'breakfast'));
|
|
|
|
assert(muting.is_topic_muted('social', 'breakfast'));
|
|
|
|
assert(muting.is_topic_muted('social', 'breakFAST'));
|
|
|
|
}());
|