Files
zulip/frontend_tests/node_tests/muting.js
Steve Howell a8718c9051 muting: Use stream_id for internal data structures.
This fixes the most core data structures inside of
muting.js.  We still use stream names for incoming
data to set_muted_topics and outgoing data from
get_muted_topics.

This will make us more resilient to stream name changes.
Before, if you were logged on when a stream rename
occured, topics that were muted under that stream would
appear to be unmuted.  (You could fix it with a reload,
but it can be jarring to have a bunch of unread messages
appear in your feed suddenly.)

Fixes #11033
2018-12-14 15:58:35 -08:00

99 lines
2.5 KiB
JavaScript

zrequire('muting');
zrequire('stream_data');
set_global('blueslip', global.make_zblueslip());
run_test('edge_cases', () => {
// private messages
assert(!muting.is_topic_muted(undefined, undefined));
// defensive
assert(!muting.is_topic_muted('nonexistent', undefined));
});
var design = {
stream_id: 100,
name: 'design',
};
var devel = {
stream_id: 101,
name: 'devel',
};
var office = {
stream_id: 102,
name: 'office',
};
var social = {
stream_id: 103,
name: 'social',
};
var unknown = {
stream_id: 999,
name: 'whatever',
};
stream_data.add_sub(design.name, design);
stream_data.add_sub(devel.name, devel);
stream_data.add_sub(office.name, office);
stream_data.add_sub(social.name, social);
run_test('basics', () => {
assert(!muting.is_topic_muted(devel.stream_id, 'java'));
muting.add_muted_topic(devel.stream_id, 'java');
assert(muting.is_topic_muted(devel.stream_id, 'java'));
// test idempotentcy
muting.add_muted_topic(devel.stream_id, 'java');
assert(muting.is_topic_muted(devel.stream_id, 'java'));
muting.remove_muted_topic(devel.stream_id, 'java');
assert(!muting.is_topic_muted(devel.stream_id, 'java'));
// test idempotentcy
muting.remove_muted_topic(devel.stream_id, 'java');
assert(!muting.is_topic_muted(devel.stream_id, 'java'));
// test unknown stream is harmless too
muting.remove_muted_topic(unknown.stream_id, 'java');
assert(!muting.is_topic_muted(unknown.stream_id, 'java'));
});
run_test('get_and_set_muted_topics', () => {
assert.deepEqual(muting.get_muted_topics(), []);
muting.add_muted_topic(office.stream_id, 'gossip');
muting.add_muted_topic(devel.stream_id, 'java');
assert.deepEqual(muting.get_muted_topics().sort(), [
['devel', 'java'],
['office', 'gossip'],
]);
blueslip.set_test_data('warn', 'Unknown stream in set_muted_topics: BOGUS STREAM');
muting.set_muted_topics([
['social', 'breakfast'],
['design', 'typography'],
['BOGUS STREAM', 'whatever'],
]);
blueslip.clear_test_data();
assert.deepEqual(muting.get_muted_topics().sort(), [
['design', 'typography'],
['social', 'breakfast'],
]);
});
run_test('case_insensitivity', () => {
muting.set_muted_topics([]);
assert(!muting.is_topic_muted(social.stream_id, 'breakfast'));
muting.set_muted_topics([
['SOCial', 'breakfast'],
]);
assert(muting.is_topic_muted(social.stream_id, 'breakfast'));
assert(muting.is_topic_muted(social.stream_id, 'breakFAST'));
});