snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
215
web/tests/settings_profile_fields.test.cjs
Normal file
215
web/tests/settings_profile_fields.test.cjs
Normal file
@@ -0,0 +1,215 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {make_realm} = require("./lib/example_realm.cjs");
|
||||
const {mock_esm, with_overrides, zrequire} = require("./lib/namespace.cjs");
|
||||
const {run_test, noop} = require("./lib/test.cjs");
|
||||
|
||||
const loading = mock_esm("../src/loading");
|
||||
|
||||
const SHORT_TEXT_ID = 1;
|
||||
|
||||
const DROPDOWN_ID = 3;
|
||||
const EXTERNAL_ACCOUNT_ID = 7;
|
||||
const PARAGRAPH_ID = 2;
|
||||
const USER_FIELD_ID = 6;
|
||||
|
||||
const SHORT_TEXT_NAME = "Short text";
|
||||
const DROPDOWN_NAME = "Dropdown";
|
||||
const EXTERNAL_ACCOUNT_NAME = "External account";
|
||||
const PARAGRAPH_NAME = "Paragraph";
|
||||
const USER_FIELD_NAME = "Person";
|
||||
|
||||
const custom_profile_field_types = {
|
||||
SHORT_TEXT: {
|
||||
id: SHORT_TEXT_ID,
|
||||
name: SHORT_TEXT_NAME,
|
||||
},
|
||||
DROPDOWN: {
|
||||
id: DROPDOWN_ID,
|
||||
name: DROPDOWN_NAME,
|
||||
},
|
||||
EXTERNAL_ACCOUNT: {
|
||||
id: EXTERNAL_ACCOUNT_ID,
|
||||
name: EXTERNAL_ACCOUNT_NAME,
|
||||
},
|
||||
PARAGRAPH: {
|
||||
id: PARAGRAPH_ID,
|
||||
name: PARAGRAPH_NAME,
|
||||
},
|
||||
USER: {
|
||||
id: USER_FIELD_ID,
|
||||
name: USER_FIELD_NAME,
|
||||
},
|
||||
};
|
||||
|
||||
const Sortable = {create: noop};
|
||||
|
||||
mock_esm("sortablejs", {default: Sortable});
|
||||
|
||||
const list_widget = mock_esm("../src/list_widget");
|
||||
|
||||
const settings_profile_fields = zrequire("settings_profile_fields");
|
||||
const {set_current_user, set_realm} = zrequire("state_data");
|
||||
|
||||
const current_user = {};
|
||||
set_current_user(current_user);
|
||||
const realm = make_realm();
|
||||
set_realm(realm);
|
||||
|
||||
function make_list_widget_only_render_items(override) {
|
||||
override(list_widget, "create", (_container, custom_profile_data, opts) => {
|
||||
for (const item of custom_profile_data) {
|
||||
opts.modifier_html(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function test_populate(opts, template_data) {
|
||||
with_overrides(({override}) => {
|
||||
const fields_data = opts.fields_data;
|
||||
|
||||
override(realm, "custom_profile_field_types", custom_profile_field_types);
|
||||
override(current_user, "is_admin", opts.is_admin);
|
||||
|
||||
loading.destroy_indicator = noop;
|
||||
|
||||
settings_profile_fields.do_populate_profile_fields(fields_data);
|
||||
|
||||
assert.deepEqual(template_data, opts.expected_template_data);
|
||||
});
|
||||
}
|
||||
|
||||
run_test("populate_profile_fields", ({mock_template, override}) => {
|
||||
make_list_widget_only_render_items(override);
|
||||
|
||||
override(realm, "custom_profile_fields", {});
|
||||
override(realm, "realm_default_external_accounts", JSON.stringify({}));
|
||||
|
||||
const template_data = [];
|
||||
mock_template("settings/admin_profile_field_list.hbs", false, (data) => {
|
||||
template_data.push(data);
|
||||
return "<admin-profile-field-list-stub>";
|
||||
});
|
||||
|
||||
const fields_data = [
|
||||
{
|
||||
type: SHORT_TEXT_ID,
|
||||
id: 10,
|
||||
name: "favorite color",
|
||||
hint: "blue?",
|
||||
field_data: "",
|
||||
display_in_profile_summary: false,
|
||||
valid_to_display_in_summary: true,
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
type: DROPDOWN_ID,
|
||||
id: 30,
|
||||
name: "meal",
|
||||
hint: "lunch",
|
||||
field_data: JSON.stringify({
|
||||
0: {
|
||||
text: "lunch",
|
||||
order: "0",
|
||||
},
|
||||
1: {
|
||||
text: "dinner",
|
||||
order: "1",
|
||||
},
|
||||
}),
|
||||
display_in_profile_summary: false,
|
||||
valid_to_display_in_summary: true,
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
type: EXTERNAL_ACCOUNT_ID,
|
||||
id: 20,
|
||||
name: "github profile",
|
||||
hint: "username only",
|
||||
field_data: JSON.stringify({
|
||||
subtype: "github",
|
||||
}),
|
||||
display_in_profile_summary: true,
|
||||
valid_to_display_in_summary: true,
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
type: EXTERNAL_ACCOUNT_ID,
|
||||
id: 21,
|
||||
name: "zulip profile",
|
||||
hint: "username only",
|
||||
field_data: JSON.stringify({
|
||||
subtype: "custom",
|
||||
url_pattern: "https://chat.zulip.com/%(username)s",
|
||||
}),
|
||||
display_in_profile_summary: true,
|
||||
valid_to_display_in_summary: true,
|
||||
required: false,
|
||||
},
|
||||
];
|
||||
const expected_template_data = [
|
||||
{
|
||||
profile_field: {
|
||||
id: 10,
|
||||
name: "favorite color",
|
||||
hint: "blue?",
|
||||
type: SHORT_TEXT_NAME,
|
||||
display_in_profile_summary: false,
|
||||
valid_to_display_in_summary: true,
|
||||
required: false,
|
||||
},
|
||||
can_modify: true,
|
||||
realm_default_external_accounts: realm.realm_default_external_accounts,
|
||||
},
|
||||
{
|
||||
profile_field: {
|
||||
id: 30,
|
||||
name: "meal",
|
||||
hint: "lunch",
|
||||
type: DROPDOWN_NAME,
|
||||
display_in_profile_summary: false,
|
||||
valid_to_display_in_summary: true,
|
||||
required: false,
|
||||
},
|
||||
can_modify: true,
|
||||
realm_default_external_accounts: realm.realm_default_external_accounts,
|
||||
},
|
||||
{
|
||||
profile_field: {
|
||||
id: 20,
|
||||
name: "github profile",
|
||||
hint: "username only",
|
||||
type: EXTERNAL_ACCOUNT_NAME,
|
||||
display_in_profile_summary: true,
|
||||
valid_to_display_in_summary: true,
|
||||
required: false,
|
||||
},
|
||||
can_modify: true,
|
||||
realm_default_external_accounts: realm.realm_default_external_accounts,
|
||||
},
|
||||
{
|
||||
profile_field: {
|
||||
id: 21,
|
||||
name: "zulip profile",
|
||||
hint: "username only",
|
||||
type: EXTERNAL_ACCOUNT_NAME,
|
||||
display_in_profile_summary: true,
|
||||
valid_to_display_in_summary: true,
|
||||
required: false,
|
||||
},
|
||||
can_modify: true,
|
||||
realm_default_external_accounts: realm.realm_default_external_accounts,
|
||||
},
|
||||
];
|
||||
|
||||
test_populate(
|
||||
{
|
||||
fields_data,
|
||||
expected_template_data,
|
||||
is_admin: true,
|
||||
},
|
||||
template_data,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user