node tests: Bring list_cursor to 100% coverage.

We had some indirect coverage of this already, so
this mostly focuses on error cases and corner
cases.
This commit is contained in:
Steve Howell 2018-08-24 12:39:22 +00:00 committed by Tim Abbott
parent eb7f7fae55
commit bee592b44e
2 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,80 @@
zrequire('list_cursor');
set_global('blueslip', global.make_zblueslip());
run_test('config errors', () => {
blueslip.set_test_data('error', 'Programming error');
list_cursor({});
});
function basic_conf() {
const list = {
scroll_container_sel: 'whatever',
find_li: () => {},
first_key: () => {},
prev_key: () => {},
next_key: () => {},
};
const conf = {
list: list,
highlight_class: 'highlight',
};
return conf;
}
run_test('misc errors', () => {
const conf = basic_conf();
const cursor = list_cursor(conf);
// Test that we just ignore empty
// lists for unknown keys.
conf.list.find_li = (opts) => {
assert.equal(opts.key, 'nada');
assert.equal(opts.force_render, true);
return [];
};
cursor.get_row('nada');
blueslip.set_test_data('error', 'Caller is not checking keys for list_cursor.go_to');
cursor.go_to(undefined);
blueslip.set_test_data('error', 'Cannot highlight key for list_cursor: nada');
cursor.go_to('nada');
blueslip.clear_test_data();
cursor.prev();
cursor.next();
});
run_test('single item list', () => {
const conf = basic_conf();
const cursor = list_cursor(conf);
const valid_key = '42';
const li_stub = {
length: 1,
addClass: () => {},
};
cursor.adjust_scroll = () => {};
conf.list.find_li = () => {
return li_stub;
};
cursor.go_to(valid_key);
// Test prev/next, which should just silently do nothing.
// (Our basic_conf() has prev_key and next_key return undefined.)
blueslip.clear_test_data();
cursor.prev();
cursor.next();
// The next line is also a noop designed to just give us test
// coverage.
cursor.go_to(valid_key);
});

View File

@ -45,6 +45,7 @@ enforce_fully_covered = {
'static/js/filter.js', 'static/js/filter.js',
'static/js/hash_util.js', 'static/js/hash_util.js',
'static/js/keydown_util.js', 'static/js/keydown_util.js',
'static/js/list_cursor.js',
'static/js/markdown.js', 'static/js/markdown.js',
'static/js/message_store.js', 'static/js/message_store.js',
'static/js/muting.js', 'static/js/muting.js',