node_tests: Mock sortablejs to avoid __Rewire__.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-03-09 21:36:44 -08:00
parent 5fc8a12d7b
commit 92a46888f0
2 changed files with 6 additions and 11 deletions

View File

@ -37,6 +37,8 @@ page_params.custom_profile_field_types = {
},
};
mock_esm("sortablejs", {Sortable: {create: () => {}}});
const settings_profile_fields = zrequire("settings_profile_fields");
function test_populate(opts) {
@ -74,8 +76,7 @@ function test_populate(opts) {
assert.equal(num_appends, fields_data.length);
}
run_test("populate_profile_fields", (override) => {
override(settings_profile_fields, "create_sortable", () => {});
run_test("populate_profile_fields", () => {
const fields_data = [
{
type: SHORT_TEXT_ID,

View File

@ -11,12 +11,6 @@ const meta = {
loaded: false,
};
export function create_sortable(...opts) {
// This function is extracted so tests can easily
// stub Sortable.
return Sortable.create(...opts);
}
export function maybe_disable_widgets() {
if (page_params.is_admin) {
return;
@ -271,7 +265,7 @@ function set_up_choices_field_edit_form(profile_field, field_data) {
// Add blank choice at last
create_choice_row(choice_list);
update_choice_delete_btn(choice_list, false);
create_sortable(choice_list[0], {
Sortable.create(choice_list[0], {
onUpdate() {},
});
}
@ -410,7 +404,7 @@ export function do_populate_profile_fields(profile_fields_data) {
if (page_params.is_admin) {
const field_list = $("#admin_profile_fields_table")[0];
create_sortable(field_list, {
Sortable.create(field_list, {
onUpdate: update_field_order,
});
}
@ -425,7 +419,7 @@ function set_up_choices_field() {
if (page_params.is_admin) {
const choice_list = $("#profile_field_choices")[0];
create_sortable(choice_list, {
Sortable.create(choice_list, {
onUpdate() {},
});
}