diff --git a/web/src/settings_user_topics.ts b/web/src/settings_user_topics.ts index a9853eb33f..ec289b41f0 100644 --- a/web/src/settings_user_topics.ts +++ b/web/src/settings_user_topics.ts @@ -61,26 +61,30 @@ export function populate_list(): void { export function set_up(): void { loaded = true; - $("body").on("change", ".settings_user_topic_visibility_policy", function (e) { - const $row = $(this).closest("tr"); - const stream_id_string = $row.attr("data-stream-id"); - assert(stream_id_string !== undefined); - const stream_id = Number.parseInt(stream_id_string, 10); - const topic = $row.attr("data-topic"); - assert(topic !== undefined); - const visibility_policy = this.value; + $("body").on( + "change", + "select.settings_user_topic_visibility_policy", + function (this: HTMLSelectElement, e) { + const $row = $(this).closest("tr"); + const stream_id_string = $row.attr("data-stream-id"); + assert(stream_id_string !== undefined); + const stream_id = Number.parseInt(stream_id_string, 10); + const topic = $row.attr("data-topic"); + assert(topic !== undefined); + const visibility_policy = Number(this.value); - e.stopPropagation(); + e.stopPropagation(); - user_topics.set_user_topic_visibility_policy( - stream_id, - topic, - visibility_policy, - false, - false, - $row.closest("#user-topic-settings").find(".alert-notification"), - ); - }); + user_topics.set_user_topic_visibility_policy( + stream_id, + topic, + visibility_policy, + false, + false, + $row.closest("#user-topic-settings").find(".alert-notification"), + ); + }, + ); populate_list(); } diff --git a/web/tests/settings_user_topics.test.js b/web/tests/settings_user_topics.test.js index 232ea5909d..3c14b2b618 100644 --- a/web/tests/settings_user_topics.test.js +++ b/web/tests/settings_user_topics.test.js @@ -52,7 +52,7 @@ run_test("settings", ({override, override_rewire}) => { const topic_change_handler = $("body").get_on_handler( "change", - ".settings_user_topic_visibility_policy", + "select.settings_user_topic_visibility_policy", ); assert.equal(typeof topic_change_handler, "function"); @@ -104,8 +104,11 @@ run_test("settings", ({override, override_rewire}) => { user_topic_visibility_policy_changed = true; }, ); - $topic_fake_this.value = user_topics.all_visibility_policies.UNMUTED; - topic_change_handler.call($topic_fake_this, event); + const topic_fake_this = { + to_$: () => $topic_fake_this, + value: user_topics.all_visibility_policies.UNMUTED, + }; + topic_change_handler.call(topic_fake_this, event); assert.ok(user_topic_visibility_policy_changed); assert.equal(topic_data_called, 2); });