node tests: Restore 100% coverage to pm_list.

This commit is contained in:
Steve Howell
2020-01-06 15:49:53 +00:00
committed by Tim Abbott
parent c22c796f1d
commit 94761b806c
2 changed files with 57 additions and 0 deletions

View File

@@ -291,3 +291,59 @@ run_test('is_all_privates', () => {
pm_list.is_all_privates(),
true);
});
function with_fake_list(f) {
const orig = pm_list._build_private_messages_list;
pm_list._build_private_messages_list = () => {
return 'PM_LIST_CONTENTS';
};
f();
pm_list._build_private_messages_list = orig;
}
run_test('expand', () => {
with_fake_list(() => {
let html_inserted;
$('#private-container').html = function (html) {
assert.equal(html, 'PM_LIST_CONTENTS');
html_inserted = true;
};
pm_list.expand();
assert(html_inserted);
});
});
run_test('update_private_messages', () => {
narrow_state.active = () => true;
with_fake_list(() => {
let html_inserted;
$('#private-container').html = function (html) {
assert.equal(html, 'PM_LIST_CONTENTS');
html_inserted = true;
};
const orig_is_all_privates = pm_list.is_all_privates;
pm_list.is_all_privates = () => true;
pm_list.update_private_messages();
assert(html_inserted);
assert($(".top_left_private_messages").hasClass('active-filter'));
pm_list.is_all_privates = orig_is_all_privates;
});
});
run_test('ensure coverage', () => {
// These aren't rigorous; they just cover cases
// where functions early exit.
narrow_state.active = () => false;
pm_list.rebuild_recent = () => {
throw Error('we should not call rebuild_recent');
};
pm_list.update_private_messages();
});

View File

@@ -59,6 +59,7 @@ enforce_fully_covered = {
'static/js/narrow_state.js',
'static/js/people.js',
'static/js/pm_conversations.js',
'static/js/pm_list.js',
'static/js/presence.js',
'static/js/reactions.js',
'static/js/recent_senders.js',