diff options
author | Kushal Pandya <kushalspandya@gmail.com> | 2019-01-08 16:07:21 +0300 |
---|---|---|
committer | Kushal Pandya <kushalspandya@gmail.com> | 2019-01-08 16:07:21 +0300 |
commit | 214d741ba5caf1e533873bba1b8f030e80774d72 (patch) | |
tree | 1e56a419805e6cf2f217fdfe1b61f4657ac57d7b /spec/javascripts/lib | |
parent | e2667b765426e9201dab6a004e1ded3578a70283 (diff) |
Add support for `offset` values in `isInViewport`
Diffstat (limited to 'spec/javascripts/lib')
-rw-r--r-- | spec/javascripts/lib/utils/common_utils_spec.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index 1ec1e8a8dd9..f320f232687 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -716,4 +716,29 @@ describe('common_utils', () => { expect(commonUtils.roundOffFloat(34567.14159, -5)).toBe(0); }); }); + + describe('isInViewport', () => { + let el; + + beforeEach(() => { + el = document.createElement('div'); + }); + + afterEach(() => { + document.body.removeChild(el); + }); + + it('returns true when provided `el` is in viewport', () => { + document.body.appendChild(el); + + expect(commonUtils.isInViewport(el)).toBe(true); + }); + + it('returns false when provided `el` is not in viewport', () => { + el.setAttribute('style', 'position: absolute; top: -1000px; left: -1000px;'); + document.body.appendChild(el); + + expect(commonUtils.isInViewport(el)).toBe(false); + }); + }); }); |