Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
f389f908
Commit
f389f908
authored
Sep 25, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor tests to actually test browser behaviour
parent
65415e32
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
49 deletions
+38
-49
app/assets/javascripts/lib/utils/sticky.js
app/assets/javascripts/lib/utils/sticky.js
+1
-1
spec/javascripts/lib/utils/sticky_spec.js
spec/javascripts/lib/utils/sticky_spec.js
+37
-48
No files found.
app/assets/javascripts/lib/utils/sticky.js
View file @
f389f908
...
@@ -22,7 +22,7 @@ export const isSticky = (el, scrollY, stickyTop, insertPlaceholder) => {
...
@@ -22,7 +22,7 @@ export const isSticky = (el, scrollY, stickyTop, insertPlaceholder) => {
}
else
if
(
top
>
stickyTop
&&
el
.
classList
.
contains
(
'
is-stuck
'
))
{
}
else
if
(
top
>
stickyTop
&&
el
.
classList
.
contains
(
'
is-stuck
'
))
{
el
.
classList
.
remove
(
'
is-stuck
'
);
el
.
classList
.
remove
(
'
is-stuck
'
);
if
(
insertPlaceholder
&&
el
.
nextElementSibling
.
classList
.
contains
(
'
sticky-placeholder
'
))
{
if
(
insertPlaceholder
&&
el
.
nextElementSibling
&&
el
.
nextElementSibling
.
classList
.
contains
(
'
sticky-placeholder
'
))
{
el
.
nextElementSibling
.
remove
();
el
.
nextElementSibling
.
remove
();
}
}
}
}
...
...
spec/javascripts/lib/utils/sticky_spec.js
View file @
f389f908
import
{
isSticky
}
from
'
~/lib/utils/sticky
'
;
import
{
isSticky
}
from
'
~/lib/utils/sticky
'
;
describe
(
'
sticky
'
,
()
=>
{
describe
(
'
sticky
'
,
()
=>
{
const
el
=
{
let
el
;
offsetTop
:
0
,
classList
:
{},
parentNode
:
{},
nextElementSibling
:
{},
};
let
isStuck
=
false
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
el
.
offsetTop
=
0
;
document
.
body
.
innerHTML
=
`
el
.
classList
.
add
=
jasmine
.
createSpy
(
'
classListAdd
'
);
<div class="parent">
el
.
classList
.
remove
=
jasmine
.
createSpy
(
'
classListRemove
'
);
<div id="js-sticky" style="position: relative;"></div>
el
.
classList
.
contains
=
jasmine
.
createSpy
(
'
classListContains
'
).
and
.
callFake
(()
=>
isStuck
);
</div>
el
.
parentNode
.
insertBefore
=
jasmine
.
createSpy
(
'
insertBefore
'
);
`
;
el
.
nextElementSibling
.
remove
=
jasmine
.
createSpy
(
'
nextElementSibling
'
);
el
.
nextElementSibling
.
classList
=
{
contains
:
jasmine
.
createSpy
(
'
classListContains
'
).
and
.
returnValue
(
true
),
};
});
afterEach
(()
=>
{
el
=
document
.
getElementById
(
'
js-sticky
'
);
isStuck
=
false
;
});
});
describe
(
'
classList.remove
'
,
()
=>
{
describe
(
'
when stuck
'
,
()
=>
{
it
(
'
does not call classList.remove when stuck
'
,
()
=>
{
it
(
'
does not remove is-stuck class
'
,
()
=>
{
isSticky
(
el
,
0
,
0
);
isSticky
(
el
,
0
,
el
.
offsetTop
);
isSticky
(
el
,
0
,
el
.
offsetTop
);
expect
(
expect
(
el
.
classList
.
remove
,
el
.
classList
.
contains
(
'
is-stuck
'
)
,
).
not
.
toHaveBeenCalled
();
).
toBeTruthy
();
});
});
it
(
'
calls classList.remove when no longer stuck
'
,
()
=>
{
it
(
'
adds is-stuck class
'
,
()
=>
{
isStuck
=
true
;
isSticky
(
el
,
0
,
el
.
offsetTop
);
el
.
offsetTop
=
10
;
isSticky
(
el
,
0
,
0
);
expect
(
expect
(
el
.
classList
.
remove
,
el
.
classList
.
contains
(
'
is-stuck
'
)
,
).
to
HaveBeenCalledWith
(
'
is-stuck
'
);
).
to
BeTruthy
(
);
});
});
it
(
'
removes placeholder when no longer stuck
'
,
()
=>
{
it
(
'
inserts placeholder element
'
,
()
=>
{
isStuck
=
true
;
isSticky
(
el
,
0
,
el
.
offsetTop
,
true
);
el
.
offsetTop
=
10
;
isSticky
(
el
,
0
,
0
,
true
);
expect
(
expect
(
el
.
nextElementSibling
.
remove
,
document
.
querySelector
(
'
.sticky-placeholder
'
)
,
).
toHaveBeenCalled
();
).
not
.
toBeNull
();
});
});
});
});
describe
(
'
classList.add
'
,
()
=>
{
describe
(
'
when not stuck
'
,
()
=>
{
it
(
'
calls classList.add when stuck
'
,
()
=>
{
it
(
'
removes is-stuck class
'
,
()
=>
{
spyOn
(
el
.
classList
,
'
remove
'
).
and
.
callThrough
();
isSticky
(
el
,
0
,
el
.
offsetTop
);
isSticky
(
el
,
0
,
0
);
isSticky
(
el
,
0
,
0
);
expect
(
expect
(
el
.
classList
.
add
,
el
.
classList
.
remove
,
).
toHaveBeenCalledWith
(
'
is-stuck
'
);
).
toHaveBeenCalledWith
(
'
is-stuck
'
);
expect
(
el
.
classList
.
contains
(
'
is-stuck
'
),
).
toBeFalsy
();
});
});
it
(
'
does not call classList.add when not stuck
'
,
()
=>
{
it
(
'
does not add is-stuck class
'
,
()
=>
{
el
.
offsetTop
=
10
;
isSticky
(
el
,
0
,
0
);
isSticky
(
el
,
0
,
0
);
expect
(
expect
(
el
.
classList
.
add
,
el
.
classList
.
contains
(
'
is-stuck
'
)
,
).
not
.
toHaveBeenCalled
();
).
toBeFalsy
();
});
});
it
(
'
inserts placeholder element when stuck
'
,
()
=>
{
it
(
'
removes placeholder
'
,
()
=>
{
isSticky
(
el
,
0
,
el
.
offsetTop
,
true
);
isSticky
(
el
,
0
,
0
,
true
);
isSticky
(
el
,
0
,
0
,
true
);
expect
(
expect
(
el
.
parentNode
.
insertBefore
,
document
.
querySelector
(
'
.sticky-placeholder
'
)
,
).
to
HaveBeenCalled
();
).
to
BeNull
();
});
});
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment