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,