summaryrefslogtreecommitdiff
path: root/spec/javascripts/lib
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-09-15 09:01:58 +0100
committerPhil Hughes <me@iamphill.com>2017-09-22 11:13:19 +0100
commit734bb736258293e213fb0580f1f0b15618a78bc2 (patch)
treea1daddfb3c2b9606bc7145367c43755d8766a874 /spec/javascripts/lib
parent7ce70dd5a046048ef13eb5f93ece8f149bfbaea3 (diff)
downloadgitlab-ce-734bb736258293e213fb0580f1f0b15618a78bc2.tar.gz
fixed and added specs for removing placeholder element
Diffstat (limited to 'spec/javascripts/lib')
-rw-r--r--spec/javascripts/lib/utils/sticky_spec.js40
1 files changed, 37 insertions, 3 deletions
diff --git a/spec/javascripts/lib/utils/sticky_spec.js b/spec/javascripts/lib/utils/sticky_spec.js
index c3ee3ef9825..5ffc41589e5 100644
--- a/spec/javascripts/lib/utils/sticky_spec.js
+++ b/spec/javascripts/lib/utils/sticky_spec.js
@@ -4,12 +4,25 @@ describe('sticky', () => {
const el = {
offsetTop: 0,
classList: {},
+ parentNode: {},
+ nextElementSibling: {},
};
+ let isStuck = false;
beforeEach(() => {
el.offsetTop = 0;
- el.classList.add = jasmine.createSpy('spy');
- el.classList.remove = jasmine.createSpy('spy');
+ el.classList.add = jasmine.createSpy('classListAdd');
+ el.classList.remove = jasmine.createSpy('classListRemove');
+ el.classList.contains = jasmine.createSpy('classListContains').and.callFake(() => isStuck);
+ el.parentNode.insertBefore = jasmine.createSpy('insertBefore');
+ el.nextElementSibling.remove = jasmine.createSpy('nextElementSibling');
+ el.nextElementSibling.classList = {
+ contains: jasmine.createSpy('classListContains').and.returnValue(true),
+ };
+ });
+
+ afterEach(() => {
+ isStuck = false;
});
describe('classList.remove', () => {
@@ -21,7 +34,9 @@ describe('sticky', () => {
).not.toHaveBeenCalled();
});
- it('calls classList.remove when not stuck', () => {
+ it('calls classList.remove when no longer stuck', () => {
+ isStuck = true;
+
el.offsetTop = 10;
isSticky(el, 0, 0);
@@ -29,6 +44,17 @@ describe('sticky', () => {
el.classList.remove,
).toHaveBeenCalledWith('is-stuck');
});
+
+ it('removes placeholder when no longer stuck', () => {
+ isStuck = true;
+
+ el.offsetTop = 10;
+ isSticky(el, 0, 0, true);
+
+ expect(
+ el.nextElementSibling.remove,
+ ).toHaveBeenCalled();
+ });
});
describe('classList.add', () => {
@@ -48,5 +74,13 @@ describe('sticky', () => {
el.classList.add,
).not.toHaveBeenCalled();
});
+
+ it('inserts placeholder element when stuck', () => {
+ isSticky(el, 0, 0, true);
+
+ expect(
+ el.parentNode.insertBefore,
+ ).toHaveBeenCalled();
+ });
});
});