mirror of
https://github.com/zulip/zulip.git
synced 2025-11-18 12:54:58 +00:00
node tests: Add explicit test for clearing input pills.
This commit is contained in:
committed by
Steve Howell
parent
e53be6d043
commit
98fc28c8ed
@@ -543,3 +543,37 @@ run_test("misc things", () => {
|
|||||||
|
|
||||||
container_click_handler.call(this_, {target: this_});
|
container_click_handler.call(this_, {target: this_});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
run_test("clear", () => {
|
||||||
|
const pill_input = $.create("pill_input");
|
||||||
|
const container = $.create("container");
|
||||||
|
container.set_find_results(".input", pill_input);
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
container,
|
||||||
|
create_item_from_text: (s) => ({display_value: s}),
|
||||||
|
get_text_from_item: (s) => s.display_value,
|
||||||
|
};
|
||||||
|
|
||||||
|
pill_input.before = () => {};
|
||||||
|
pill_input[0] = {};
|
||||||
|
|
||||||
|
const widget = input_pill.create(config);
|
||||||
|
|
||||||
|
widget.appendValue("red,yellow,blue");
|
||||||
|
|
||||||
|
const pills = widget._get_pills_for_testing();
|
||||||
|
|
||||||
|
const removed_colors = [];
|
||||||
|
for (const pill of pills) {
|
||||||
|
pill.$element.remove = () => {
|
||||||
|
removed_colors.push(pill.item.display_value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.clear();
|
||||||
|
|
||||||
|
// Note that we remove colors in the reverse order that we inserted.
|
||||||
|
assert.deepEqual(removed_colors, ["blue", "yellow", "red"]);
|
||||||
|
assert.equal(pill_input[0].textContent, "");
|
||||||
|
});
|
||||||
|
|||||||
@@ -221,6 +221,10 @@ exports.create = function (opts) {
|
|||||||
return store.pills.find((pill) => pill.id === id);
|
return store.pills.find((pill) => pill.id === id);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_get_pills_for_testing() {
|
||||||
|
return store.pills;
|
||||||
|
},
|
||||||
|
|
||||||
items() {
|
items() {
|
||||||
return store.pills.map((pill) => pill.item);
|
return store.pills.map((pill) => pill.item);
|
||||||
},
|
},
|
||||||
@@ -393,6 +397,7 @@ exports.create = function (opts) {
|
|||||||
clear: funcs.removeAllPills.bind(funcs),
|
clear: funcs.removeAllPills.bind(funcs),
|
||||||
clear_text: funcs.clear_text,
|
clear_text: funcs.clear_text,
|
||||||
is_pending: funcs.is_pending,
|
is_pending: funcs.is_pending,
|
||||||
|
_get_pills_for_testing: funcs._get_pills_for_testing,
|
||||||
};
|
};
|
||||||
|
|
||||||
return prototype;
|
return prototype;
|
||||||
|
|||||||
Reference in New Issue
Block a user