mirror of https://github.com/zulip/zulip.git
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:
parent
96d6bf28db
commit
06f46cc146
|
@ -7,7 +7,11 @@ const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const blueslip = require("../zjsunit/zblueslip");
|
const blueslip = require("../zjsunit/zblueslip");
|
||||||
const $ = require("../zjsunit/zjquery");
|
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 = () => {};
|
const noop = () => {};
|
||||||
|
|
||||||
|
@ -985,3 +989,16 @@ run_test("server_event_dispatch_op_errors", ({override}) => {
|
||||||
blueslip.expect("error", "Unexpected event type user_group/other");
|
blueslip.expect("error", "Unexpected event type user_group/other");
|
||||||
server_events_dispatch.dispatch_normal_event({type: "user_group", op: "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);
|
||||||
|
});
|
||||||
|
|
|
@ -518,6 +518,13 @@ exports.fixtures = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
realm_user_settings_defaults__emojiset: {
|
||||||
|
type: "realm_user_settings_defaults",
|
||||||
|
op: "update",
|
||||||
|
property: "emojiset",
|
||||||
|
value: "google",
|
||||||
|
},
|
||||||
|
|
||||||
restart: {
|
restart: {
|
||||||
type: "restart",
|
type: "restart",
|
||||||
zulip_version: "4.0-dev+git",
|
zulip_version: "4.0-dev+git",
|
||||||
|
|
|
@ -102,6 +102,8 @@ try {
|
||||||
require("../../static/js/page_params");
|
require("../../static/js/page_params");
|
||||||
namespace.mock_esm("../../static/js/user_settings", zpage_params);
|
namespace.mock_esm("../../static/js/user_settings", zpage_params);
|
||||||
require("../../static/js/user_settings");
|
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);
|
run_one_module(file);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.page_params = {};
|
exports.page_params = {};
|
||||||
|
exports.realm_user_settings_defaults = {};
|
||||||
exports.user_settings = {};
|
exports.user_settings = {};
|
||||||
|
|
||||||
exports.reset = () => {
|
exports.reset = () => {
|
||||||
|
@ -14,4 +15,9 @@ exports.reset = () => {
|
||||||
delete exports.user_settings[field];
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,6 +36,7 @@ import * as reactions from "./reactions";
|
||||||
import * as realm_icon from "./realm_icon";
|
import * as realm_icon from "./realm_icon";
|
||||||
import * as realm_logo from "./realm_logo";
|
import * as realm_logo from "./realm_logo";
|
||||||
import * as realm_playground from "./realm_playground";
|
import * as realm_playground from "./realm_playground";
|
||||||
|
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
|
||||||
import * as reload from "./reload";
|
import * as reload from "./reload";
|
||||||
import * as scroll_bar from "./scroll_bar";
|
import * as scroll_bar from "./scroll_bar";
|
||||||
import * as settings_account from "./settings_account";
|
import * as settings_account from "./settings_account";
|
||||||
|
@ -381,6 +382,36 @@ export function dispatch_normal_event(event) {
|
||||||
}
|
}
|
||||||
break;
|
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":
|
case "realm_user":
|
||||||
switch (event.op) {
|
switch (event.op) {
|
||||||
case "add":
|
case "add":
|
||||||
|
|
Loading…
Reference in New Issue