settings: Add live update code for realm-level defaults settings.

This commit adds code for live-updating the realm-level default
settings page which contains only display settings as of now.

This commit also adds realm_user_settings_defaults object to
zpage_params so that we can write the tests.
This commit is contained in:
Sahil Batra 2021-08-30 19:56:38 +05:30 committed by Tim Abbott
parent 96d6bf28db
commit 06f46cc146
5 changed files with 64 additions and 1 deletions

View File

@ -7,7 +7,11 @@ const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip");
const $ = require("../zjsunit/zjquery");
const {page_params, user_settings} = require("../zjsunit/zpage_params");
const {
page_params,
realm_user_settings_defaults,
user_settings,
} = require("../zjsunit/zpage_params");
const noop = () => {};
@ -985,3 +989,16 @@ run_test("server_event_dispatch_op_errors", ({override}) => {
blueslip.expect("error", "Unexpected event type user_group/other");
server_events_dispatch.dispatch_normal_event({type: "user_group", op: "other"});
});
run_test("realm_user_settings_defaults", ({override}) => {
override(settings_display, "update_page", noop);
const event = event_fixtures.realm_user_settings_defaults__emojiset;
realm_user_settings_defaults.emojiset = "text";
let called = false;
settings_display.report_emojiset_change = () => {
called = true;
};
dispatch(event);
assert_same(realm_user_settings_defaults.emojiset, "google");
assert_same(called, true);
});

View File

@ -518,6 +518,13 @@ exports.fixtures = {
},
},
realm_user_settings_defaults__emojiset: {
type: "realm_user_settings_defaults",
op: "update",
property: "emojiset",
value: "google",
},
restart: {
type: "restart",
zulip_version: "4.0-dev+git",

View File

@ -102,6 +102,8 @@ try {
require("../../static/js/page_params");
namespace.mock_esm("../../static/js/user_settings", zpage_params);
require("../../static/js/user_settings");
namespace.mock_esm("../../static/js/realm_user_settings_defaults", zpage_params);
require("../../static/js/realm_user_settings_defaults");
run_one_module(file);

View File

@ -1,6 +1,7 @@
"use strict";
exports.page_params = {};
exports.realm_user_settings_defaults = {};
exports.user_settings = {};
exports.reset = () => {
@ -14,4 +15,9 @@ exports.reset = () => {
delete exports.user_settings[field];
}
}
for (const field in exports.realm_user_settings_defaults) {
if (Object.prototype.hasOwnProperty.call(exports.realm_user_settings_defaults, field)) {
delete exports.realm_user_settings_defaults[field];
}
}
};

View File

@ -36,6 +36,7 @@ import * as reactions from "./reactions";
import * as realm_icon from "./realm_icon";
import * as realm_logo from "./realm_logo";
import * as realm_playground from "./realm_playground";
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
import * as reload from "./reload";
import * as scroll_bar from "./scroll_bar";
import * as settings_account from "./settings_account";
@ -381,6 +382,36 @@ export function dispatch_normal_event(event) {
}
break;
case "realm_user_settings_defaults": {
realm_user_settings_defaults[event.property] = event.value;
const display_settings_list = [
"color_scheme",
"default_view",
"demote_inactive_streams",
"dense_mode",
"emojiset",
"fluid_layout_width",
"high_contrast_mode",
"left_side_userlist",
"translate_emoticons",
"starred_message_counts",
];
const container_elem = $("#realm-user-default-settings");
if (display_settings_list.includes(event.property)) {
settings_display.update_page(container_elem, realm_user_settings_defaults);
}
if (event.property === "emojiset") {
settings_display.report_emojiset_change(
container_elem,
realm_user_settings_defaults,
);
}
break;
}
case "realm_user":
switch (event.op) {
case "add":