Files
zulip/frontend_tests/node_tests/muting.js
Steve Howell 7d153c9f8a Revert "muting.js: Track muted streams using stream id."
This reverts commit c7f710b8d4.

Because the back end still stores muted topics fundamentally using
stream name as a key, trying to cut over the client to use stream
id was just making things more brittle.  Mutes would work after
renaming the stream, which was progress in the change that we
revert here, but only until page load.  The other problem, which
is more severe, is that the order of page loading functions would
cause no mutes to happen at page load time.  This could be fixed
to some degree, but we should do a deeper fix on the back end.
2017-05-17 07:06:32 -07:00

66 lines
1.9 KiB
JavaScript

set_global('page_params', {});
add_dependencies({
unread: 'js/unread.js',
});
var muting = require('js/muting.js');
(function test_edge_cases() {
// private messages
assert(!muting.is_topic_muted(undefined, undefined));
// defensive
assert(!muting.is_topic_muted('nonexistent', undefined));
}());
(function test_basics() {
assert(!muting.is_topic_muted('devel', 'java'));
muting.add_muted_topic('devel', 'java');
assert(muting.is_topic_muted('devel', 'java'));
// test idempotentcy
muting.add_muted_topic('devel', 'java');
assert(muting.is_topic_muted('devel', 'java'));
muting.remove_muted_topic('devel', 'java');
assert(!muting.is_topic_muted('devel', 'java'));
// test idempotentcy
muting.remove_muted_topic('devel', 'java');
assert(!muting.is_topic_muted('devel', 'java'));
// test unknown stream is harmless too
muting.remove_muted_topic('unknown', 'java');
assert(!muting.is_topic_muted('unknown', 'java'));
}());
(function test_get_and_set_muted_topics() {
assert.deepEqual(muting.get_muted_topics(), []);
muting.add_muted_topic('office', 'gossip');
muting.add_muted_topic('devel', 'java');
assert.deepEqual(muting.get_muted_topics().sort(), [
['devel', 'java'],
['office', 'gossip'],
]);
muting.set_muted_topics([
['social', 'breakfast'],
['design', 'typography'],
]);
assert.deepEqual(muting.get_muted_topics().sort(), [
['design', 'typography'],
['social', 'breakfast'],
]);
}());
(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'));
}());