2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
const {zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-03-25 22:35:45 +01:00
|
|
|
const {page_params} = require("../zjsunit/zpage_params");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const settings_data = zrequire("settings_data");
|
|
|
|
const settings_config = zrequire("settings_config");
|
2020-02-25 12:46:14 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Some methods in settings_data are fairly
|
|
|
|
trivial, so the meaningful tests happen
|
|
|
|
at the higher layers, such as when we
|
|
|
|
test people.js.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const isaac = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "isaac@example.com",
|
|
|
|
delivery_email: "isaac-delivery@example.com",
|
2020-02-25 12:46:14 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("email_for_user_settings", () => {
|
2020-02-25 12:46:14 +01:00
|
|
|
const email = settings_data.email_for_user_settings;
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
page_params.realm_email_address_visibility =
|
|
|
|
settings_config.email_address_visibility_values.admins_only.code;
|
2020-02-25 12:46:14 +01:00
|
|
|
assert.equal(email(isaac), undefined);
|
|
|
|
|
|
|
|
page_params.is_admin = true;
|
|
|
|
assert.equal(email(isaac), isaac.delivery_email);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
page_params.realm_email_address_visibility =
|
|
|
|
settings_config.email_address_visibility_values.nobody.code;
|
2020-03-07 01:15:34 +01:00
|
|
|
assert.equal(email(isaac), undefined);
|
2020-02-25 12:46:14 +01:00
|
|
|
|
|
|
|
page_params.is_admin = false;
|
2020-03-07 01:15:34 +01:00
|
|
|
assert.equal(email(isaac), undefined);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
page_params.realm_email_address_visibility =
|
|
|
|
settings_config.email_address_visibility_values.everyone.code;
|
2020-02-25 12:46:14 +01:00
|
|
|
assert.equal(email(isaac), isaac.email);
|
|
|
|
});
|
2020-06-17 07:43:53 +02:00
|
|
|
|
2021-03-21 16:46:13 +01:00
|
|
|
run_test("user_can_change_name", () => {
|
|
|
|
const can_change_name = settings_data.user_can_change_name;
|
|
|
|
|
|
|
|
page_params.is_admin = true;
|
|
|
|
assert.equal(can_change_name(), true);
|
|
|
|
|
|
|
|
page_params.is_admin = false;
|
|
|
|
page_params.realm_name_changes_disabled = true;
|
|
|
|
page_params.server_name_changes_disabled = false;
|
|
|
|
assert.equal(can_change_name(), false);
|
|
|
|
|
|
|
|
page_params.realm_name_changes_disabled = false;
|
|
|
|
page_params.server_name_changes_disabled = false;
|
|
|
|
assert.equal(can_change_name(), true);
|
|
|
|
|
|
|
|
page_params.realm_name_changes_disabled = false;
|
|
|
|
page_params.server_name_changes_disabled = true;
|
|
|
|
assert.equal(can_change_name(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test("user_can_change_avatar", () => {
|
|
|
|
const can_change_avatar = settings_data.user_can_change_avatar;
|
|
|
|
|
|
|
|
page_params.is_admin = true;
|
|
|
|
assert.equal(can_change_avatar(), true);
|
|
|
|
|
|
|
|
page_params.is_admin = false;
|
|
|
|
page_params.realm_avatar_changes_disabled = true;
|
|
|
|
page_params.server_avatar_changes_disabled = false;
|
|
|
|
assert.equal(can_change_avatar(), false);
|
|
|
|
|
|
|
|
page_params.realm_avatar_changes_disabled = false;
|
|
|
|
page_params.server_avatar_changes_disabled = false;
|
|
|
|
assert.equal(can_change_avatar(), true);
|
|
|
|
|
|
|
|
page_params.realm_avatar_changes_disabled = false;
|
|
|
|
page_params.server_avatar_changes_disabled = true;
|
|
|
|
assert.equal(can_change_avatar(), false);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("user_can_change_logo", () => {
|
2020-06-17 07:43:53 +02:00
|
|
|
const can_change_logo = settings_data.user_can_change_logo;
|
|
|
|
|
|
|
|
page_params.is_admin = true;
|
|
|
|
page_params.zulip_plan_is_not_limited = true;
|
|
|
|
assert.equal(can_change_logo(), true);
|
|
|
|
|
|
|
|
page_params.is_admin = false;
|
|
|
|
page_params.zulip_plan_is_not_limited = false;
|
|
|
|
assert.equal(can_change_logo(), false);
|
|
|
|
|
|
|
|
page_params.is_admin = true;
|
|
|
|
page_params.zulip_plan_is_not_limited = false;
|
|
|
|
assert.equal(can_change_logo(), false);
|
|
|
|
|
|
|
|
page_params.is_admin = false;
|
|
|
|
page_params.zulip_plan_is_not_limited = true;
|
|
|
|
assert.equal(can_change_logo(), false);
|
|
|
|
});
|