2018-04-09 15:22:26 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
|
|
|
zrequire('settings_muting');
|
2018-12-13 22:26:10 +01:00
|
|
|
zrequire('stream_data');
|
2018-04-09 15:22:26 +02:00
|
|
|
zrequire('muting');
|
|
|
|
set_global('muting_ui', {});
|
|
|
|
|
|
|
|
var noop = function () {};
|
|
|
|
|
2018-12-13 22:26:10 +01:00
|
|
|
var frontend = {
|
|
|
|
stream_id: 101,
|
|
|
|
name: 'frontend',
|
|
|
|
};
|
|
|
|
stream_data.add_sub('frontend', frontend);
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('settings', () => {
|
2018-04-09 15:22:26 +02:00
|
|
|
|
2018-12-13 22:26:10 +01:00
|
|
|
muting.add_muted_topic(frontend.stream_id, 'js');
|
2018-04-09 15:22:26 +02:00
|
|
|
var set_up_ui_called = false;
|
|
|
|
muting_ui.set_up_muted_topics_ui = function (opts) {
|
|
|
|
assert.deepEqual(opts, [['frontend', 'js']]);
|
|
|
|
set_up_ui_called = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
settings_muting.set_up();
|
|
|
|
|
|
|
|
var click_handler = $('body').get_on_handler('click', '.settings-unmute-topic');
|
2018-06-05 08:12:06 +02:00
|
|
|
assert.equal(typeof click_handler, 'function');
|
2018-04-09 15:22:26 +02:00
|
|
|
|
|
|
|
var event = {
|
|
|
|
stopImmediatePropagation: noop,
|
|
|
|
};
|
|
|
|
|
|
|
|
var fake_this = $.create('fake.settings-unmute-topic');
|
|
|
|
var tr_html = $('tr[data-topic="js"]');
|
|
|
|
fake_this.closest = function (opts) {
|
|
|
|
assert.equal(opts, 'tr');
|
|
|
|
return tr_html;
|
|
|
|
};
|
|
|
|
|
|
|
|
var data_called = 0;
|
|
|
|
tr_html.data = function (opts) {
|
|
|
|
if (opts === 'stream') {
|
|
|
|
data_called += 1;
|
|
|
|
return 'frontend';
|
|
|
|
}
|
|
|
|
if (opts === 'topic') {
|
|
|
|
data_called += 1;
|
|
|
|
return 'js';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var unmute_called = false;
|
2018-12-14 17:20:35 +01:00
|
|
|
muting_ui.unmute = function (stream_id, topic) {
|
|
|
|
assert.equal(stream_id, frontend.stream_id);
|
2018-04-09 15:22:26 +02:00
|
|
|
assert.equal(topic, 'js');
|
|
|
|
unmute_called = true;
|
|
|
|
};
|
|
|
|
click_handler.call(fake_this, event);
|
|
|
|
assert(unmute_called);
|
|
|
|
assert(set_up_ui_called);
|
|
|
|
assert.equal(data_called, 2);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|