From 94761b806ca02a40adaea437bb8c3d188d919b68 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 6 Jan 2020 15:49:53 +0000 Subject: [PATCH] node tests: Restore 100% coverage to pm_list. --- frontend_tests/node_tests/pm_list.js | 56 ++++++++++++++++++++++++++++ tools/test-js-with-node | 1 + 2 files changed, 57 insertions(+) diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js index d31603ab0d..ccc4de6994 100644 --- a/frontend_tests/node_tests/pm_list.js +++ b/frontend_tests/node_tests/pm_list.js @@ -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(); +}); diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 16df1b1a1b..61c47b96b6 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -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',