mirror of https://github.com/zulip/zulip.git
dropdown_list_widget: Add basic tests.
This commit is contained in:
parent
c76648c3d4
commit
6528226a80
|
@ -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());
|
||||||
|
});
|
Loading…
Reference in New Issue