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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
5e4b18ee
Commit
5e4b18ee
authored
Jul 19, 2017
by
Luke "Jared" Bennett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished scroll_helper tests
parent
99193d82
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
4 deletions
+44
-4
app/assets/javascripts/helpers/scroll_helper.js
app/assets/javascripts/helpers/scroll_helper.js
+2
-1
spec/javascripts/helpers/scroll_helper_spec.js
spec/javascripts/helpers/scroll_helper_spec.js
+42
-3
No files found.
app/assets/javascripts/helpers/scroll_helper.js
View file @
5e4b18ee
...
...
@@ -9,10 +9,11 @@ const ScrollHelper = {
});
const
$ruler
=
$
(
'
<div>
'
).
css
({
width
:
'
100%
'
,
width
:
100
,
});
$ruler
.
appendTo
(
$rulerContainer
);
$rulerContainer
.
appendTo
(
'
body
'
);
const
scrollWidth
=
$ruler
.
outerWidth
();
...
...
spec/javascripts/helpers/scroll_helper_spec.js
View file @
5e4b18ee
...
...
@@ -2,17 +2,56 @@ import $ from 'jquery';
import
ScrollHelper
from
'
~/helpers/scroll_helper
'
;
describe
(
'
ScrollHelper
'
,
()
=>
{
describe
(
'
setScrollWidth
'
,
()
=>
{
it
(
'
calls getScrollWidth and sets data-scroll-width
'
,
()
=>
{
const
width
=
10
;
describe
(
'
getScrollWidth
'
,
()
=>
{
const
parent
=
jasmine
.
createSpyObj
(
'
parent
'
,
[
'
css
'
,
'
appendTo
'
,
'
remove
'
]);
const
child
=
jasmine
.
createSpyObj
(
'
child
'
,
[
'
css
'
,
'
appendTo
'
,
'
outerWidth
'
]);
let
scrollWidth
;
beforeEach
(()
=>
{
spyOn
(
$
.
fn
,
'
init
'
).
and
.
returnValues
(
parent
,
child
);
spyOn
(
jasmine
.
Fixtures
.
prototype
,
'
cleanUp
'
);
// disable jasmine-jquery cleanup, we dont want it but its imported in test_bundle :(
parent
.
css
.
and
.
returnValue
(
parent
);
child
.
css
.
and
.
returnValue
(
child
);
child
.
outerWidth
.
and
.
returnValue
(
width
);
scrollWidth
=
ScrollHelper
.
getScrollWidth
();
});
it
(
'
inserts 2 nested hidden scrollable divs, calls parents outerWidth, removes parent and returns the width
'
,
()
=>
{
const
initArgs
=
$
.
fn
.
init
.
calls
.
allArgs
();
expect
(
initArgs
[
0
][
0
]).
toEqual
(
'
<div>
'
);
expect
(
initArgs
[
1
][
0
]).
toEqual
(
'
<div>
'
);
expect
(
parent
.
css
).
toHaveBeenCalledWith
({
visibility
:
'
hidden
'
,
width
:
100
,
overflow
:
'
scroll
'
,
});
expect
(
child
.
css
).
toHaveBeenCalledWith
({
width
:
100
,
});
expect
(
child
.
appendTo
).
toHaveBeenCalledWith
(
parent
);
expect
(
parent
.
appendTo
).
toHaveBeenCalledWith
(
'
body
'
);
expect
(
child
.
outerWidth
).
toHaveBeenCalled
();
expect
(
parent
.
remove
).
toHaveBeenCalled
();
expect
(
scrollWidth
).
toEqual
(
100
-
width
);
});
});
describe
(
'
setScrollWidth
'
,
()
=>
{
it
(
'
calls getScrollWidth and sets data-scroll-width
'
,
()
=>
{
spyOn
(
$
.
fn
,
'
find
'
).
and
.
callThrough
();
spyOn
(
$
.
fn
,
'
attr
'
);
spyOn
(
ScrollHelper
,
'
getScrollWidth
'
).
and
.
returnValue
(
width
);
ScrollHelper
.
setScrollWidth
();
expect
(
ScrollHelper
.
getScrollWidth
).
toHaveBeenCalled
(
);
expect
(
$
.
fn
.
find
).
toHaveBeenCalledWith
(
'
body
'
);
expect
(
$
.
fn
.
attr
).
toHaveBeenCalledWith
(
'
data-scroll-width
'
,
width
);
expect
(
ScrollHelper
.
getScrollWidth
).
toHaveBeenCalled
();
});
});
});
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