From b2235ec9c46c1e7b5a47dd4d5034fcc856ab6fd3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 12 Jan 2019 11:00:51 +0100 Subject: [PATCH] Add a unit-test to check that the `sortByVisibility` parameter, in `getVisibleElements`, works correctly --- test/unit/ui_utils_spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/unit/ui_utils_spec.js b/test/unit/ui_utils_spec.js index 84a2bed10..aaab50cd2 100644 --- a/test/unit/ui_utils_spec.js +++ b/test/unit/ui_utils_spec.js @@ -690,6 +690,34 @@ describe('ui_utils', function() { scrollOverDocument(pages, true); }); + it('handles `sortByVisibility` correctly', function() { + const scrollEl = { + scrollTop: 75, + scrollLeft: 0, + clientHeight: 750, + clientWidth: 1500, + }; + const views = makePages([ + [[100, 150]], + [[100, 150]], + [[100, 150]], + ]); + + const visible = getVisibleElements(scrollEl, views); + const visibleSorted = getVisibleElements(scrollEl, views, + /* sortByVisibility = */ true); + + const viewsOrder = [], viewsSortedOrder = []; + for (const view of visible.views) { + viewsOrder.push(view.id); + } + for (const view of visibleSorted.views) { + viewsSortedOrder.push(view.id); + } + expect(viewsOrder).toEqual([0, 1, 2]); + expect(viewsSortedOrder).toEqual([1, 2, 0]); + }); + it('handles views being empty', function() { const scrollEl = { scrollTop: 10,