mirror of https://github.com/zulip/zulip.git
node tests: Add test_all() wrapper for widgetize.
I also move around a couple set_global/mock_esm calls.
This commit is contained in:
parent
09bad82131
commit
d7d357f61e
|
@ -8,7 +8,7 @@ const $ = require("../zjsunit/zjquery");
|
|||
|
||||
mock_cjs("jquery", $);
|
||||
|
||||
const events = [
|
||||
const sample_events = [
|
||||
{
|
||||
data: {
|
||||
option: "First option",
|
||||
|
@ -35,10 +35,12 @@ const events = [
|
|||
},
|
||||
];
|
||||
|
||||
let events;
|
||||
let widget_elem;
|
||||
let is_event_handled;
|
||||
let is_widget_activated;
|
||||
mock_esm("../../static/js/poll_widget", {
|
||||
|
||||
const fake_poll_widget = {
|
||||
activate(data) {
|
||||
is_widget_activated = true;
|
||||
widget_elem = data.elem;
|
||||
|
@ -51,15 +53,28 @@ mock_esm("../../static/js/poll_widget", {
|
|||
};
|
||||
data.callback("test_data");
|
||||
},
|
||||
});
|
||||
set_global("document", "document-stub");
|
||||
};
|
||||
|
||||
const narrow_state = mock_esm("../../static/js/narrow_state");
|
||||
set_global("current_msg_list", {});
|
||||
mock_esm("../../static/js/poll_widget", fake_poll_widget);
|
||||
|
||||
const current_msg_list = set_global("current_msg_list", {});
|
||||
set_global("document", "document-stub");
|
||||
|
||||
const widgetize = zrequire("widgetize");
|
||||
|
||||
run_test("activate", (override) => {
|
||||
function test(label, f) {
|
||||
run_test(label, (override) => {
|
||||
events = [...sample_events];
|
||||
widget_elem = undefined;
|
||||
is_event_handled = false;
|
||||
is_widget_activated = false;
|
||||
widgetize.clear_for_testing();
|
||||
f(override);
|
||||
});
|
||||
}
|
||||
|
||||
test("activate", (override) => {
|
||||
// Both widgetize.activate and widgetize.handle_event are tested
|
||||
// here to use the "caching" of widgets
|
||||
const row = $.create("<stub message row>");
|
||||
|
|
|
@ -13,6 +13,10 @@ const widgets = new Map([
|
|||
|
||||
export const widget_contents = new Map();
|
||||
|
||||
export function clear_for_testing() {
|
||||
widget_contents.clear();
|
||||
}
|
||||
|
||||
function set_widget_in_message(row, widget_elem) {
|
||||
const content_holder = row.find(".message_content");
|
||||
content_holder.empty().append(widget_elem);
|
||||
|
|
Loading…
Reference in New Issue