2020-02-04 21:50:55 +01:00
|
|
|
set_global('i18n', global.stub_i18n);
|
|
|
|
|
2017-11-08 18:22:21 +01:00
|
|
|
zrequire('muting');
|
2018-12-13 22:26:10 +01:00
|
|
|
zrequire('stream_data');
|
|
|
|
set_global('blueslip', global.make_zblueslip());
|
2018-12-15 19:53:20 +01:00
|
|
|
set_global('page_params', {});
|
2013-08-20 22:05:56 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('edge_cases', () => {
|
2013-09-10 22:42:48 +02:00
|
|
|
// private messages
|
|
|
|
assert(!muting.is_topic_muted(undefined, undefined));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-09-10 22:42:48 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const design = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 100,
|
|
|
|
name: 'design',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const devel = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 101,
|
|
|
|
name: 'devel',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const office = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 102,
|
|
|
|
name: 'office',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const social = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 103,
|
|
|
|
name: 'social',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const unknown = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 999,
|
|
|
|
name: 'whatever',
|
|
|
|
};
|
|
|
|
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(design);
|
|
|
|
stream_data.add_sub(devel);
|
|
|
|
stream_data.add_sub(office);
|
|
|
|
stream_data.add_sub(social);
|
2018-12-13 22:26:10 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('basics', () => {
|
2018-12-13 22:26:10 +01:00
|
|
|
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'));
|
2013-08-27 19:36:31 +02:00
|
|
|
|
|
|
|
// test idempotentcy
|
2018-12-13 22:26:10 +01:00
|
|
|
muting.add_muted_topic(devel.stream_id, 'java');
|
|
|
|
assert(muting.is_topic_muted(devel.stream_id, 'java'));
|
2013-09-09 20:33:25 +02:00
|
|
|
|
2018-12-13 22:26:10 +01:00
|
|
|
muting.remove_muted_topic(devel.stream_id, 'java');
|
|
|
|
assert(!muting.is_topic_muted(devel.stream_id, 'java'));
|
2013-09-09 20:33:25 +02:00
|
|
|
|
|
|
|
// test idempotentcy
|
2018-12-13 22:26:10 +01:00
|
|
|
muting.remove_muted_topic(devel.stream_id, 'java');
|
|
|
|
assert(!muting.is_topic_muted(devel.stream_id, 'java'));
|
2013-09-09 20:33:25 +02:00
|
|
|
|
|
|
|
// test unknown stream is harmless too
|
2018-12-13 22:26:10 +01:00
|
|
|
muting.remove_muted_topic(unknown.stream_id, 'java');
|
|
|
|
assert(!muting.is_topic_muted(unknown.stream_id, 'java'));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-09-09 20:33:25 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('get_and_set_muted_topics', () => {
|
2013-09-10 17:01:38 +02:00
|
|
|
assert.deepEqual(muting.get_muted_topics(), []);
|
2018-12-13 22:26:10 +01:00
|
|
|
muting.add_muted_topic(office.stream_id, 'gossip');
|
|
|
|
muting.add_muted_topic(devel.stream_id, 'java');
|
2013-09-10 17:01:38 +02:00
|
|
|
assert.deepEqual(muting.get_muted_topics().sort(), [
|
2018-12-14 18:08:08 +01:00
|
|
|
[devel.stream_id, 'java'],
|
|
|
|
[office.stream_id, 'gossip'],
|
2013-09-10 17:01:38 +02:00
|
|
|
]);
|
2013-09-10 20:34:41 +02:00
|
|
|
|
2018-12-13 22:26:10 +01:00
|
|
|
blueslip.set_test_data('warn', 'Unknown stream in set_muted_topics: BOGUS STREAM');
|
|
|
|
|
2018-12-15 19:53:20 +01:00
|
|
|
page_params.muted_topics = [
|
2013-09-10 20:34:41 +02:00
|
|
|
['social', 'breakfast'],
|
2016-12-03 23:17:57 +01:00
|
|
|
['design', 'typography'],
|
2018-12-13 22:26:10 +01:00
|
|
|
['BOGUS STREAM', 'whatever'],
|
2018-12-15 19:53:20 +01:00
|
|
|
];
|
|
|
|
muting.initialize();
|
2018-12-13 22:26:10 +01:00
|
|
|
|
|
|
|
blueslip.clear_test_data();
|
|
|
|
|
|
|
|
|
2013-09-10 20:34:41 +02:00
|
|
|
assert.deepEqual(muting.get_muted_topics().sort(), [
|
2018-12-14 18:08:08 +01:00
|
|
|
[design.stream_id, 'typography'],
|
|
|
|
[social.stream_id, 'breakfast'],
|
2013-09-10 20:34:41 +02:00
|
|
|
]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-09-10 21:33:59 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('case_insensitivity', () => {
|
2013-09-10 21:33:59 +02:00
|
|
|
muting.set_muted_topics([]);
|
2018-12-13 22:26:10 +01:00
|
|
|
assert(!muting.is_topic_muted(social.stream_id, 'breakfast'));
|
2013-09-10 21:33:59 +02:00
|
|
|
muting.set_muted_topics([
|
2016-12-03 23:17:57 +01:00
|
|
|
['SOCial', 'breakfast'],
|
2013-09-10 21:33:59 +02:00
|
|
|
]);
|
2018-12-13 22:26:10 +01:00
|
|
|
assert(muting.is_topic_muted(social.stream_id, 'breakfast'));
|
|
|
|
assert(muting.is_topic_muted(social.stream_id, 'breakFAST'));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|