diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2018-06-01 19:41:50 +0300 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2018-06-01 19:41:50 +0300 |
commit | 30bc82f68b6de69a2e456286888824fa0221d4a7 (patch) | |
tree | 32597a02aa74ed80a3370c3f08dda12d152c5b68 /spec | |
parent | abe98d44e8902a3f721c0f17cc20dc55bcb2d2f6 (diff) |
Revert "Merge branch '46833-sticky-polyfill' into 'master'"
This reverts merge request !19304
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/lib/utils/sticky_spec.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/sticky_spec.js b/spec/javascripts/lib/utils/sticky_spec.js new file mode 100644 index 00000000000..b87c836654d --- /dev/null +++ b/spec/javascripts/lib/utils/sticky_spec.js @@ -0,0 +1,79 @@ +import { isSticky } from '~/lib/utils/sticky'; + +describe('sticky', () => { + let el; + + beforeEach(() => { + document.body.innerHTML += ` + <div class="parent"> + <div id="js-sticky"></div> + </div> + `; + + el = document.getElementById('js-sticky'); + }); + + afterEach(() => { + el.parentNode.remove(); + }); + + describe('when stuck', () => { + it('does not remove is-stuck class', () => { + isSticky(el, 0, el.offsetTop); + isSticky(el, 0, el.offsetTop); + + expect( + el.classList.contains('is-stuck'), + ).toBeTruthy(); + }); + + it('adds is-stuck class', () => { + isSticky(el, 0, el.offsetTop); + + expect( + el.classList.contains('is-stuck'), + ).toBeTruthy(); + }); + + it('inserts placeholder element', () => { + isSticky(el, 0, el.offsetTop, true); + + expect( + document.querySelector('.sticky-placeholder'), + ).not.toBeNull(); + }); + }); + + describe('when not stuck', () => { + it('removes is-stuck class', () => { + spyOn(el.classList, 'remove').and.callThrough(); + + isSticky(el, 0, el.offsetTop); + isSticky(el, 0, 0); + + expect( + el.classList.remove, + ).toHaveBeenCalledWith('is-stuck'); + expect( + el.classList.contains('is-stuck'), + ).toBeFalsy(); + }); + + it('does not add is-stuck class', () => { + isSticky(el, 0, 0); + + expect( + el.classList.contains('is-stuck'), + ).toBeFalsy(); + }); + + it('removes placeholder', () => { + isSticky(el, 0, el.offsetTop, true); + isSticky(el, 0, 0, true); + + expect( + document.querySelector('.sticky-placeholder'), + ).toBeNull(); + }); + }); +}); |