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
Léo-Paul Géneau
gitlab-ce
Commits
203185fe
Commit
203185fe
authored
Apr 13, 2018
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for shortcuts_dashboard_navigation.js
parent
7ec607d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
app/assets/javascripts/shortcuts_dashboard_navigation.js
app/assets/javascripts/shortcuts_dashboard_navigation.js
+5
-3
spec/javascripts/shortcuts_dashboard_navigation_spec.js
spec/javascripts/shortcuts_dashboard_navigation_spec.js
+24
-0
No files found.
app/assets/javascripts/shortcuts_dashboard_navigation.js
View file @
203185fe
import
{
visitUrl
}
from
'
./lib/utils/url_utility
'
;
/**
/**
* Helper function that finds the href of the fiven selector and updates the location.
* Helper function that finds the href of the fiven selector and updates the location.
*
*
* @param {String} selector
* @param {String} selector
*/
*/
export
default
selector
=>
{
export
default
function
findAndFollowLink
(
selector
)
{
const
element
=
document
.
querySelector
(
selector
);
const
element
=
document
.
querySelector
(
selector
);
const
link
=
element
&&
element
.
getAttribute
(
'
href
'
);
const
link
=
element
&&
element
.
getAttribute
(
'
href
'
);
if
(
link
)
{
if
(
link
)
{
window
.
location
=
link
;
visitUrl
(
link
)
;
}
}
}
;
}
spec/javascripts/shortcuts_dashboard_navigation_spec.js
0 → 100644
View file @
203185fe
import
findAndFollowLink
from
'
~/shortcuts_dashboard_navigation
'
;
import
*
as
urlUtility
from
'
~/lib/utils/url_utility
'
;
describe
(
'
findAndFollowLink
'
,
()
=>
{
it
(
'
visits a link when the selector exists
'
,
()
=>
{
const
href
=
'
/some/path
'
;
const
locationSpy
=
spyOn
(
urlUtility
,
'
visitUrl
'
);
setFixtures
(
`<a class="my-shortcut" href="
${
href
}
">link</a>`
);
findAndFollowLink
(
'
.my-shortcut
'
);
expect
(
locationSpy
).
toHaveBeenCalledWith
(
href
);
});
it
(
'
does not throw an exception when the selector does not exist
'
,
()
=>
{
const
locationSpy
=
spyOn
(
urlUtility
,
'
visitUrl
'
);
// this should not throw an exception
findAndFollowLink
(
'
.this-selector-does-not-exist
'
);
expect
(
locationSpy
).
not
.
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