2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-08-25 18:37:48 +02:00
|
|
|
const rewiremock = require("rewiremock/node");
|
|
|
|
|
2020-12-01 00:19:42 +01:00
|
|
|
const {stub_templates} = require("../zjsunit/handlebars");
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-04-16 18:58:27 +02:00
|
|
|
const noop = () => {};
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let form_data;
|
2018-08-01 21:17:03 +02:00
|
|
|
|
|
|
|
const _jQuery = {
|
2020-07-20 22:18:43 +02:00
|
|
|
each(lst, f) {
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
for (const [k, v] of lst.entries()) {
|
2018-08-01 21:17:03 +02:00
|
|
|
f(k, v);
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2018-08-01 21:17:03 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const _FormData = function () {
|
|
|
|
return form_data;
|
|
|
|
};
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _loading = {
|
2017-06-16 14:41:10 +02:00
|
|
|
make_indicator: noop,
|
|
|
|
destroy_indicator: noop,
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2021-02-23 03:54:07 +01:00
|
|
|
const page_params = set_global("page_params", {
|
2017-06-16 14:41:10 +02:00
|
|
|
is_admin: false,
|
|
|
|
realm_domains: [
|
2020-07-16 22:40:18 +02:00
|
|
|
{domain: "example.com", allow_subdomains: true},
|
|
|
|
{domain: "example.org", allow_subdomains: false},
|
2017-06-16 14:41:10 +02:00
|
|
|
],
|
2020-02-09 04:45:48 +01:00
|
|
|
realm_authentication_methods: {},
|
2021-02-23 03:54:07 +01:00
|
|
|
});
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const realm_icon = set_global("realm_icon", {});
|
|
|
|
const channel = set_global("channel", {});
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-12-01 00:19:42 +01:00
|
|
|
stub_templates((name, data) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (name === "settings/admin_realm_domains_list") {
|
2019-07-11 05:06:20 +02:00
|
|
|
assert(data.realm_domain.domain);
|
2020-07-15 01:29:15 +02:00
|
|
|
return "stub-domains-list";
|
2019-07-11 05:06:20 +02:00
|
|
|
}
|
2020-09-24 07:50:36 +02:00
|
|
|
throw new Error(`Unknown template ${name}`);
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const overlays = set_global("overlays", {});
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _ui_report = {
|
2020-07-20 22:18:43 +02:00
|
|
|
success(msg, elem) {
|
2017-06-16 14:41:10 +02:00
|
|
|
elem.val(msg);
|
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
error(msg, xhr, elem) {
|
2017-06-16 14:41:10 +02:00
|
|
|
elem.val(msg);
|
|
|
|
},
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
|
|
|
|
2018-08-16 01:26:55 +02:00
|
|
|
const _realm_logo = {
|
2019-03-11 16:48:59 +01:00
|
|
|
build_realm_logo_widget: noop,
|
2018-08-16 01:26:55 +02:00
|
|
|
};
|
|
|
|
|
2021-01-29 10:27:56 +01:00
|
|
|
const _ListWidget = {
|
2020-07-16 22:40:18 +02:00
|
|
|
create: () => ({init: noop}),
|
2020-04-15 04:29:15 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("csrf_token", "token-stub");
|
|
|
|
set_global("FormData", _FormData);
|
|
|
|
set_global("jQuery", _jQuery);
|
|
|
|
set_global("loading", _loading);
|
|
|
|
set_global("realm_logo", _realm_logo);
|
|
|
|
set_global("ui_report", _ui_report);
|
2021-01-29 10:27:56 +01:00
|
|
|
set_global("ListWidget", _ListWidget);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
|
|
|
const settings_config = zrequire("settings_config");
|
|
|
|
const settings_bots = zrequire("settings_bots");
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
const settings_account = rewiremock.proxy(() => zrequire("settings_account"), {
|
2020-08-25 18:37:48 +02:00
|
|
|
// Setup is only imported to set the
|
|
|
|
// setup.password_change_in_progress flag.
|
|
|
|
"../../static/js/setup": {},
|
|
|
|
});
|
2021-02-10 04:53:22 +01:00
|
|
|
const settings_org = zrequire("settings_org");
|
|
|
|
const dropdown_list_widget = zrequire("dropdown_list_widget");
|
2020-07-15 01:29:15 +02:00
|
|
|
|
|
|
|
run_test("unloaded", () => {
|
2018-08-01 21:17:03 +02:00
|
|
|
// This test mostly gets us line coverage, and makes
|
|
|
|
// sure things don't explode before set_up is called.
|
|
|
|
|
|
|
|
settings_org.reset();
|
|
|
|
settings_org.populate_realm_domains();
|
|
|
|
settings_org.populate_auth_methods();
|
2017-06-16 14:41:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function simulate_realm_domains_table() {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#realm_domains_table tbody").set_find_results("tr", $.create("realm-tr-stub"));
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let appended;
|
2021-02-23 14:37:26 +01:00
|
|
|
$("#realm_domains_table tbody").append = (html) => {
|
2017-06-16 14:41:10 +02:00
|
|
|
appended = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(html, "stub-domains-list");
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return function verify() {
|
|
|
|
assert(appended);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_realms_domain_modal(add_realm_domain) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const info = $(".realm_domains_info");
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#add-realm-domain-widget").set_find_results(
|
|
|
|
".new-realm-domain",
|
|
|
|
$.create("new-realm-domain-stub"),
|
2017-06-16 14:41:10 +02:00
|
|
|
);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#add-realm-domain-widget").set_find_results(
|
|
|
|
".new-realm-domain-allow-subdomains",
|
|
|
|
$.create("new-realm-domain-allow-subdomains-stub"),
|
2017-06-16 14:41:10 +02:00
|
|
|
);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let posted;
|
|
|
|
let success_callback;
|
|
|
|
let error_callback;
|
2021-02-23 14:37:26 +01:00
|
|
|
channel.post = (req) => {
|
2017-06-16 14:41:10 +02:00
|
|
|
posted = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(req.url, "/json/realm/domains");
|
2017-06-16 14:41:10 +02:00
|
|
|
success_callback = req.success;
|
|
|
|
error_callback = req.error;
|
|
|
|
};
|
|
|
|
|
|
|
|
add_realm_domain();
|
|
|
|
|
|
|
|
assert(posted);
|
|
|
|
|
|
|
|
success_callback();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(info.val(), "translated: Added successfully!");
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-12-25 17:49:46 +01:00
|
|
|
error_callback({});
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(info.val(), "translated: Failed");
|
2017-06-16 14:41:10 +02:00
|
|
|
}
|
2018-04-16 18:58:27 +02:00
|
|
|
|
|
|
|
function createSaveButtons(subsection) {
|
2021-02-03 23:23:32 +01:00
|
|
|
const stub_save_button_header = $(`#org-${CSS.escape(subsection)}`);
|
2020-07-15 01:29:15 +02:00
|
|
|
const save_button_controls = $(".save-button-controls");
|
2021-02-03 23:23:32 +01:00
|
|
|
const stub_save_button = $(`#org-submit-${CSS.escape(subsection)}`);
|
|
|
|
const stub_discard_button = $(`#org-discard-${CSS.escape(subsection)}`);
|
2020-09-01 07:54:40 +02:00
|
|
|
const stub_save_button_text = $(".save-discard-widget-button-text");
|
2018-04-30 15:27:35 +02:00
|
|
|
stub_save_button_header.set_find_results(
|
2020-07-15 00:34:28 +02:00
|
|
|
".subsection-failed-status p",
|
|
|
|
$("<failed status element>"),
|
2018-04-30 15:27:35 +02:00
|
|
|
);
|
2018-06-16 13:21:59 +02:00
|
|
|
stub_save_button.closest = () => stub_save_button_header;
|
2020-07-15 00:34:28 +02:00
|
|
|
save_button_controls.set_find_results(".save-button", stub_save_button);
|
2020-09-01 07:54:40 +02:00
|
|
|
stub_save_button.set_find_results(".save-discard-widget-button-text", stub_save_button_text);
|
2020-07-15 00:34:28 +02:00
|
|
|
stub_save_button_header.set_find_results(".save-button-controls", save_button_controls);
|
2018-03-29 02:02:01 +02:00
|
|
|
stub_save_button_header.set_find_results(
|
2020-07-15 00:34:28 +02:00
|
|
|
".subsection-changes-discard .button",
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`#org-discard-${CSS.escape(subsection)}`),
|
2019-03-07 15:18:10 +01:00
|
|
|
);
|
2020-07-15 00:34:28 +02:00
|
|
|
save_button_controls.set_find_results(".discard-button", stub_discard_button);
|
2020-07-16 23:29:01 +02:00
|
|
|
const props = {};
|
2018-03-29 02:02:01 +02:00
|
|
|
props.hidden = false;
|
2019-03-10 09:00:30 +01:00
|
|
|
save_button_controls.fadeIn = () => {
|
2018-05-07 03:30:13 +02:00
|
|
|
props.hidden = false;
|
2018-04-30 15:01:55 +02:00
|
|
|
};
|
2019-03-10 09:00:30 +01:00
|
|
|
save_button_controls.fadeOut = () => {
|
2018-04-30 15:01:55 +02:00
|
|
|
props.hidden = true;
|
2018-03-29 02:02:01 +02:00
|
|
|
};
|
|
|
|
return {
|
2020-07-20 22:18:43 +02:00
|
|
|
props,
|
2018-03-29 02:02:01 +02:00
|
|
|
save_button: stub_save_button,
|
2019-03-07 15:18:10 +01:00
|
|
|
discard_button: stub_discard_button,
|
2018-03-29 02:02:01 +02:00
|
|
|
save_button_header: stub_save_button_header,
|
2020-07-20 22:18:43 +02:00
|
|
|
save_button_controls,
|
2018-03-29 02:02:01 +02:00
|
|
|
save_button_text: stub_save_button_text,
|
|
|
|
};
|
|
|
|
}
|
2018-04-16 18:58:27 +02:00
|
|
|
|
2017-08-18 01:23:55 +02:00
|
|
|
function test_submit_settings_form(submit_form) {
|
2019-05-05 15:49:37 +02:00
|
|
|
Object.assign(page_params, {
|
2020-04-01 08:30:41 +02:00
|
|
|
realm_bot_creation_policy: settings_bots.bot_creation_policy_values.restricted.code,
|
|
|
|
realm_email_address_visibility:
|
2020-07-15 00:34:28 +02:00
|
|
|
settings_config.email_address_visibility_values.admins_only.code,
|
2019-05-05 15:49:37 +02:00
|
|
|
realm_add_emoji_by_admins_only: true,
|
|
|
|
realm_create_stream_by_admins_only: true,
|
|
|
|
realm_waiting_period_threshold: 1,
|
|
|
|
realm_default_language: '"es"',
|
2020-04-01 08:30:41 +02:00
|
|
|
realm_default_twenty_four_hour_time: false,
|
|
|
|
realm_invite_to_stream_policy:
|
2020-07-15 00:34:28 +02:00
|
|
|
settings_config.invite_to_stream_policy_values.by_admins_only.code,
|
2020-04-01 08:30:41 +02:00
|
|
|
realm_create_stream_policy: settings_config.create_stream_policy_values.by_members.code,
|
2019-05-05 15:49:37 +02:00
|
|
|
});
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
set_global("setTimeout", (func) => func());
|
2018-04-16 18:58:27 +02:00
|
|
|
const ev = {
|
2017-06-16 14:41:10 +02:00
|
|
|
preventDefault: noop,
|
|
|
|
stopPropagation: noop,
|
|
|
|
};
|
|
|
|
|
2018-04-16 18:58:27 +02:00
|
|
|
let patched;
|
|
|
|
let data;
|
|
|
|
let success_callback;
|
|
|
|
channel.patch = (req) => {
|
2017-06-16 14:41:10 +02:00
|
|
|
patched = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(req.url, "/json/realm");
|
2018-04-16 18:58:27 +02:00
|
|
|
data = req.data;
|
2017-06-16 14:41:10 +02:00
|
|
|
success_callback = req.success;
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let subsection = "other-permissions";
|
2021-02-03 23:23:32 +01:00
|
|
|
ev.currentTarget = `#org-submit-${CSS.escape(subsection)}`;
|
2019-03-06 17:24:14 +01:00
|
|
|
let stubs = createSaveButtons(subsection);
|
2018-04-16 18:58:27 +02:00
|
|
|
let save_button = stubs.save_button;
|
2020-07-15 01:29:15 +02:00
|
|
|
save_button.attr("id", `org-submit-${subsection}`);
|
2020-07-02 01:41:40 +02:00
|
|
|
save_button.replace = () => `${subsection}`;
|
2020-01-23 07:01:34 +01:00
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
$("#id_realm_waiting_period_threshold").val(10);
|
2019-05-05 15:13:52 +02:00
|
|
|
|
2020-01-25 10:23:40 +01:00
|
|
|
const invite_to_stream_policy_elem = $("#id_realm_invite_to_stream_policy");
|
2020-07-15 01:29:15 +02:00
|
|
|
invite_to_stream_policy_elem.val("1");
|
|
|
|
invite_to_stream_policy_elem.attr("id", "id_realm_invite_to_stream_policy");
|
2020-07-02 01:41:40 +02:00
|
|
|
invite_to_stream_policy_elem.data = () => "number";
|
2020-01-25 10:23:40 +01:00
|
|
|
|
2020-01-23 07:01:34 +01:00
|
|
|
const create_stream_policy_elem = $("#id_realm_create_stream_policy");
|
2020-07-15 01:29:15 +02:00
|
|
|
create_stream_policy_elem.val("2");
|
|
|
|
create_stream_policy_elem.attr("id", "id_realm_create_stream_policy");
|
2020-07-02 01:41:40 +02:00
|
|
|
create_stream_policy_elem.data = () => "number";
|
2020-01-23 07:01:34 +01:00
|
|
|
|
2019-05-05 15:13:52 +02:00
|
|
|
const add_emoji_by_admins_only_elem = $("#id_realm_add_emoji_by_admins_only");
|
|
|
|
add_emoji_by_admins_only_elem.val("by_anyone");
|
2020-07-15 01:29:15 +02:00
|
|
|
add_emoji_by_admins_only_elem.attr("id", "id_realm_add_emoji_by_admins_only");
|
2019-05-05 15:13:52 +02:00
|
|
|
|
2019-03-06 17:24:14 +01:00
|
|
|
const bot_creation_policy_elem = $("#id_realm_bot_creation_policy");
|
|
|
|
bot_creation_policy_elem.val("1");
|
2020-07-15 01:29:15 +02:00
|
|
|
bot_creation_policy_elem.attr("id", "id_realm_bot_creation_policy");
|
2020-07-02 01:41:40 +02:00
|
|
|
bot_creation_policy_elem.data = () => "number";
|
2019-03-06 17:24:14 +01:00
|
|
|
const email_address_visibility_elem = $("#id_realm_email_address_visibility");
|
|
|
|
email_address_visibility_elem.val("1");
|
2020-07-15 01:29:15 +02:00
|
|
|
email_address_visibility_elem.attr("id", "id_realm_email_address_visibility");
|
2020-07-02 01:41:40 +02:00
|
|
|
email_address_visibility_elem.data = () => "number";
|
2019-03-06 17:24:14 +01:00
|
|
|
|
2021-02-03 23:23:32 +01:00
|
|
|
let subsection_elem = $(`#org-${CSS.escape(subsection)}`);
|
2019-05-05 15:13:52 +02:00
|
|
|
subsection_elem.closest = () => subsection_elem;
|
2020-07-15 01:29:15 +02:00
|
|
|
subsection_elem.set_find_results(".prop-element", [
|
2019-03-06 17:24:14 +01:00
|
|
|
bot_creation_policy_elem,
|
|
|
|
email_address_visibility_elem,
|
2019-05-05 15:13:52 +02:00
|
|
|
add_emoji_by_admins_only_elem,
|
2020-01-23 07:01:34 +01:00
|
|
|
create_stream_policy_elem,
|
2020-01-25 10:23:40 +01:00
|
|
|
invite_to_stream_policy_elem,
|
2019-03-06 17:24:14 +01:00
|
|
|
]);
|
2018-03-14 23:45:42 +01:00
|
|
|
|
2018-06-16 13:21:59 +02:00
|
|
|
patched = false;
|
2017-06-16 14:41:10 +02:00
|
|
|
submit_form(ev);
|
|
|
|
assert(patched);
|
|
|
|
|
2018-04-16 18:58:27 +02:00
|
|
|
let expected_value = {
|
2020-07-15 01:29:15 +02:00
|
|
|
bot_creation_policy: "1",
|
|
|
|
invite_to_stream_policy: "1",
|
|
|
|
email_address_visibility: "1",
|
2018-04-16 18:58:27 +02:00
|
|
|
add_emoji_by_admins_only: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
create_stream_policy: "2",
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
2018-04-16 18:58:27 +02:00
|
|
|
assert.deepEqual(data, expected_value);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
subsection = "user-defaults";
|
2021-02-03 23:23:32 +01:00
|
|
|
ev.currentTarget = `#org-submit-${CSS.escape(subsection)}`;
|
2019-03-06 17:24:14 +01:00
|
|
|
stubs = createSaveButtons(subsection);
|
2018-04-16 18:58:27 +02:00
|
|
|
save_button = stubs.save_button;
|
2020-07-15 01:29:15 +02:00
|
|
|
save_button.attr("id", `org-submit-${subsection}`);
|
2019-03-06 17:24:14 +01:00
|
|
|
|
|
|
|
const realm_default_language_elem = $("#id_realm_default_language");
|
|
|
|
realm_default_language_elem.val("en");
|
2020-07-15 01:29:15 +02:00
|
|
|
realm_default_language_elem.attr("id", "id_realm_default_language");
|
2020-07-02 01:41:40 +02:00
|
|
|
realm_default_language_elem.data = () => "string";
|
2019-03-06 17:24:14 +01:00
|
|
|
const realm_default_twenty_four_hour_time_elem = $("#id_realm_default_twenty_four_hour_time");
|
2020-07-15 01:29:15 +02:00
|
|
|
realm_default_twenty_four_hour_time_elem.val("true");
|
|
|
|
realm_default_twenty_four_hour_time_elem.attr("id", "id_realm_default_twenty_four_hour_time");
|
2020-07-02 01:41:40 +02:00
|
|
|
realm_default_twenty_four_hour_time_elem.data = () => "boolean";
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2021-02-03 23:23:32 +01:00
|
|
|
subsection_elem = $(`#org-${CSS.escape(subsection)}`);
|
2019-05-05 15:13:52 +02:00
|
|
|
subsection_elem.closest = () => subsection_elem;
|
2020-07-15 01:29:15 +02:00
|
|
|
subsection_elem.set_find_results(".prop-element", [
|
2019-03-06 17:24:14 +01:00
|
|
|
realm_default_language_elem,
|
|
|
|
realm_default_twenty_four_hour_time_elem,
|
|
|
|
]);
|
2018-04-16 18:58:27 +02:00
|
|
|
|
|
|
|
submit_form(ev);
|
|
|
|
assert(patched);
|
|
|
|
|
|
|
|
expected_value = {
|
|
|
|
default_language: '"en"',
|
2020-07-15 01:29:15 +02:00
|
|
|
default_twenty_four_hour_time: "true",
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
2018-04-16 18:58:27 +02:00
|
|
|
assert.deepEqual(data, expected_value);
|
|
|
|
|
|
|
|
// Testing only once for since callback is same for all cases
|
|
|
|
success_callback();
|
|
|
|
assert.equal(stubs.props.hidden, true);
|
|
|
|
assert.equal(save_button.attr("data-status"), "saved");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(stubs.save_button_text.text(), "translated: Saved");
|
2017-08-18 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
function test_change_save_button_state() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const {
|
2019-03-10 09:00:30 +01:00
|
|
|
save_button_controls,
|
|
|
|
save_button_text,
|
|
|
|
save_button,
|
|
|
|
discard_button,
|
|
|
|
props,
|
2020-07-15 01:29:15 +02:00
|
|
|
} = createSaveButtons("msg-editing");
|
2019-03-10 09:00:30 +01:00
|
|
|
save_button.attr("id", "org-submit-msg-editing");
|
|
|
|
|
|
|
|
{
|
|
|
|
settings_org.change_save_button_state(save_button_controls, "unsaved");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(save_button_text.text(), "translated: Save changes");
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(props.hidden, false);
|
|
|
|
assert.equal(save_button.attr("data-status"), "unsaved");
|
|
|
|
assert.equal(discard_button.visible(), true);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
settings_org.change_save_button_state(save_button_controls, "saved");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(save_button_text.text(), "translated: Save changes");
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(props.hidden, true);
|
|
|
|
assert.equal(save_button.attr("data-status"), "");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
settings_org.change_save_button_state(save_button_controls, "saving");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(save_button_text.text(), "translated: Saving");
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(save_button.attr("data-status"), "saving");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(save_button.hasClass("saving"), true);
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(discard_button.visible(), false);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
settings_org.change_save_button_state(save_button_controls, "discarded");
|
|
|
|
assert.equal(props.hidden, true);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
settings_org.change_save_button_state(save_button_controls, "succeeded");
|
|
|
|
assert.equal(props.hidden, true);
|
|
|
|
assert.equal(save_button.attr("data-status"), "saved");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(save_button_text.text(), "translated: Saved");
|
2019-03-10 09:00:30 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
settings_org.change_save_button_state(save_button_controls, "failed");
|
|
|
|
assert.equal(props.hidden, false);
|
|
|
|
assert.equal(save_button.attr("data-status"), "failed");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(save_button_text.text(), "translated: Save changes");
|
2019-03-10 09:00:30 +01:00
|
|
|
}
|
2018-03-29 02:02:01 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 01:04:12 +02:00
|
|
|
function test_upload_realm_icon(upload_realm_logo_or_icon) {
|
2018-08-01 21:17:03 +02:00
|
|
|
form_data = {
|
2020-07-20 22:18:43 +02:00
|
|
|
append(field, val) {
|
2017-06-16 14:41:10 +02:00
|
|
|
form_data[field] = val;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const file_input = [{files: ["image1.png", "image2.png"]}];
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let posted;
|
2021-02-23 14:37:26 +01:00
|
|
|
channel.post = (req) => {
|
2017-06-16 14:41:10 +02:00
|
|
|
posted = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(req.url, "/json/realm/icon");
|
|
|
|
assert.equal(req.data.csrfmiddlewaretoken, "token-stub");
|
|
|
|
assert.equal(req.data["file-0"], "image1.png");
|
|
|
|
assert.equal(req.data["file-1"], "image2.png");
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
|
|
|
|
2020-06-11 01:04:12 +02:00
|
|
|
upload_realm_logo_or_icon(file_input, null, true);
|
2017-06-16 14:41:10 +02:00
|
|
|
assert(posted);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_change_allow_subdomains(change_allow_subdomains) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const ev = {
|
2017-06-16 14:41:10 +02:00
|
|
|
stopPropagation: noop,
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const info = $(".realm_domains_info");
|
2018-04-28 21:34:57 +02:00
|
|
|
info.fadeOut = noop;
|
2020-07-15 01:29:15 +02:00
|
|
|
const domain = "example.com";
|
2019-11-02 00:06:25 +01:00
|
|
|
let allow = true;
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let success_callback;
|
|
|
|
let error_callback;
|
2021-02-23 14:37:26 +01:00
|
|
|
channel.patch = (req) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(req.url, "/json/realm/domains/example.com");
|
2017-06-16 14:41:10 +02:00
|
|
|
assert.equal(req.data.allow_subdomains, JSON.stringify(allow));
|
|
|
|
success_callback = req.success;
|
|
|
|
error_callback = req.error;
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const domain_obj = $.create("domain object");
|
2017-07-08 15:16:19 +02:00
|
|
|
domain_obj.text(domain);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const elem_obj = $.create("<elem html>");
|
|
|
|
const parents_obj = $.create("parents object");
|
2017-07-08 15:16:19 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
elem_obj.set_parents_result("tr", parents_obj);
|
|
|
|
parents_obj.set_find_results(".domain", domain_obj);
|
|
|
|
elem_obj.prop("checked", allow);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-02-12 01:35:16 +01:00
|
|
|
change_allow_subdomains.call(elem_obj, ev);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
success_callback();
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(info.val(), "translated: Update successful: Subdomains allowed for example.com");
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-12-25 17:49:46 +01:00
|
|
|
error_callback({});
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(info.val(), "translated: Failed");
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
allow = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
elem_obj.prop("checked", allow);
|
2020-02-12 01:35:16 +01:00
|
|
|
change_allow_subdomains.call(elem_obj, ev);
|
2017-06-16 14:41:10 +02:00
|
|
|
success_callback();
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
info.val(),
|
|
|
|
"translated: Update successful: Subdomains no longer allowed for example.com",
|
|
|
|
);
|
2017-06-16 14:41:10 +02:00
|
|
|
}
|
|
|
|
|
2018-03-14 23:50:17 +01:00
|
|
|
function test_extract_property_name() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#id_realm_allow_message_editing").attr("id", "id_realm_allow_message_editing");
|
2018-03-14 23:50:17 +01:00
|
|
|
assert.equal(
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.extract_property_name($("#id_realm_allow_message_editing")),
|
|
|
|
"realm_allow_message_editing",
|
2018-03-14 23:50:17 +01:00
|
|
|
);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#id_realm_message_content_edit_limit_minutes_label").attr(
|
2020-07-15 00:34:28 +02:00
|
|
|
"id",
|
|
|
|
"id_realm_message_content_edit_limit_minutes_label",
|
|
|
|
);
|
2018-03-14 23:50:17 +01:00
|
|
|
assert.equal(
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.extract_property_name($("#id_realm_message_content_edit_limit_minutes_label")),
|
|
|
|
"realm_message_content_edit_limit_minutes_label",
|
2018-03-14 23:50:17 +01:00
|
|
|
);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#id-realm-allow-message-deleting").attr("id", "id-realm-allow-message-deleting");
|
2018-03-14 23:50:17 +01:00
|
|
|
assert.equal(
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.extract_property_name($("#id-realm-allow-message-deleting")),
|
|
|
|
"realm_allow_message_deleting",
|
2018-03-14 23:50:17 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-16 18:58:27 +02:00
|
|
|
function test_sync_realm_settings() {
|
|
|
|
overlays.settings_open = () => true;
|
|
|
|
|
2018-06-16 13:21:59 +02:00
|
|
|
{
|
2018-06-16 17:25:27 +02:00
|
|
|
/* Test invalid settings property sync */
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_invalid_settings_property");
|
|
|
|
property_elem.attr("id", "id_realm_invalid_settings_property");
|
2018-06-16 17:25:27 +02:00
|
|
|
property_elem.length = 1;
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
blueslip.expect(
|
|
|
|
"error",
|
|
|
|
"Element refers to unknown property realm_invalid_settings_property",
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("invalid_settings_property");
|
2018-06-16 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-05-07 19:06:05 +02:00
|
|
|
/*
|
|
|
|
Test that when create stream policy is set to "full members" that the dropdown
|
|
|
|
is set to the correct value.
|
|
|
|
*/
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_create_stream_policy");
|
2018-06-16 13:21:59 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_create_stream_policy");
|
2018-04-16 18:58:27 +02:00
|
|
|
|
2019-05-06 16:34:31 +02:00
|
|
|
page_params.realm_create_stream_policy = 3;
|
2018-04-16 18:58:27 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("create_stream_policy");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#id_realm_create_stream_policy").val(),
|
|
|
|
settings_config.create_stream_policy_values.by_full_members.code,
|
|
|
|
);
|
2019-05-07 19:06:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Test that when create stream policy is set to "by members" that the dropdown
|
|
|
|
is set to the correct value.
|
|
|
|
*/
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_create_stream_policy");
|
2019-05-07 19:06:05 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_create_stream_policy");
|
2019-05-07 19:06:05 +02:00
|
|
|
|
|
|
|
page_params.realm_create_stream_policy = 1;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("create_stream_policy");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#id_realm_create_stream_policy").val(),
|
|
|
|
settings_config.create_stream_policy_values.by_members.code,
|
|
|
|
);
|
2019-05-07 19:06:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Test that when create stream policy is set to "by admins only" that the dropdown
|
|
|
|
is set to the correct value.
|
|
|
|
*/
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_create_stream_policy");
|
2019-05-07 19:06:05 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_create_stream_policy");
|
2019-05-07 19:06:05 +02:00
|
|
|
|
|
|
|
page_params.realm_create_stream_policy = 2;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("create_stream_policy");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#id_realm_create_stream_policy").val(),
|
|
|
|
settings_config.create_stream_policy_values.by_admins_only.code,
|
|
|
|
);
|
2018-06-16 13:21:59 +02:00
|
|
|
}
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2019-04-08 19:23:00 +02:00
|
|
|
{
|
2019-05-07 19:06:05 +02:00
|
|
|
/*
|
|
|
|
Test that when invite to stream policy is set to "full members" that the dropdown
|
|
|
|
is set to the correct value.
|
|
|
|
*/
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_invite_to_stream_policy");
|
2019-04-08 19:23:00 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_invite_to_stream_policy");
|
2019-04-08 19:23:00 +02:00
|
|
|
|
|
|
|
page_params.realm_invite_to_stream_policy = 3;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("invite_to_stream_policy");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#id_realm_invite_to_stream_policy").val(),
|
|
|
|
settings_config.create_stream_policy_values.by_full_members.code,
|
|
|
|
);
|
2019-05-07 19:06:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Test that when create stream policy is set to "by members" that the dropdown
|
|
|
|
is set to the correct value.
|
|
|
|
*/
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_invite_to_stream_policy");
|
2019-05-07 19:06:05 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_invite_to_stream_policy");
|
2019-05-07 19:06:05 +02:00
|
|
|
|
|
|
|
page_params.realm_invite_to_stream_policy = 1;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("invite_to_stream_policy");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#id_realm_invite_to_stream_policy").val(),
|
|
|
|
settings_config.create_stream_policy_values.by_members.code,
|
|
|
|
);
|
2019-05-07 19:06:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Test that when create stream policy is set to "by admins only" that the dropdown
|
|
|
|
is set to the correct value.
|
|
|
|
*/
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_invite_to_stream_policy");
|
2019-05-07 19:06:05 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_invite_to_stream_policy");
|
2019-05-07 19:06:05 +02:00
|
|
|
|
|
|
|
page_params.realm_invite_to_stream_policy = 2;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("invite_to_stream_policy");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#id_realm_invite_to_stream_policy").val(),
|
|
|
|
settings_config.create_stream_policy_values.by_admins_only.code,
|
|
|
|
);
|
2019-04-08 19:23:00 +02:00
|
|
|
}
|
|
|
|
|
2018-06-16 17:25:27 +02:00
|
|
|
{
|
|
|
|
/* Test message content edit limit minutes sync */
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_message_content_edit_limit_minutes");
|
2018-06-16 17:25:27 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2019-05-06 16:34:31 +02:00
|
|
|
page_params.realm_create_stream_policy = 1;
|
2018-06-16 17:25:27 +02:00
|
|
|
page_params.realm_message_content_edit_limit_seconds = 120;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("message_content_edit_limit_seconds");
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal($("#id_realm_message_content_edit_limit_minutes").val(), "2");
|
2018-06-16 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Test message content edit limit dropdown value sync */
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_msg_edit_limit_setting");
|
2018-06-16 17:25:27 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_msg_edit_limit_setting");
|
2018-06-16 17:25:27 +02:00
|
|
|
|
|
|
|
page_params.realm_allow_message_editing = false;
|
|
|
|
page_params.realm_message_content_edit_limit_seconds = 120;
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("allow_message_editing");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_msg_edit_limit_setting").val(), "never");
|
|
|
|
|
|
|
|
page_params.realm_allow_message_editing = true;
|
|
|
|
|
|
|
|
page_params.realm_message_content_edit_limit_seconds = 120;
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("allow_message_editing");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_msg_edit_limit_setting").val(), "upto_two_min");
|
|
|
|
|
|
|
|
page_params.realm_message_content_edit_limit_seconds = 130;
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("allow_message_editing");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_msg_edit_limit_setting").val(), "custom_limit");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Test message content edit limit minutes sync */
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_message_content_edit_limit_minutes");
|
2018-06-16 17:25:27 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2019-05-06 16:34:31 +02:00
|
|
|
page_params.realm_create_stream_policy = 1;
|
2018-06-16 17:25:27 +02:00
|
|
|
page_params.realm_message_content_edit_limit_seconds = 120;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("message_content_edit_limit_seconds");
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal($("#id_realm_message_content_edit_limit_minutes").val(), "2");
|
2018-06-16 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Test organization joining restrictions settings sync */
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_elem = $("#id_realm_org_join_restrictions");
|
2018-06-16 17:25:27 +02:00
|
|
|
property_elem.length = 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
property_elem.attr("id", "id_realm_org_join_restrictions");
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2018-07-27 23:26:29 +02:00
|
|
|
page_params.realm_emails_restricted_to_domains = true;
|
2018-06-16 17:25:27 +02:00
|
|
|
page_params.realm_disallow_disposable_email_addresses = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_org_join_restrictions").val(), "only_selected_domain");
|
|
|
|
|
2018-07-27 23:26:29 +02:00
|
|
|
page_params.realm_emails_restricted_to_domains = false;
|
2018-06-16 17:25:27 +02:00
|
|
|
|
|
|
|
page_params.realm_disallow_disposable_email_addresses = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_org_join_restrictions").val(), "no_disposable_email");
|
|
|
|
|
|
|
|
page_params.realm_disallow_disposable_email_addresses = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_org_join_restrictions").val(), "no_restriction");
|
|
|
|
}
|
2018-04-16 18:58:27 +02:00
|
|
|
}
|
|
|
|
|
2018-04-28 15:35:14 +02:00
|
|
|
function test_parse_time_limit() {
|
2020-07-15 01:29:15 +02:00
|
|
|
const elem = $("#id_realm_message_content_edit_limit_minutes");
|
2018-04-28 15:35:14 +02:00
|
|
|
const test_function = (value, expected_value = value) => {
|
|
|
|
elem.val(value);
|
2020-12-01 00:57:57 +01:00
|
|
|
page_params.realm_message_content_edit_limit_seconds = settings_org.parse_time_limit(elem);
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
settings_org.get_realm_time_limits_in_minutes(
|
|
|
|
"realm_message_content_edit_limit_seconds",
|
|
|
|
),
|
2020-07-28 17:00:59 +02:00
|
|
|
expected_value,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2018-04-28 15:35:14 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
test_function("0.01", "0");
|
|
|
|
test_function("0.1");
|
|
|
|
test_function("0.122", "0.1");
|
|
|
|
test_function("0.155", "0.2");
|
|
|
|
test_function("0.150", "0.1");
|
|
|
|
test_function("0.5");
|
|
|
|
test_function("1");
|
|
|
|
test_function("1.1");
|
|
|
|
test_function("10.5");
|
|
|
|
test_function("50.3");
|
|
|
|
test_function("100");
|
|
|
|
test_function("100.1");
|
|
|
|
test_function("127.79", "127.8");
|
|
|
|
test_function("201.1");
|
|
|
|
test_function("501.15", "501.1");
|
|
|
|
test_function("501.34", "501.3");
|
2018-04-28 15:35:14 +02:00
|
|
|
}
|
|
|
|
|
2018-06-16 17:25:27 +02:00
|
|
|
function test_discard_changes_button(discard_changes) {
|
|
|
|
const ev = {
|
|
|
|
preventDefault: noop,
|
|
|
|
stopPropagation: noop,
|
2020-07-15 01:29:15 +02:00
|
|
|
target: "#org-discard-msg-editing",
|
2018-06-16 17:25:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
page_params.realm_allow_edit_history = true;
|
|
|
|
page_params.realm_allow_community_topic_editing = true;
|
|
|
|
page_params.realm_allow_message_editing = true;
|
|
|
|
page_params.realm_message_content_edit_limit_seconds = 3600;
|
|
|
|
page_params.realm_allow_message_deleting = true;
|
|
|
|
page_params.realm_message_content_delete_limit_seconds = 120;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const allow_edit_history = $("#id_realm_allow_edit_history").prop("checked", false);
|
2020-07-15 00:34:28 +02:00
|
|
|
const allow_community_topic_editing = $("#id_realm_allow_community_topic_editing").prop(
|
|
|
|
"checked",
|
|
|
|
true,
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
const msg_edit_limit_setting = $("#id_realm_msg_edit_limit_setting").val("custom_limit");
|
2020-07-15 00:34:28 +02:00
|
|
|
const message_content_edit_limit_minutes = $(
|
|
|
|
"#id_realm_message_content_edit_limit_minutes",
|
|
|
|
).val(130);
|
2020-07-15 01:29:15 +02:00
|
|
|
const msg_delete_limit_setting = $("#id_realm_msg_delete_limit_setting").val("custom_limit");
|
2020-07-15 00:34:28 +02:00
|
|
|
const message_content_delete_limit_minutes = $(
|
|
|
|
"#id_realm_message_content_delete_limit_minutes",
|
|
|
|
).val(130);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
|
|
|
allow_edit_history.attr("id", "id_realm_allow_edit_history");
|
|
|
|
msg_edit_limit_setting.attr("id", "id_realm_msg_edit_limit_setting");
|
|
|
|
msg_delete_limit_setting.attr("id", "id_realm_msg_delete_limit_setting");
|
|
|
|
allow_community_topic_editing.attr("id", "id_realm_allow_community_topic_editing");
|
|
|
|
message_content_edit_limit_minutes.attr("id", "id_realm_message_content_edit_limit_minutes");
|
2020-07-15 00:34:28 +02:00
|
|
|
message_content_delete_limit_minutes.attr(
|
|
|
|
"id",
|
|
|
|
"id_realm_message_content_delete_limit_minutes",
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
|
|
|
const discard_button_parent = $(".org-subsection-parent");
|
2018-06-16 17:25:27 +02:00
|
|
|
discard_button_parent.find = () => [
|
|
|
|
allow_edit_history,
|
|
|
|
msg_edit_limit_setting,
|
|
|
|
msg_delete_limit_setting,
|
|
|
|
allow_community_topic_editing,
|
|
|
|
message_content_edit_limit_minutes,
|
|
|
|
message_content_delete_limit_minutes,
|
|
|
|
];
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#org-discard-msg-editing").closest = () => discard_button_parent;
|
2018-06-16 17:25:27 +02:00
|
|
|
|
|
|
|
const stubbed_function = settings_org.change_save_button_state;
|
2019-03-10 09:00:30 +01:00
|
|
|
settings_org.change_save_button_state = (save_button_controls, state) => {
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal(state, "discarded");
|
|
|
|
};
|
|
|
|
|
|
|
|
discard_changes(ev);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(allow_edit_history.prop("checked"), true);
|
|
|
|
assert.equal(allow_community_topic_editing.prop("checked"), true);
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal(msg_edit_limit_setting.val(), "upto_one_hour");
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal(message_content_edit_limit_minutes.val(), "60");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal(msg_delete_limit_setting.val(), "upto_two_min");
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal(message_content_delete_limit_minutes.val(), "2");
|
2018-06-16 17:25:27 +02:00
|
|
|
|
|
|
|
settings_org.change_save_button_state = stubbed_function;
|
|
|
|
}
|
|
|
|
|
2020-07-26 16:38:46 +02:00
|
|
|
run_test("set_up", (override) => {
|
2018-06-16 17:25:27 +02:00
|
|
|
const verify_realm_domains = simulate_realm_domains_table();
|
2019-05-09 09:54:38 +02:00
|
|
|
page_params.realm_available_video_chat_providers = {
|
|
|
|
jitsi_meet: {
|
|
|
|
id: 1,
|
|
|
|
name: "Jitsi Meet",
|
|
|
|
},
|
|
|
|
zoom: {
|
|
|
|
id: 3,
|
|
|
|
name: "Zoom",
|
|
|
|
},
|
2020-04-27 22:41:31 +02:00
|
|
|
big_blue_button: {
|
|
|
|
id: 4,
|
|
|
|
name: "Big Blue Button",
|
|
|
|
},
|
2019-05-09 09:54:38 +02:00
|
|
|
};
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-06-11 01:04:12 +02:00
|
|
|
let upload_realm_logo_or_icon;
|
2021-02-23 14:37:26 +01:00
|
|
|
realm_icon.build_realm_icon_widget = (f) => {
|
2020-06-11 01:04:12 +02:00
|
|
|
upload_realm_logo_or_icon = f;
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
|
|
|
|
2020-05-12 20:44:05 +02:00
|
|
|
const dropdown_list_widget_backup = dropdown_list_widget;
|
2020-07-02 01:41:40 +02:00
|
|
|
window.dropdown_list_widget = () => ({
|
|
|
|
render: noop,
|
|
|
|
update: noop,
|
|
|
|
});
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#id_realm_message_content_edit_limit_minutes").set_parent(
|
|
|
|
$.create("<stub edit limit parent>"),
|
|
|
|
);
|
|
|
|
$("#id_realm_message_content_delete_limit_minutes").set_parent(
|
|
|
|
$.create("<stub delete limit parent>"),
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#id_realm_message_retention_days").set_parent($.create("<stub retention period parent>"));
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#message_content_in_email_notifications_label").set_parent(
|
|
|
|
$.create("<stub in-content setting checkbox>"),
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#enable_digest_emails_label").set_parent($.create("<stub digest setting checkbox>"));
|
|
|
|
$("#id_realm_digest_weekday").set_parent($.create("<stub digest weekday setting dropdown>"));
|
|
|
|
$("#allowed_domains_label").set_parent($.create("<stub-allowed-domain-label-parent>"));
|
|
|
|
const waiting_period_parent_elem = $.create("waiting-period-parent-stub");
|
|
|
|
$("#id_realm_waiting_period_threshold").set_parent(waiting_period_parent_elem);
|
2018-08-18 12:31:21 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const allow_topic_edit_label_parent = $.create("allow-topic-edit-label-parent");
|
|
|
|
$("#id_realm_allow_community_topic_editing_label").set_parent(allow_topic_edit_label_parent);
|
2018-08-18 12:31:21 +02:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
channel.get = (opts) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(opts.url, "/json/export/realm");
|
2019-04-09 21:49:07 +02:00
|
|
|
};
|
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
// TEST set_up() here, but this mostly just allows us to
|
|
|
|
// get access to the click handlers.
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_org, "maybe_disable_widgets", noop);
|
2017-06-16 14:41:10 +02:00
|
|
|
settings_org.set_up();
|
|
|
|
|
|
|
|
verify_realm_domains();
|
|
|
|
|
2020-07-21 00:23:06 +02:00
|
|
|
test_realms_domain_modal(() => $("#submit-add-realm-domain").trigger("click"));
|
|
|
|
test_submit_settings_form(
|
|
|
|
$(".organization").get_on_handler(
|
|
|
|
"click",
|
|
|
|
".subsection-header .subsection-changes-save .button",
|
|
|
|
),
|
|
|
|
);
|
2020-06-11 01:04:12 +02:00
|
|
|
test_upload_realm_icon(upload_realm_logo_or_icon);
|
2020-07-21 00:23:06 +02:00
|
|
|
test_change_allow_subdomains(
|
|
|
|
$("#realm_domains_table").get_on_handler("change", ".allow-subdomains"),
|
|
|
|
);
|
2018-03-14 23:50:17 +01:00
|
|
|
test_extract_property_name();
|
2018-03-29 02:02:01 +02:00
|
|
|
test_change_save_button_state();
|
2018-04-16 18:58:27 +02:00
|
|
|
test_sync_realm_settings();
|
2018-04-28 15:35:14 +02:00
|
|
|
test_parse_time_limit();
|
2020-07-21 00:23:06 +02:00
|
|
|
test_discard_changes_button(
|
|
|
|
$(".organization").get_on_handler(
|
|
|
|
"click",
|
|
|
|
".subsection-header .subsection-changes-discard .button",
|
|
|
|
),
|
|
|
|
);
|
2018-04-16 14:55:23 +02:00
|
|
|
|
2020-05-27 00:44:14 +02:00
|
|
|
window.dropdown_list_widget = dropdown_list_widget_backup;
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("test get_organization_settings_options", () => {
|
2020-01-23 07:01:34 +01:00
|
|
|
const sorted_option_values = settings_org.get_organization_settings_options();
|
|
|
|
const sorted_create_stream_policy_values = sorted_option_values.create_stream_policy_values;
|
|
|
|
const expected_create_stream_policy_values = [
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_admins_only",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 1,
|
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Admins"),
|
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_full_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 2,
|
|
|
|
code: 3,
|
|
|
|
description: i18n.t("Admins and full members"),
|
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 3,
|
|
|
|
code: 1,
|
|
|
|
description: i18n.t("Admins and members"),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
assert.deepEqual(sorted_create_stream_policy_values, expected_create_stream_policy_values);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("test get_sorted_options_list", () => {
|
2020-01-23 07:01:34 +01:00
|
|
|
const option_values_1 = {
|
|
|
|
by_admins_only: {
|
|
|
|
order: 3,
|
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Admins"),
|
|
|
|
},
|
|
|
|
by_members: {
|
|
|
|
order: 2,
|
|
|
|
code: 1,
|
|
|
|
description: i18n.t("Admins and members"),
|
|
|
|
},
|
|
|
|
by_full_members: {
|
|
|
|
order: 1,
|
|
|
|
code: 3,
|
|
|
|
description: i18n.t("Admins and full members"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
let expected_option_values = [
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_full_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 1,
|
|
|
|
code: 3,
|
|
|
|
description: i18n.t("Admins and full members"),
|
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 2,
|
|
|
|
code: 1,
|
|
|
|
description: i18n.t("Admins and members"),
|
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_admins_only",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 3,
|
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Admins"),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
assert.deepEqual(settings_org.get_sorted_options_list(option_values_1), expected_option_values);
|
|
|
|
|
|
|
|
const option_values_2 = {
|
|
|
|
by_admins_only: {
|
|
|
|
code: 1,
|
|
|
|
description: i18n.t("Admins"),
|
|
|
|
},
|
|
|
|
by_members: {
|
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Admins and members"),
|
|
|
|
},
|
|
|
|
by_full_members: {
|
|
|
|
code: 3,
|
|
|
|
description: i18n.t("Admins and full members"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
expected_option_values = [
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_admins_only",
|
2020-01-23 07:01:34 +01:00
|
|
|
code: 1,
|
|
|
|
description: i18n.t("Admins"),
|
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_full_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
code: 3,
|
|
|
|
description: i18n.t("Admins and full members"),
|
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Admins and members"),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
assert.deepEqual(settings_org.get_sorted_options_list(option_values_2), expected_option_values);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("misc", () => {
|
2018-02-02 16:54:26 +01:00
|
|
|
page_params.is_admin = false;
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const stub_notification_disable_parent = $.create("<stub notification_disable parent");
|
2020-07-15 00:34:28 +02:00
|
|
|
stub_notification_disable_parent.set_find_results(
|
2020-10-30 00:26:54 +01:00
|
|
|
".dropdown_list_reset_button:enabled",
|
2020-07-15 00:34:28 +02:00
|
|
|
$.create("<disable link>"),
|
|
|
|
);
|
2018-04-03 22:25:18 +02:00
|
|
|
|
2018-03-02 21:26:59 +01:00
|
|
|
page_params.realm_name_changes_disabled = false;
|
2019-05-03 08:09:03 +02:00
|
|
|
page_params.server_name_changes_disabled = false;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert(!$("#full_name").prop("disabled"));
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($(".change_name_tooltip").is(":visible"), false);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-03-02 21:26:59 +01:00
|
|
|
page_params.realm_name_changes_disabled = true;
|
2019-05-03 08:09:03 +02:00
|
|
|
page_params.server_name_changes_disabled = false;
|
|
|
|
settings_account.update_name_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert($("#full_name").prop("disabled"));
|
2020-07-15 01:29:15 +02:00
|
|
|
assert($(".change_name_tooltip").is(":visible"));
|
2019-05-03 08:09:03 +02:00
|
|
|
|
|
|
|
page_params.realm_name_changes_disabled = true;
|
|
|
|
page_params.server_name_changes_disabled = true;
|
|
|
|
settings_account.update_name_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert($("#full_name").prop("disabled"));
|
2020-07-15 01:29:15 +02:00
|
|
|
assert($(".change_name_tooltip").is(":visible"));
|
2019-05-03 08:09:03 +02:00
|
|
|
|
|
|
|
page_params.realm_name_changes_disabled = false;
|
|
|
|
page_params.server_name_changes_disabled = true;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert($("#full_name").prop("disabled"));
|
2020-07-15 01:29:15 +02:00
|
|
|
assert($(".change_name_tooltip").is(":visible"));
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-03-02 21:26:59 +01:00
|
|
|
page_params.realm_email_changes_disabled = false;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert(!$("#change_email .button").prop("disabled"));
|
2018-01-04 13:02:17 +01:00
|
|
|
|
2018-03-02 21:26:59 +01:00
|
|
|
page_params.realm_email_changes_disabled = true;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert($("#change_email .button").prop("disabled"));
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2019-04-23 04:51:04 +02:00
|
|
|
page_params.realm_avatar_changes_disabled = false;
|
2019-04-29 08:41:00 +02:00
|
|
|
page_params.server_avatar_changes_disabled = false;
|
2019-04-23 04:51:04 +02:00
|
|
|
settings_account.update_avatar_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert(!$("#user-avatar-upload-widget .image_upload_button").prop("disabled"));
|
|
|
|
assert(!$("#user-avatar-upload-widget .image-delete-button .button").prop("disabled"));
|
2019-04-23 04:51:04 +02:00
|
|
|
page_params.realm_avatar_changes_disabled = true;
|
2019-04-29 08:41:00 +02:00
|
|
|
page_params.server_avatar_changes_disabled = false;
|
|
|
|
settings_account.update_avatar_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert($("#user-avatar-upload-widget .image_upload_button").prop("disabled"));
|
|
|
|
assert($("#user-avatar-upload-widget .image-delete-button .button").prop("disabled"));
|
2019-04-29 08:41:00 +02:00
|
|
|
page_params.realm_avatar_changes_disabled = false;
|
|
|
|
page_params.server_avatar_changes_disabled = true;
|
|
|
|
settings_account.update_avatar_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert($("#user-avatar-upload-widget .image_upload_button").prop("disabled"));
|
|
|
|
assert($("#user-avatar-upload-widget .image-delete-button .button").prop("disabled"));
|
2019-04-29 08:41:00 +02:00
|
|
|
page_params.realm_avatar_changes_disabled = true;
|
|
|
|
page_params.server_avatar_changes_disabled = true;
|
2019-04-23 04:51:04 +02:00
|
|
|
settings_account.update_avatar_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert($("#user-avatar-upload-widget .image_upload_button").prop("disabled"));
|
|
|
|
assert($("#user-avatar-upload-widget .image-delete-button .button").prop("disabled"));
|
2019-04-23 04:51:04 +02:00
|
|
|
|
2018-03-02 21:44:14 +01:00
|
|
|
// If organization admin, these UI elements are never disabled.
|
2018-02-02 16:54:26 +01:00
|
|
|
page_params.is_admin = true;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert(!$("#full_name").prop("disabled"));
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($(".change_name_tooltip").is(":visible"), false);
|
2018-02-02 16:54:26 +01:00
|
|
|
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2020-07-22 02:59:06 +02:00
|
|
|
assert(!$("#change_email .button").prop("disabled"));
|
2018-02-02 16:54:26 +01:00
|
|
|
|
2021-01-23 02:46:57 +01:00
|
|
|
stream_data.get_streams_for_settings_page = () => [
|
|
|
|
{name: "some_stream", stream_id: 75},
|
|
|
|
{name: "some_stream", stream_id: 42},
|
|
|
|
];
|
2020-04-15 04:29:15 +02:00
|
|
|
|
2020-05-12 20:44:05 +02:00
|
|
|
// Set stubs for dropdown_list_widget:
|
2020-07-15 00:34:28 +02:00
|
|
|
const widget_settings = [
|
|
|
|
"realm_notifications_stream_id",
|
|
|
|
"realm_signup_notifications_stream_id",
|
|
|
|
"realm_default_code_block_language",
|
|
|
|
];
|
2020-07-15 01:29:15 +02:00
|
|
|
const dropdown_list_parent = $.create("<list parent>");
|
2020-07-15 00:34:28 +02:00
|
|
|
dropdown_list_parent.set_find_results(
|
2020-10-30 00:26:54 +01:00
|
|
|
".dropdown_list_reset_button:enabled",
|
2020-07-15 00:34:28 +02:00
|
|
|
$.create("<disable button>"),
|
|
|
|
);
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const name of widget_settings) {
|
2021-02-03 23:23:32 +01:00
|
|
|
const elem = $.create(`#${CSS.escape(name)}_widget #${CSS.escape(name)}_name`);
|
2020-07-02 01:41:40 +02:00
|
|
|
elem.closest = () => dropdown_list_parent;
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2020-04-15 04:29:15 +02:00
|
|
|
|
2020-05-19 00:16:34 +02:00
|
|
|
// We do not define any settings we need in page_params yet, but we don't need to for this test.
|
2020-07-15 00:34:28 +02:00
|
|
|
blueslip.expect(
|
|
|
|
"warn",
|
|
|
|
"dropdown-list-widget: Called without a default value; using null value",
|
|
|
|
3,
|
|
|
|
);
|
2020-04-10 09:38:55 +02:00
|
|
|
settings_org.init_dropdown_widgets();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let setting_name = "realm_notifications_stream_id";
|
2021-02-03 23:23:32 +01:00
|
|
|
let elem = $(`#${CSS.escape(setting_name)}_widget #${CSS.escape(setting_name)}_name`);
|
2021-02-23 14:37:26 +01:00
|
|
|
elem.closest = () => stub_notification_disable_parent;
|
|
|
|
stream_data.get_sub_by_id = (stream_id) => {
|
2017-06-16 14:41:10 +02:00
|
|
|
assert.equal(stream_id, 42);
|
2020-07-16 22:40:18 +02:00
|
|
|
return {name: "some_stream"};
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
2020-04-10 09:38:55 +02:00
|
|
|
settings_org.notifications_stream_widget.render(42);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(elem.text(), "#some_stream");
|
|
|
|
assert(!elem.hasClass("text-warning"));
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-04-10 09:38:55 +02:00
|
|
|
settings_org.notifications_stream_widget.render(undefined);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(elem.text(), "translated: Disabled");
|
|
|
|
assert(elem.hasClass("text-warning"));
|
2017-10-20 16:55:04 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
setting_name = "realm_signup_notifications_stream_id";
|
2021-02-03 23:23:32 +01:00
|
|
|
elem = $(`#${CSS.escape(setting_name)}_widget #${CSS.escape(setting_name)}_name`);
|
2021-02-23 14:37:26 +01:00
|
|
|
elem.closest = () => stub_notification_disable_parent;
|
|
|
|
stream_data.get_sub_by_id = (stream_id) => {
|
2017-10-20 16:55:04 +02:00
|
|
|
assert.equal(stream_id, 75);
|
2020-07-16 22:40:18 +02:00
|
|
|
return {name: "some_stream"};
|
2017-10-20 16:55:04 +02:00
|
|
|
};
|
2020-04-10 09:38:55 +02:00
|
|
|
settings_org.signup_notifications_stream_widget.render(75);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(elem.text(), "#some_stream");
|
|
|
|
assert(!elem.hasClass("text-warning"));
|
2017-10-20 16:55:04 +02:00
|
|
|
|
2020-04-10 09:38:55 +02:00
|
|
|
settings_org.signup_notifications_stream_widget.render(undefined);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(elem.text(), "translated: Disabled");
|
|
|
|
assert(elem.hasClass("text-warning"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|