2013-08-20 22:05:56 +02:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
add_dependencies({
|
|
|
|
_: 'third/underscore/underscore.js',
|
|
|
|
Dict: 'js/dict.js'
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('page_params', {
|
|
|
|
domain: 'zulip.com'
|
|
|
|
});
|
|
|
|
|
|
|
|
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'));
|
|
|
|
muting.mute_topic('devel', 'java');
|
|
|
|
assert(muting.is_topic_muted('devel', 'java'));
|
2013-08-27 19:36:31 +02:00
|
|
|
|
|
|
|
// test idempotentcy
|
|
|
|
muting.mute_topic('devel', 'java');
|
|
|
|
assert(muting.is_topic_muted('devel', 'java'));
|
2013-09-09 20:33:25 +02:00
|
|
|
|
|
|
|
muting.unmute_topic('devel', 'java');
|
|
|
|
assert(!muting.is_topic_muted('devel', 'java'));
|
|
|
|
|
|
|
|
// test idempotentcy
|
|
|
|
muting.unmute_topic('devel', 'java');
|
|
|
|
assert(!muting.is_topic_muted('devel', 'java'));
|
|
|
|
|
|
|
|
// test unknown stream is harmless too
|
|
|
|
muting.unmute_topic('unknown', 'java');
|
|
|
|
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(), []);
|
|
|
|
muting.mute_topic('office', 'gossip');
|
|
|
|
muting.mute_topic('devel', 'java');
|
|
|
|
assert.deepEqual(muting.get_muted_topics().sort(), [
|
|
|
|
['devel', 'java'],
|
|
|
|
['office', 'gossip']
|
|
|
|
]);
|
2013-09-10 20:34:41 +02:00
|
|
|
|
|
|
|
muting.set_muted_topics([
|
|
|
|
['social', 'breakfast'],
|
|
|
|
['design', 'typography']
|
|
|
|
]);
|
|
|
|
assert.deepEqual(muting.get_muted_topics().sort(), [
|
|
|
|
['design', 'typography'],
|
|
|
|
['social', 'breakfast']
|
|
|
|
]);
|
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([
|
|
|
|
['SOCial', 'breakfast']
|
|
|
|
]);
|
|
|
|
assert(muting.is_topic_muted('SOCial', 'breakfast'));
|
|
|
|
assert(muting.is_topic_muted('social', 'breakfast'));
|
|
|
|
assert(muting.is_topic_muted('social', 'breakFAST'));
|
|
|
|
}());
|