From 605a90ce36329d2c480efee3c08ee17fad1f4809 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 24 Apr 2018 12:28:24 +0000 Subject: [PATCH] node tests: Reach 100% coverage for scroll_util.js. --- frontend_tests/node_tests/scroll_util.js | 38 ++++++++++++++++++++++++ tools/test-js-with-node | 1 + 2 files changed, 39 insertions(+) diff --git a/frontend_tests/node_tests/scroll_util.js b/frontend_tests/node_tests/scroll_util.js index a09c9c6497..b3d2e79b8b 100644 --- a/frontend_tests/node_tests/scroll_util.js +++ b/frontend_tests/node_tests/scroll_util.js @@ -53,3 +53,41 @@ zrequire('scroll_util'); })); }()); + +(function test_scroll_element_into_container() { + const container = (function () { + var top = 3; + return { + height: () => 100, + scrollTop: (arg) => { + if (arg === undefined) { + return top; + } + top = arg; + }, + }; + }()); + + const elem1 = { + height: () => 25, + position: () => { + return { + top: 0, + }; + }, + }; + scroll_util.scroll_element_into_container(elem1, container); + assert.equal(container.scrollTop(), 3); + + const elem2 = { + height: () => 15, + position: () => { + return { + top: 250, + }; + }, + }; + scroll_util.scroll_element_into_container(elem2, container); + assert.equal(container.scrollTop(), 250 - 100 + 3 + 15); +}()); + diff --git a/tools/test-js-with-node b/tools/test-js-with-node index c25f101ed5..95d8bc4522 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -54,6 +54,7 @@ enforce_fully_covered = { 'static/js/reactions.js', 'static/js/recent_senders.js', 'static/js/rtl.js', + 'static/js/scroll_util.js', 'static/js/search_suggestion.js', # Removed because we're migrating code from uncovered other settings pages to here. # 'static/js/settings_ui.js',