mirror of https://github.com/zulip/zulip.git
refactor: Move get_notifications_table_row_data.
The only caller for this function was settings_config, so we put it there. For the stream_edit test we no longer mock the function. (The reason we mocked the function was more about avoiding the heavy settings_notifications import than the function itself.) This gives some incidental coverage, but then I also add some more real coverage on it.
This commit is contained in:
parent
e637004695
commit
a429ecbb1b
|
@ -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: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
|
@ -25,9 +25,6 @@ mock_esm("../../static/js/hashchange", {update_browser_history: noop});
|
||||||
mock_esm("../../static/js/list_widget", {
|
mock_esm("../../static/js/list_widget", {
|
||||||
create: () => ({init: noop}),
|
create: () => ({init: noop}),
|
||||||
});
|
});
|
||||||
mock_esm("../../static/js/settings_notifications", {
|
|
||||||
get_notifications_table_row_data: noop,
|
|
||||||
});
|
|
||||||
mock_esm("../../static/js/stream_color", {
|
mock_esm("../../static/js/stream_color", {
|
||||||
set_colorpicker_color: noop,
|
set_colorpicker_color: noop,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import * as settings_notifications from "./settings_notifications";
|
|
||||||
/*
|
/*
|
||||||
This file contains translations between the integer values used in
|
This file contains translations between the integer values used in
|
||||||
the Zulip API to describe values in dropdowns, radio buttons, and
|
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,
|
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 = () => ({
|
export const all_notifications = () => ({
|
||||||
general_settings: [
|
general_settings: [
|
||||||
{
|
{
|
||||||
label: i18n.t("Streams"),
|
label: i18n.t("Streams"),
|
||||||
notification_settings: settings_notifications.get_notifications_table_row_data(
|
notification_settings: get_notifications_table_row_data(stream_notification_settings),
|
||||||
stream_notification_settings,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: i18n.t("PMs, mentions, and alerts"),
|
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,
|
pm_mention_notification_settings,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,28 +11,6 @@ import * as stream_data from "./stream_data";
|
||||||
import * as stream_edit from "./stream_edit";
|
import * as stream_edit from "./stream_edit";
|
||||||
import * as unread_ui from "./unread_ui";
|
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 = {
|
export const desktop_icon_count_display_values = {
|
||||||
messages: {
|
messages: {
|
||||||
code: 1,
|
code: 1,
|
||||||
|
|
Loading…
Reference in New Issue