diff options
Diffstat (limited to 'spec/frontend/lib/utils/scroll_utils_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/scroll_utils_spec.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/scroll_utils_spec.js b/spec/frontend/lib/utils/scroll_utils_spec.js new file mode 100644 index 00000000000..d42e25b929c --- /dev/null +++ b/spec/frontend/lib/utils/scroll_utils_spec.js @@ -0,0 +1,21 @@ +import { isScrolledToBottom } from '~/lib/utils/scroll_utils'; + +describe('isScrolledToBottom', () => { + const setScrollGetters = (getters) => { + Object.entries(getters).forEach(([name, value]) => { + jest.spyOn(Element.prototype, name, 'get').mockReturnValue(value); + }); + }; + + it.each` + context | scrollTop | scrollHeight | result + ${'returns false when not scrolled to bottom'} | ${0} | ${2000} | ${false} + ${'returns true when scrolled to bottom'} | ${1000} | ${2000} | ${true} + ${'returns true when scrolled to bottom with subpixel precision'} | ${999.25} | ${2000} | ${true} + ${'returns true when cannot scroll'} | ${0} | ${500} | ${true} + `('$context', ({ scrollTop, scrollHeight, result }) => { + setScrollGetters({ scrollTop, clientHeight: 1000, scrollHeight }); + + expect(isScrolledToBottom()).toBe(result); + }); +}); |