diff --git a/frontend_tests/node_tests/settings_config.js b/frontend_tests/node_tests/settings_config.js new file mode 100644 index 0000000000..f8d644d0a7 --- /dev/null +++ b/frontend_tests/node_tests/settings_config.js @@ -0,0 +1,85 @@ +"use strict"; + +const {strict: assert} = require("assert"); + +const {set_global, zrequire} = require("../zjsunit/namespace"); +const {run_test} = require("../zjsunit/test"); + +const page_params = set_global("page_params", {}); +const settings_config = zrequire("settings_config"); + +run_test("all_notifications", () => { + page_params.enable_stream_desktop_notifications = false; + page_params.enable_stream_audible_notifications = true; + page_params.enable_stream_push_notifications = true; + page_params.enable_stream_email_notifications = false; + page_params.enable_desktop_notifications = false; + page_params.enable_sounds = true; + page_params.enable_offline_push_notifications = false; + page_params.enable_offline_email_notifications = true; + + const notifications = settings_config.all_notifications(); + + assert.deepEqual(notifications.general_settings, [ + { + label: "translated: Streams", + notification_settings: [ + { + is_checked: false, + is_disabled: false, + setting_name: "enable_stream_desktop_notifications", + }, + { + is_checked: true, + is_disabled: false, + setting_name: "enable_stream_audible_notifications", + }, + { + is_checked: true, + is_disabled: true, + setting_name: "enable_stream_push_notifications", + }, + { + is_checked: false, + is_disabled: false, + setting_name: "enable_stream_email_notifications", + }, + { + is_checked: undefined, + is_disabled: false, + setting_name: "wildcard_mentions_notify", + }, + ], + }, + { + label: "translated: PMs, mentions, and alerts", + notification_settings: [ + { + is_checked: false, + is_disabled: false, + setting_name: "enable_desktop_notifications", + }, + { + is_checked: true, + is_disabled: false, + setting_name: "enable_sounds", + }, + { + is_checked: false, + is_disabled: true, + setting_name: "enable_offline_push_notifications", + }, + { + is_checked: true, + is_disabled: false, + setting_name: "enable_offline_email_notifications", + }, + { + is_checked: false, + is_disabled: true, + setting_name: "", + }, + ], + }, + ]); +}); diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js index 77bb6db832..0faacb1750 100644 --- a/frontend_tests/node_tests/stream_edit.js +++ b/frontend_tests/node_tests/stream_edit.js @@ -25,9 +25,6 @@ mock_esm("../../static/js/hashchange", {update_browser_history: noop}); mock_esm("../../static/js/list_widget", { create: () => ({init: noop}), }); -mock_esm("../../static/js/settings_notifications", { - get_notifications_table_row_data: noop, -}); mock_esm("../../static/js/stream_color", { set_colorpicker_color: noop, }); diff --git a/static/js/settings_config.js b/static/js/settings_config.js index 6cb7047d7d..58ac4e952d 100644 --- a/static/js/settings_config.js +++ b/static/js/settings_config.js @@ -1,4 +1,3 @@ -import * as settings_notifications from "./settings_notifications"; /* This file contains translations between the integer values used in the Zulip API to describe values in dropdowns, radio buttons, and @@ -340,17 +339,37 @@ export const all_notification_settings = other_notification_settings.concat( stream_notification_settings, ); +export function get_notifications_table_row_data(notify_settings) { + return general_notifications_table_labels.realm.map((column, index) => { + const setting_name = notify_settings[index]; + if (setting_name === undefined) { + return { + setting_name: "", + is_disabled: true, + is_checked: false, + }; + } + const checkbox = { + setting_name, + is_disabled: false, + }; + if (column === "mobile") { + checkbox.is_disabled = !page_params.realm_push_notifications_enabled; + } + checkbox.is_checked = page_params[setting_name]; + return checkbox; + }); +} + export const all_notifications = () => ({ general_settings: [ { label: i18n.t("Streams"), - notification_settings: settings_notifications.get_notifications_table_row_data( - stream_notification_settings, - ), + notification_settings: get_notifications_table_row_data(stream_notification_settings), }, { label: i18n.t("PMs, mentions, and alerts"), - notification_settings: settings_notifications.get_notifications_table_row_data( + notification_settings: get_notifications_table_row_data( pm_mention_notification_settings, ), }, diff --git a/static/js/settings_notifications.js b/static/js/settings_notifications.js index 5ae6b3eab4..dfed0cbe37 100644 --- a/static/js/settings_notifications.js +++ b/static/js/settings_notifications.js @@ -11,28 +11,6 @@ import * as stream_data from "./stream_data"; import * as stream_edit from "./stream_edit"; import * as unread_ui from "./unread_ui"; -export function get_notifications_table_row_data(notify_settings) { - return settings_config.general_notifications_table_labels.realm.map((column, index) => { - const setting_name = notify_settings[index]; - if (setting_name === undefined) { - return { - setting_name: "", - is_disabled: true, - is_checked: false, - }; - } - const checkbox = { - setting_name, - is_disabled: false, - }; - if (column === "mobile") { - checkbox.is_disabled = !page_params.realm_push_notifications_enabled; - } - checkbox.is_checked = page_params[setting_name]; - return checkbox; - }); -} - export const desktop_icon_count_display_values = { messages: { code: 1,