mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
node tests: Use mock_template in settings_profile_fields.
This commit is contained in:
committed by
Steve Howell
parent
30023d4b76
commit
de6988b16d
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {stub_templates} = require("../zjsunit/handlebars");
|
const {mock_cjs, mock_esm, zrequire, mock_template} = require("../zjsunit/namespace");
|
||||||
const {mock_cjs, mock_esm, zrequire} = require("../zjsunit/namespace");
|
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const $ = require("../zjsunit/zjquery");
|
const $ = require("../zjsunit/zjquery");
|
||||||
const {page_params} = require("../zjsunit/zpage_params");
|
const {page_params} = require("../zjsunit/zpage_params");
|
||||||
|
|
||||||
mock_cjs("jquery", $);
|
mock_cjs("jquery", $);
|
||||||
|
const render_admin_profile_field_list = mock_template("settings/admin_profile_field_list.hbs");
|
||||||
const loading = mock_esm("../../static/js/loading");
|
const loading = mock_esm("../../static/js/loading");
|
||||||
|
|
||||||
const SHORT_TEXT_ID = 1;
|
const SHORT_TEXT_ID = 1;
|
||||||
@@ -41,7 +41,7 @@ mock_esm("sortablejs", {Sortable: {create: () => {}}});
|
|||||||
|
|
||||||
const settings_profile_fields = zrequire("settings_profile_fields");
|
const settings_profile_fields = zrequire("settings_profile_fields");
|
||||||
|
|
||||||
function test_populate(opts) {
|
function test_populate(opts, template_data) {
|
||||||
const fields_data = opts.fields_data;
|
const fields_data = opts.fields_data;
|
||||||
|
|
||||||
page_params.is_admin = opts.is_admin;
|
page_params.is_admin = opts.is_admin;
|
||||||
@@ -63,23 +63,22 @@ function test_populate(opts) {
|
|||||||
|
|
||||||
loading.destroy_indicator = () => {};
|
loading.destroy_indicator = () => {};
|
||||||
|
|
||||||
const template_data = [];
|
|
||||||
stub_templates((fn, data) => {
|
|
||||||
assert.equal(fn, "settings/admin_profile_field_list");
|
|
||||||
template_data.push(data);
|
|
||||||
return "whatever";
|
|
||||||
});
|
|
||||||
|
|
||||||
settings_profile_fields.do_populate_profile_fields(fields_data);
|
settings_profile_fields.do_populate_profile_fields(fields_data);
|
||||||
|
|
||||||
assert.deepEqual(template_data, opts.expected_template_data);
|
assert.deepEqual(template_data, opts.expected_template_data);
|
||||||
assert.equal(num_appends, fields_data.length);
|
assert.equal(num_appends, fields_data.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("populate_profile_fields", () => {
|
run_test("populate_profile_fields", (override) => {
|
||||||
page_params.custom_profile_fields = {};
|
page_params.custom_profile_fields = {};
|
||||||
page_params.realm_default_external_accounts = JSON.stringify({});
|
page_params.realm_default_external_accounts = JSON.stringify({});
|
||||||
|
|
||||||
|
const template_data = [];
|
||||||
|
override(render_admin_profile_field_list, "f", (data) => {
|
||||||
|
template_data.push(data);
|
||||||
|
return "whatever";
|
||||||
|
});
|
||||||
|
|
||||||
const fields_data = [
|
const fields_data = [
|
||||||
{
|
{
|
||||||
type: SHORT_TEXT_ID,
|
type: SHORT_TEXT_ID,
|
||||||
@@ -182,9 +181,12 @@ run_test("populate_profile_fields", () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
test_populate({
|
test_populate(
|
||||||
fields_data,
|
{
|
||||||
expected_template_data,
|
fields_data,
|
||||||
is_admin: true,
|
expected_template_data,
|
||||||
});
|
is_admin: true,
|
||||||
|
},
|
||||||
|
template_data,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user