Add a unit-test to check that the sortByVisibility parameter, in getVisibleElements, works correctly

This commit is contained in:
Jonas Jenwald 2019-01-12 11:00:51 +01:00
parent 9743708a24
commit b2235ec9c4

View File

@ -690,6 +690,34 @@ describe('ui_utils', function() {
scrollOverDocument(pages, true); 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() { it('handles views being empty', function() {
const scrollEl = { const scrollEl = {
scrollTop: 10, scrollTop: 10,