2020-07-15 01:29:15 +02:00
|
|
|
zrequire("list_render");
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
// We need these stubs to get by instanceof checks.
|
|
|
|
// The list_render library allows you to insert objects
|
|
|
|
// that are either jQuery, Element, or just raw HTML
|
|
|
|
// strings. We initially test with raw strings.
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("jQuery", "stub");
|
2020-07-02 01:55:18 +02:00
|
|
|
function Element() {
|
2018-04-17 21:29:21 +02:00
|
|
|
return { };
|
2020-07-02 01:55:18 +02:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("Element", Element);
|
|
|
|
set_global("ui", {});
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
// We only need very simple jQuery wrappers for when the
|
|
|
|
// "real" code wraps html or sets up click handlers.
|
|
|
|
// We'll simulate most other objects ourselves.
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("$", (arg) => {
|
2018-04-17 21:29:21 +02:00
|
|
|
if (arg.to_jquery) {
|
|
|
|
return arg.to_jquery();
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2020-05-28 19:58:51 +02:00
|
|
|
replace: (regex, string) => {
|
|
|
|
arg = arg.replace(regex, string);
|
|
|
|
},
|
2018-04-17 21:29:21 +02:00
|
|
|
html: () => arg,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-24 12:20:45 +02:00
|
|
|
// We build objects here that simulate jQuery containers.
|
|
|
|
// The main thing to do at first is simulate that our
|
|
|
|
// scroll container is the nearest ancestor to our main
|
|
|
|
// container that has a max-height attribute, and then
|
|
|
|
// the scroll container will have a scroll event attached to
|
|
|
|
// it. This is a good time to read set_up_event_handlers
|
|
|
|
// in the real code.
|
|
|
|
|
|
|
|
function make_container() {
|
2018-04-17 21:29:21 +02:00
|
|
|
const container = {};
|
|
|
|
|
|
|
|
container.length = () => 1;
|
|
|
|
container.is = () => false;
|
|
|
|
container.css = (prop) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(prop, "max-height");
|
|
|
|
return "none";
|
2018-04-17 21:29:21 +02:00
|
|
|
};
|
|
|
|
|
2020-04-24 12:20:45 +02:00
|
|
|
// Make our append function just set a field we can
|
|
|
|
// check in our tests.
|
|
|
|
container.append = (data) => {
|
|
|
|
container.appended_data = data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2020-07-04 10:07:43 +02:00
|
|
|
function make_scroll_container() {
|
2020-04-24 12:20:45 +02:00
|
|
|
const scroll_container = {};
|
2018-04-17 21:29:21 +02:00
|
|
|
|
2020-04-24 13:22:32 +02:00
|
|
|
scroll_container.cleared = false;
|
|
|
|
|
2018-04-17 21:29:21 +02:00
|
|
|
// Capture the scroll callback so we can call it in
|
|
|
|
// our tests.
|
2020-04-24 12:20:45 +02:00
|
|
|
scroll_container.on = (ev, f) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(ev, "scroll.list_widget_container");
|
2020-04-24 12:20:45 +02:00
|
|
|
scroll_container.call_scroll = () => {
|
|
|
|
f.call(scroll_container);
|
2018-04-17 21:29:21 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 13:22:32 +02:00
|
|
|
scroll_container.off = (ev) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(ev, "scroll.list_widget_container");
|
2020-04-24 13:22:32 +02:00
|
|
|
scroll_container.cleared = true;
|
|
|
|
};
|
|
|
|
|
2020-04-24 12:20:45 +02:00
|
|
|
return scroll_container;
|
2018-04-17 21:29:21 +02:00
|
|
|
}
|
|
|
|
|
2020-04-24 12:30:56 +02:00
|
|
|
function make_sort_container() {
|
|
|
|
const sort_container = {};
|
|
|
|
|
2020-04-24 13:22:32 +02:00
|
|
|
sort_container.cleared = false;
|
|
|
|
|
2020-04-24 12:30:56 +02:00
|
|
|
sort_container.on = (ev, sel, f) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(ev, "click.list_widget_sort");
|
|
|
|
assert.equal(sel, "[data-sort]");
|
2020-04-24 12:30:56 +02:00
|
|
|
sort_container.f = f;
|
|
|
|
};
|
|
|
|
|
2020-04-24 13:22:32 +02:00
|
|
|
sort_container.off = (ev) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(ev, "click.list_widget_sort");
|
2020-04-24 13:22:32 +02:00
|
|
|
sort_container.cleared = true;
|
|
|
|
};
|
|
|
|
|
2020-04-24 12:30:56 +02:00
|
|
|
return sort_container;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:59:33 +02:00
|
|
|
function make_filter_element() {
|
|
|
|
const element = {};
|
|
|
|
|
2020-04-24 13:22:32 +02:00
|
|
|
element.cleared = false;
|
|
|
|
|
2020-04-24 13:59:33 +02:00
|
|
|
element.on = (ev, f) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(ev, "input.list_widget_filter");
|
2020-04-24 13:59:33 +02:00
|
|
|
element.f = f;
|
|
|
|
};
|
|
|
|
|
2020-04-24 13:22:32 +02:00
|
|
|
element.off = (ev) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(ev, "input.list_widget_filter");
|
2020-04-24 13:22:32 +02:00
|
|
|
element.cleared = true;
|
|
|
|
};
|
|
|
|
|
2020-04-24 13:59:33 +02:00
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2018-04-17 21:29:21 +02:00
|
|
|
function make_search_input() {
|
|
|
|
const $element = {};
|
|
|
|
|
|
|
|
// Allow ourselves to be wrapped by $(...) and
|
|
|
|
// return ourselves.
|
|
|
|
$element.to_jquery = () => $element;
|
|
|
|
|
|
|
|
$element.on = (event_name, f) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(event_name, "input.list_widget_filter");
|
2018-04-17 21:29:21 +02:00
|
|
|
$element.simulate_input_event = () => {
|
|
|
|
const elem = {
|
|
|
|
value: $element.val(),
|
|
|
|
};
|
|
|
|
f.call(elem);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return $element;
|
|
|
|
}
|
|
|
|
|
|
|
|
function div(item) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return "<div>" + item + "</div>";
|
2018-04-17 21:29:21 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("scrolling", () => {
|
2020-04-24 12:20:45 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2018-04-17 21:29:21 +02:00
|
|
|
|
2020-04-12 19:45:33 +02:00
|
|
|
const items = [];
|
|
|
|
|
2020-07-04 10:07:43 +02:00
|
|
|
let get_scroll_element_called = false;
|
|
|
|
ui.get_scroll_element = (element) => {
|
|
|
|
get_scroll_element_called = true;
|
|
|
|
return element;
|
|
|
|
};
|
|
|
|
|
2020-04-12 19:45:33 +02:00
|
|
|
for (let i = 0; i < 200; i += 1) {
|
2020-07-15 01:29:15 +02:00
|
|
|
items.push("item " + i);
|
2020-04-12 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const opts = {
|
|
|
|
modifier: (item) => item,
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-04-12 19:45:33 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
container.html = (html) => { assert.equal(html, ""); };
|
2020-04-11 16:23:29 +02:00
|
|
|
list_render.create(container, items, opts);
|
2020-04-12 19:45:33 +02:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
container.appended_data.html(),
|
2020-07-15 01:29:15 +02:00
|
|
|
items.slice(0, 80).join(""),
|
2020-04-12 19:45:33 +02:00
|
|
|
);
|
2020-07-04 10:07:43 +02:00
|
|
|
assert.equal(get_scroll_element_called, true);
|
2020-04-12 19:45:33 +02:00
|
|
|
|
|
|
|
// Set up our fake geometry so it forces a scroll action.
|
2020-04-24 12:20:45 +02:00
|
|
|
scroll_container.scrollTop = 180;
|
|
|
|
scroll_container.clientHeight = 100;
|
|
|
|
scroll_container.scrollHeight = 260;
|
2020-04-12 19:45:33 +02:00
|
|
|
|
|
|
|
// Scrolling gets the next two elements from the list into
|
|
|
|
// our widget.
|
2020-04-24 12:20:45 +02:00
|
|
|
scroll_container.call_scroll();
|
2020-04-12 19:45:33 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
container.appended_data.html(),
|
2020-07-15 01:29:15 +02:00
|
|
|
items.slice(80, 100).join(""),
|
2020-04-12 19:45:33 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("filtering", () => {
|
2020-04-24 12:20:45 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-04-12 19:45:33 +02:00
|
|
|
|
2018-04-17 21:29:21 +02:00
|
|
|
const search_input = make_search_input();
|
|
|
|
|
|
|
|
const list = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"apple",
|
|
|
|
"banana",
|
|
|
|
"carrot",
|
|
|
|
"dog",
|
|
|
|
"egg",
|
|
|
|
"fence",
|
|
|
|
"grape",
|
2018-04-17 21:29:21 +02:00
|
|
|
];
|
2020-04-24 22:16:39 +02:00
|
|
|
const opts = {
|
2018-04-17 21:29:21 +02:00
|
|
|
filter: {
|
|
|
|
element: search_input,
|
2020-07-02 01:41:40 +02:00
|
|
|
predicate: (item, value) => item.includes(value),
|
2018-04-17 21:29:21 +02:00
|
|
|
},
|
|
|
|
modifier: (item) => div(item),
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2018-04-17 21:29:21 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
container.html = (html) => { assert.equal(html, ""); };
|
2020-04-24 22:16:39 +02:00
|
|
|
const widget = list_render.create(container, list, opts);
|
2018-04-17 21:29:21 +02:00
|
|
|
|
2020-04-12 19:45:33 +02:00
|
|
|
let expected_html =
|
2020-07-15 01:29:15 +02:00
|
|
|
"<div>apple</div>" +
|
|
|
|
"<div>banana</div>" +
|
|
|
|
"<div>carrot</div>" +
|
|
|
|
"<div>dog</div>" +
|
|
|
|
"<div>egg</div>" +
|
|
|
|
"<div>fence</div>" +
|
|
|
|
"<div>grape</div>";
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
|
|
|
|
|
|
|
// Filtering will pick out dog/egg/grape when we put "g"
|
|
|
|
// into our search input. (This uses the default filter, which
|
|
|
|
// is a glorified indexOf call.)
|
2020-07-15 01:29:15 +02:00
|
|
|
search_input.val = () => "g";
|
2018-04-17 21:29:21 +02:00
|
|
|
search_input.simulate_input_event();
|
2020-07-15 01:29:15 +02:00
|
|
|
expected_html = "<div>dog</div><div>egg</div><div>grape</div>";
|
2018-04-17 21:29:21 +02:00
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
|
|
|
|
|
|
|
// We can insert new data into the widget.
|
|
|
|
const new_data = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"greta",
|
|
|
|
"faye",
|
|
|
|
"gary",
|
|
|
|
"frank",
|
|
|
|
"giraffe",
|
|
|
|
"fox",
|
2018-04-17 21:29:21 +02:00
|
|
|
];
|
|
|
|
|
2020-04-15 01:29:34 +02:00
|
|
|
widget.replace_list_data(new_data);
|
2020-04-12 19:45:33 +02:00
|
|
|
expected_html =
|
2020-07-15 01:29:15 +02:00
|
|
|
"<div>greta</div>" +
|
|
|
|
"<div>gary</div>" +
|
|
|
|
"<div>giraffe</div>";
|
2018-04-17 21:29:21 +02:00
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
2020-04-24 22:16:39 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("no filtering", () => {
|
2020-04-24 22:16:39 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-04-24 22:16:39 +02:00
|
|
|
container.html = () => {};
|
2020-03-10 19:48:03 +01:00
|
|
|
|
|
|
|
// Opts does not require a filter key.
|
2020-04-24 22:16:39 +02:00
|
|
|
const opts = {
|
2020-03-10 19:48:03 +01:00
|
|
|
modifier: (item) => div(item),
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-03-10 19:48:03 +01:00
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
const widget = list_render.create(container, ["apple", "banana"], opts);
|
2020-03-10 19:48:03 +01:00
|
|
|
widget.render();
|
|
|
|
|
2020-04-24 22:16:39 +02:00
|
|
|
const expected_html =
|
2020-07-15 01:29:15 +02:00
|
|
|
"<div>apple</div>" +
|
|
|
|
"<div>banana</div>";
|
2020-03-10 19:48:03 +01:00
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
function sort_button(opts) {
|
|
|
|
// The complications here are due to needing to find
|
|
|
|
// the list via complicated HTML assumptions. Also, we
|
|
|
|
// don't have any abstraction for the button and its
|
|
|
|
// siblings other than direct jQuery actions.
|
|
|
|
|
|
|
|
function data(sel) {
|
|
|
|
switch (sel) {
|
2018-05-07 03:30:13 +02:00
|
|
|
case "sort": return opts.sort_type;
|
|
|
|
case "sort-prop": return opts.prop_name;
|
2020-07-15 01:29:15 +02:00
|
|
|
default: throw Error("unknown selector: " + sel);
|
2018-04-17 21:29:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function lookup(sel, value) {
|
|
|
|
return (selector) => {
|
|
|
|
assert.equal(sel, selector);
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-24 16:13:42 +02:00
|
|
|
const classList = new Set();
|
|
|
|
|
2020-04-15 12:22:23 +02:00
|
|
|
const button = {
|
2018-04-17 21:29:21 +02:00
|
|
|
data: data,
|
2020-07-15 01:29:15 +02:00
|
|
|
closest: lookup(".progressive-table-wrapper", {
|
|
|
|
data: lookup("list-render", opts.list_name),
|
2018-04-17 21:29:21 +02:00
|
|
|
}),
|
2020-04-24 16:13:42 +02:00
|
|
|
addClass: (cls) => {
|
|
|
|
classList.add(cls);
|
|
|
|
},
|
2020-07-02 01:41:40 +02:00
|
|
|
hasClass: (cls) => classList.has(cls),
|
2020-04-24 16:13:42 +02:00
|
|
|
removeClass: (cls) => {
|
|
|
|
classList.delete(cls);
|
2020-04-13 16:13:06 +02:00
|
|
|
},
|
2020-07-15 01:29:15 +02:00
|
|
|
siblings: lookup(".active", {
|
2020-04-24 16:13:42 +02:00
|
|
|
removeClass: (cls) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(cls, "active");
|
2018-04-17 21:29:21 +02:00
|
|
|
button.siblings_deactivated = true;
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
siblings_deactivated: false,
|
2020-04-24 12:30:56 +02:00
|
|
|
to_jquery: () => button,
|
2018-04-17 21:29:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("wire up filter element", () => {
|
2019-12-30 16:13:42 +01:00
|
|
|
const lst = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"alice",
|
|
|
|
"JESSE",
|
|
|
|
"moses",
|
|
|
|
"scott",
|
|
|
|
"Sean",
|
|
|
|
"Xavier",
|
2019-12-30 16:13:42 +01:00
|
|
|
];
|
|
|
|
|
2020-04-24 13:59:33 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-04-24 13:59:33 +02:00
|
|
|
const filter_element = make_filter_element();
|
|
|
|
|
|
|
|
// We don't care about what gets drawn initially.
|
|
|
|
container.html = () => {};
|
|
|
|
|
2019-12-30 16:13:42 +01:00
|
|
|
const opts = {
|
|
|
|
filter: {
|
2020-07-02 01:41:40 +02:00
|
|
|
filterer: (list, value) => list.filter((item) => item.toLowerCase().includes(value)),
|
2020-04-24 13:59:33 +02:00
|
|
|
element: filter_element,
|
2019-12-30 16:13:42 +01:00
|
|
|
},
|
2020-07-15 01:29:15 +02:00
|
|
|
modifier: (s) => "(" + s + ")",
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2019-12-30 16:13:42 +01:00
|
|
|
};
|
|
|
|
|
2020-04-24 13:59:33 +02:00
|
|
|
list_render.create(container, lst, opts);
|
2020-07-15 01:29:15 +02:00
|
|
|
filter_element.f.apply({value: "se"});
|
2020-04-24 13:59:33 +02:00
|
|
|
assert.equal(
|
|
|
|
container.appended_data.html(),
|
2020-07-15 01:29:15 +02:00
|
|
|
"(JESSE)(moses)(Sean)",
|
2020-04-24 13:59:33 +02:00
|
|
|
);
|
2019-12-30 16:13:42 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("sorting", () => {
|
2020-04-24 12:20:45 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-04-24 12:30:56 +02:00
|
|
|
const sort_container = make_sort_container();
|
2018-04-17 21:29:21 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let cleared;
|
2018-04-17 21:29:21 +02:00
|
|
|
container.html = (html) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(html, "");
|
2018-04-17 21:29:21 +02:00
|
|
|
cleared = true;
|
|
|
|
};
|
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
const alice = {name: "alice", salary: 50};
|
|
|
|
const bob = {name: "Bob", salary: 40};
|
|
|
|
const cal = {name: "cal", salary: 30};
|
|
|
|
const dave = {name: "dave", salary: 25};
|
|
|
|
const ellen = {name: "ellen", salary: 95};
|
2018-04-17 21:29:21 +02:00
|
|
|
|
2020-04-24 16:13:42 +02:00
|
|
|
const list = [bob, ellen, dave, alice, cal];
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
const opts = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "sorting-list",
|
2020-04-24 12:30:56 +02:00
|
|
|
parent_container: sort_container,
|
2020-07-02 01:41:40 +02:00
|
|
|
modifier: (item) => div(item.name) + div(item.salary),
|
2019-12-30 16:13:42 +01:00
|
|
|
filter: {
|
2019-12-30 17:44:24 +01:00
|
|
|
predicate: () => true,
|
2019-12-30 16:13:42 +01:00
|
|
|
},
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2018-04-17 21:29:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function html_for(people) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return people.map(opts.modifier).join("");
|
2018-04-17 21:29:21 +02:00
|
|
|
}
|
|
|
|
|
2020-04-24 12:30:56 +02:00
|
|
|
list_render.create(container, list, opts);
|
2018-04-17 21:29:21 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let button_opts;
|
|
|
|
let button;
|
|
|
|
let expected_html;
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
button_opts = {
|
2020-07-15 01:29:15 +02:00
|
|
|
sort_type: "alphabetic",
|
|
|
|
prop_name: "name",
|
|
|
|
list_name: "my-list",
|
2018-04-17 21:29:21 +02:00
|
|
|
active: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
button = sort_button(button_opts);
|
|
|
|
|
2020-04-24 12:30:56 +02:00
|
|
|
sort_container.f.apply(button);
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
assert(cleared);
|
|
|
|
assert(button.siblings_deactivated);
|
|
|
|
|
2020-04-24 16:13:42 +02:00
|
|
|
expected_html = html_for([
|
|
|
|
alice,
|
|
|
|
bob,
|
|
|
|
cal,
|
|
|
|
dave,
|
|
|
|
ellen,
|
|
|
|
]);
|
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
|
|
|
|
|
|
|
// Hit same button again to reverse the data.
|
|
|
|
cleared = false;
|
|
|
|
sort_container.f.apply(button);
|
|
|
|
assert(cleared);
|
|
|
|
expected_html = html_for([
|
|
|
|
ellen,
|
|
|
|
dave,
|
|
|
|
cal,
|
|
|
|
bob,
|
|
|
|
alice,
|
|
|
|
]);
|
2018-04-17 21:29:21 +02:00
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(button.hasClass("descend"));
|
2020-04-24 16:13:42 +02:00
|
|
|
|
|
|
|
// And then hit a third time to go back to the forward sort.
|
|
|
|
cleared = false;
|
|
|
|
sort_container.f.apply(button);
|
|
|
|
assert(cleared);
|
|
|
|
expected_html = html_for([
|
|
|
|
alice,
|
|
|
|
bob,
|
|
|
|
cal,
|
|
|
|
dave,
|
|
|
|
ellen,
|
|
|
|
]);
|
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(!button.hasClass("descend"));
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
// Now try a numeric sort.
|
|
|
|
button_opts = {
|
2020-07-15 01:29:15 +02:00
|
|
|
sort_type: "numeric",
|
|
|
|
prop_name: "salary",
|
|
|
|
list_name: "my-list",
|
2018-04-17 21:29:21 +02:00
|
|
|
active: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
button = sort_button(button_opts);
|
|
|
|
|
|
|
|
cleared = false;
|
|
|
|
button.siblings_deactivated = false;
|
|
|
|
|
2020-04-24 12:30:56 +02:00
|
|
|
sort_container.f.apply(button);
|
2018-04-17 21:29:21 +02:00
|
|
|
|
|
|
|
assert(cleared);
|
|
|
|
assert(button.siblings_deactivated);
|
|
|
|
|
2020-04-24 16:13:42 +02:00
|
|
|
expected_html = html_for([
|
|
|
|
dave,
|
|
|
|
cal,
|
|
|
|
bob,
|
|
|
|
alice,
|
|
|
|
ellen,
|
|
|
|
]);
|
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
|
|
|
|
|
|
|
// Hit same button again to reverse the numeric sort.
|
|
|
|
cleared = false;
|
|
|
|
sort_container.f.apply(button);
|
|
|
|
assert(cleared);
|
|
|
|
expected_html = html_for([
|
|
|
|
ellen,
|
|
|
|
alice,
|
|
|
|
bob,
|
|
|
|
cal,
|
|
|
|
dave,
|
|
|
|
]);
|
2018-04-17 21:29:21 +02:00
|
|
|
assert.deepEqual(container.appended_data.html(), expected_html);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(button.hasClass("descend"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2020-04-24 13:22:32 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("custom sort", () => {
|
2020-04-24 22:23:35 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-04-24 22:23:35 +02:00
|
|
|
container.html = () => {};
|
|
|
|
|
|
|
|
const n42 = {x: 6, y: 7};
|
|
|
|
const n43 = {x: 1, y: 43};
|
|
|
|
const n44 = {x: 4, y: 11};
|
|
|
|
|
|
|
|
const list = [n42, n43, n44];
|
|
|
|
|
|
|
|
function sort_by_x(a, b) {
|
|
|
|
return a.x - b.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function sort_by_product(a, b) {
|
|
|
|
return a.x * a.y - b.x * b.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_render.create(container, list, {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "custom-sort-list",
|
2020-07-16 23:29:01 +02:00
|
|
|
modifier: (n) => "(" + n.x + ", " + n.y + ")",
|
2020-04-24 22:23:35 +02:00
|
|
|
sort_fields: {
|
|
|
|
product: sort_by_product,
|
|
|
|
x_value: sort_by_x,
|
|
|
|
},
|
|
|
|
init_sort: sort_by_product,
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-04-24 22:23:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
container.appended_data.html(),
|
2020-07-15 01:29:15 +02:00
|
|
|
"(6, 7)(1, 43)(4, 11)",
|
2020-04-24 22:23:35 +02:00
|
|
|
);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const widget = list_render.get("custom-sort-list");
|
2020-04-24 22:23:35 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
widget.sort("x_value");
|
2020-04-24 22:23:35 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
container.appended_data.html(),
|
2020-07-15 01:29:15 +02:00
|
|
|
"(1, 43)(4, 11)(6, 7)",
|
2020-04-24 22:23:35 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// We can sort without registering the function, too.
|
|
|
|
function sort_by_y(a, b) {
|
|
|
|
return a.y - b.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
widget.sort(sort_by_y);
|
|
|
|
assert.deepEqual(
|
|
|
|
container.appended_data.html(),
|
2020-07-15 01:29:15 +02:00
|
|
|
"(6, 7)(4, 11)(1, 43)",
|
2020-04-24 22:23:35 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("clear_event_handlers", () => {
|
2020-04-24 13:22:32 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-04-24 13:22:32 +02:00
|
|
|
const sort_container = make_sort_container();
|
|
|
|
const filter_element = make_filter_element();
|
|
|
|
|
|
|
|
// We don't care about actual data for this test.
|
|
|
|
const list = [];
|
|
|
|
container.html = () => {};
|
|
|
|
|
|
|
|
const opts = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "list-we-create-twice",
|
2020-04-24 13:22:32 +02:00
|
|
|
parent_container: sort_container,
|
|
|
|
modifier: () => {},
|
|
|
|
filter: {
|
|
|
|
element: filter_element,
|
|
|
|
predicate: () => true,
|
|
|
|
},
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-04-24 13:22:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create it the first time.
|
|
|
|
list_render.create(container, list, opts);
|
|
|
|
assert.equal(sort_container.cleared, false);
|
|
|
|
assert.equal(scroll_container.cleared, false);
|
|
|
|
assert.equal(filter_element.cleared, false);
|
|
|
|
|
|
|
|
// The second time we'll clear the old events.
|
|
|
|
list_render.create(container, list, opts);
|
|
|
|
assert.equal(sort_container.cleared, true);
|
|
|
|
assert.equal(scroll_container.cleared, true);
|
|
|
|
assert.equal(filter_element.cleared, true);
|
|
|
|
});
|
2020-04-24 15:38:16 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("errors", () => {
|
2020-04-24 15:38:16 +02:00
|
|
|
// We don't care about actual data for this test.
|
2020-07-15 01:29:15 +02:00
|
|
|
const list = "stub";
|
2020-04-24 15:57:41 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-04-24 15:38:16 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Need opts to create widget.");
|
2020-04-24 15:38:16 +02:00
|
|
|
list_render.create(container, list);
|
|
|
|
blueslip.reset();
|
2020-04-24 15:57:41 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "simplebar_container is missing.");
|
2020-07-04 10:07:43 +02:00
|
|
|
list_render.create(container, list, {
|
2020-07-15 01:29:15 +02:00
|
|
|
modifier: "hello world",
|
2020-07-04 10:07:43 +02:00
|
|
|
});
|
|
|
|
blueslip.reset();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "get_item should be a function");
|
2020-05-10 12:45:16 +02:00
|
|
|
list_render.create(container, list, {
|
2020-07-15 01:29:15 +02:00
|
|
|
get_item: "not a function",
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-05-10 12:45:16 +02:00
|
|
|
});
|
|
|
|
blueslip.reset();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Filter predicate is not a function.");
|
2020-04-24 15:57:41 +02:00
|
|
|
list_render.create(container, list, {
|
|
|
|
filter: {
|
2020-07-15 01:29:15 +02:00
|
|
|
predicate: "wrong type",
|
2020-04-24 15:57:41 +02:00
|
|
|
},
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-04-24 15:57:41 +02:00
|
|
|
});
|
|
|
|
blueslip.reset();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Filterer and predicate are mutually exclusive.");
|
2020-04-24 15:57:41 +02:00
|
|
|
list_render.create(container, list, {
|
|
|
|
filter: {
|
|
|
|
filterer: () => true,
|
|
|
|
predicate: () => true,
|
|
|
|
},
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-04-24 15:57:41 +02:00
|
|
|
});
|
|
|
|
blueslip.reset();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Filter filterer is not a function (or missing).");
|
2020-04-24 15:57:41 +02:00
|
|
|
list_render.create(container, list, {
|
|
|
|
filter: {
|
|
|
|
},
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-04-24 15:57:41 +02:00
|
|
|
});
|
|
|
|
blueslip.reset();
|
2020-04-24 22:09:17 +02:00
|
|
|
|
|
|
|
container.html = () => {};
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "List item is not a string: 999");
|
2020-04-24 22:09:17 +02:00
|
|
|
list_render.create(container, list, {
|
|
|
|
modifier: () => 999,
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-04-24 22:09:17 +02:00
|
|
|
});
|
|
|
|
blueslip.reset();
|
2020-04-24 15:38:16 +02:00
|
|
|
});
|
2020-04-24 19:49:18 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("sort helpers", () => {
|
2020-04-24 19:49:18 +02:00
|
|
|
/*
|
|
|
|
We mostly test our sorting helpers using the
|
|
|
|
actual widget, but this test gets us a bit
|
|
|
|
more line coverage.
|
|
|
|
*/
|
2020-07-15 01:29:15 +02:00
|
|
|
const alice2 = {name: "alice", id: 2};
|
|
|
|
const alice10 = {name: "alice", id: 10};
|
|
|
|
const bob2 = {name: "bob", id: 2};
|
|
|
|
const bob10 = {name: "bob", id: 10};
|
2020-04-24 19:49:18 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const alpha_cmp = list_render.alphabetic_sort("name");
|
|
|
|
const num_cmp = list_render.numeric_sort("id");
|
2020-04-24 19:49:18 +02:00
|
|
|
|
|
|
|
assert.equal(alpha_cmp(alice2, alice10), 0);
|
|
|
|
assert.equal(alpha_cmp(alice2, bob2), -1);
|
|
|
|
assert.equal(alpha_cmp(bob2, alice10), 1);
|
|
|
|
assert.equal(num_cmp(alice2, bob2), 0);
|
|
|
|
assert.equal(num_cmp(alice2, bob10), -1);
|
|
|
|
assert.equal(num_cmp(alice10, bob2), 1);
|
|
|
|
});
|
2020-04-24 23:23:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("replace_list_data w/filter update", () => {
|
2020-04-24 23:23:51 +02:00
|
|
|
const container = make_container();
|
2020-07-04 10:07:43 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-04-24 23:23:51 +02:00
|
|
|
container.html = () => {};
|
|
|
|
|
|
|
|
const list = [1, 2, 3, 4];
|
|
|
|
let num_updates = 0;
|
|
|
|
|
|
|
|
list_render.create(container, list, {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "replace-list",
|
|
|
|
modifier: (n) => "(" + n.toString() + ")",
|
2020-04-24 23:23:51 +02:00
|
|
|
filter: {
|
|
|
|
predicate: (n) => n % 2 === 0,
|
|
|
|
onupdate: () => {
|
|
|
|
num_updates += 1;
|
|
|
|
},
|
|
|
|
},
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-04-24 23:23:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(num_updates, 0);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
container.appended_data.html(),
|
2020-07-15 01:29:15 +02:00
|
|
|
"(2)(4)",
|
2020-04-24 23:23:51 +02:00
|
|
|
);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const widget = list_render.get("replace-list");
|
2020-04-24 23:23:51 +02:00
|
|
|
widget.replace_list_data([5, 6, 7, 8]);
|
|
|
|
|
|
|
|
assert.equal(num_updates, 1);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
container.appended_data.html(),
|
2020-07-15 01:29:15 +02:00
|
|
|
"(6)(8)",
|
2020-04-24 23:23:51 +02:00
|
|
|
);
|
|
|
|
});
|
2020-05-10 12:45:16 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("opts.get_item", () => {
|
2020-05-10 12:45:16 +02:00
|
|
|
const items = {};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
items[1] = "one";
|
|
|
|
items[2] = "two";
|
|
|
|
items[3] = "three";
|
|
|
|
items[4] = "four";
|
2020-05-10 12:45:16 +02:00
|
|
|
|
|
|
|
const list = [1, 2, 3, 4];
|
|
|
|
|
|
|
|
const boring_opts = {
|
|
|
|
get_item: (n) => items[n],
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
list_render.get_filtered_items(
|
2020-07-15 01:29:15 +02:00
|
|
|
"whatever", list, boring_opts,
|
2020-05-10 12:45:16 +02:00
|
|
|
),
|
2020-07-15 01:29:15 +02:00
|
|
|
["one", "two", "three", "four"],
|
2020-05-10 12:45:16 +02:00
|
|
|
);
|
|
|
|
|
2020-07-02 01:41:40 +02:00
|
|
|
const predicate = (item, value) => item.startsWith(value);
|
2020-05-10 12:45:16 +02:00
|
|
|
|
|
|
|
const predicate_opts = {
|
|
|
|
get_item: (n) => items[n],
|
|
|
|
filter: {
|
|
|
|
predicate: predicate,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
list_render.get_filtered_items(
|
2020-07-15 01:29:15 +02:00
|
|
|
"t", list, predicate_opts,
|
2020-05-10 12:45:16 +02:00
|
|
|
),
|
2020-07-15 01:29:15 +02:00
|
|
|
["two", "three"],
|
2020-05-10 12:45:16 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
const filterer_opts = {
|
|
|
|
get_item: (n) => items[n],
|
|
|
|
filter: {
|
2020-07-02 01:41:40 +02:00
|
|
|
filterer: (items, value) => items.filter((item) => predicate(item, value)),
|
2020-05-10 12:45:16 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
list_render.get_filtered_items(
|
2020-07-15 01:29:15 +02:00
|
|
|
"t", list, filterer_opts,
|
2020-05-10 12:45:16 +02:00
|
|
|
),
|
2020-07-15 01:29:15 +02:00
|
|
|
["two", "three"],
|
2020-05-10 12:45:16 +02:00
|
|
|
);
|
|
|
|
});
|
2020-05-28 19:58:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("render item", () => {
|
2020-05-28 19:58:51 +02:00
|
|
|
const container = make_container();
|
2020-07-16 23:29:01 +02:00
|
|
|
const scroll_container = make_scroll_container();
|
2020-05-28 19:58:51 +02:00
|
|
|
const INITIAL_RENDER_COUNT = 80; // Keep this in sync with the actual code.
|
|
|
|
container.html = () => {};
|
|
|
|
let called = false;
|
|
|
|
scroll_container.find = (query) => {
|
|
|
|
const expected_queries = [`tr[data-item='${INITIAL_RENDER_COUNT}']`,
|
|
|
|
`tr[data-item='${INITIAL_RENDER_COUNT - 1}']`];
|
|
|
|
const item = INITIAL_RENDER_COUNT - 1;
|
|
|
|
const new_html = `<tr data-item=${item}>updated: ${item}</tr>\n`;
|
2020-07-16 23:08:05 +02:00
|
|
|
const regex = new RegExp(`\\<tr data-item=${item}\\>.*?<\\/tr\\>`);
|
2020-05-28 19:58:51 +02:00
|
|
|
assert(expected_queries.includes(query));
|
|
|
|
if (query.includes(`data-item='${INITIAL_RENDER_COUNT}'`)) {
|
|
|
|
return; // This item is not rendered, so we find nothing
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
// Return a JQuery stub for the original HTML.
|
|
|
|
// We want this to be called when we replace
|
|
|
|
// the existing HTML with newly rendered HTML.
|
|
|
|
replaceWith: (html) => {
|
|
|
|
assert.equal(new_html, html);
|
|
|
|
called = true;
|
|
|
|
container.appended_data.replace(regex, new_html);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const list = [...Array(100).keys()];
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let text = "initial";
|
2020-05-28 19:58:51 +02:00
|
|
|
const get_item = (item) => ({text: `${text}: ${item}`, value: item});
|
|
|
|
|
|
|
|
const widget = list_render.create(container, list, {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "replace-list",
|
2020-05-28 19:58:51 +02:00
|
|
|
modifier: (item) => `<tr data-item=${item.value}>${item.text}</tr>\n`,
|
|
|
|
get_item: get_item,
|
|
|
|
html_selector: (item) => `tr[data-item='${item}']`,
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-05-28 19:58:51 +02:00
|
|
|
});
|
|
|
|
const item = INITIAL_RENDER_COUNT - 1;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(container.appended_data.html().includes("<tr data-item=2>initial: 2</tr>"));
|
|
|
|
assert(container.appended_data.html().includes("<tr data-item=3>initial: 3</tr>"));
|
|
|
|
text = "updated";
|
2020-05-28 19:58:51 +02:00
|
|
|
called = false;
|
|
|
|
widget.render_item(INITIAL_RENDER_COUNT - 1);
|
|
|
|
assert(called);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(container.appended_data.html().includes("<tr data-item=2>initial: 2</tr>"));
|
2020-05-28 19:58:51 +02:00
|
|
|
assert(container.appended_data.html().includes(`<tr data-item=${item}>updated: ${item}</tr>`));
|
|
|
|
|
|
|
|
// Item 80 should not be in the rendered list. (0 indexed)
|
|
|
|
assert(!container.appended_data.html().includes(`<tr data-item=${INITIAL_RENDER_COUNT}>initial: ${INITIAL_RENDER_COUNT}</tr>`));
|
|
|
|
called = false;
|
|
|
|
widget.render_item(INITIAL_RENDER_COUNT);
|
|
|
|
assert(!called);
|
|
|
|
widget.render_item(INITIAL_RENDER_COUNT - 1);
|
|
|
|
assert(called);
|
|
|
|
|
|
|
|
// Tests below this are for the corner cases, where we abort the rerender.
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "html_selector should be a function.");
|
2020-05-28 19:58:51 +02:00
|
|
|
list_render.create(container, list, {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "replace-list",
|
2020-05-28 19:58:51 +02:00
|
|
|
modifier: (item) => `<tr data-item=${item.value}>${item.text}</tr>\n`,
|
|
|
|
get_item: get_item,
|
2020-07-15 01:29:15 +02:00
|
|
|
html_selector: "hello world",
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-05-28 19:58:51 +02:00
|
|
|
});
|
|
|
|
blueslip.reset();
|
|
|
|
|
|
|
|
let get_item_called;
|
|
|
|
const widget_2 = list_render.create(container, list, {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "replace-list",
|
2020-05-28 19:58:51 +02:00
|
|
|
modifier: (item) => `<tr data-item=${item.value}>${item.text}</tr>\n`,
|
|
|
|
get_item: (item) => {
|
|
|
|
get_item_called = true;
|
|
|
|
return item;
|
|
|
|
},
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-05-28 19:58:51 +02:00
|
|
|
});
|
|
|
|
get_item_called = false;
|
|
|
|
widget_2.render_item(item);
|
|
|
|
// Test that we didn't try to render the item.
|
|
|
|
assert(!get_item_called);
|
|
|
|
|
|
|
|
let rendering_item = false;
|
|
|
|
const widget_3 = list_render.create(container, list, {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "replace-list",
|
2020-07-02 01:41:40 +02:00
|
|
|
modifier: (item) => rendering_item ? undefined : `${item}\n`,
|
2020-05-28 19:58:51 +02:00
|
|
|
get_item: get_item,
|
|
|
|
html_selector: (item) => `tr[data-item='${item}']`,
|
2020-07-04 10:07:43 +02:00
|
|
|
simplebar_container: scroll_container,
|
2020-05-28 19:58:51 +02:00
|
|
|
});
|
|
|
|
// Once we have initially rendered the widget, change the
|
|
|
|
// behavior of the modifier function.
|
|
|
|
rendering_item = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "List item is not a string: undefined");
|
2020-05-28 19:58:51 +02:00
|
|
|
widget_3.render_item(item);
|
|
|
|
blueslip.reset();
|
|
|
|
});
|