dropdown_list_widget: Add basic tests.

This commit is contained in:
Rohitt Vashishtha 2020-05-16 11:53:32 +05:30 committed by Tim Abbott
parent c76648c3d4
commit 6528226a80
1 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,47 @@
zrequire('dropdown_list_widget');
zrequire('scroll_util');
set_global('$', global.make_zjquery());
const noop = () => {};
const _list_render = {
create: () => {
return { init: noop };
},
};
set_global('list_render', _list_render);
run_test('basic_functions', () => {
let updated_value;
const opts = {
setting_name: 'my_setting',
data: ['one', 'two', 'three'].map(x => ({name: x, value: x})),
value: 'one',
on_update: (val) => { updated_value = val; },
default_text: i18n.t("not set"),
render_text: (text) => `rendered: ${text}`,
};
const input_group = $(".input_group");
const reset_button = $('.dropdown_list_reset_button');
input_group.set_find_results('.dropdown_list_reset_button', reset_button);
$("#my_setting_widget #my_setting_name").closest = () => input_group;
const $widget = $("#my_setting_widget #my_setting_name");
const widget = dropdown_list_widget(opts);
assert.equal(widget.value(), 'one');
assert.equal(updated_value, undefined); // We haven't 'updated' the widget yet.
assert(reset_button.visible());
widget.update('two');
assert.equal($widget.text(), 'rendered: two');
assert.equal(widget.value(), 'two');
assert.equal(updated_value, 'two');
assert(reset_button.visible());
widget.update(null);
assert.equal($widget.text(), 'translated: not set');
assert.equal(widget.value(), '');
assert.equal(updated_value, null);
assert(!reset_button.visible());
});