mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-09 23:06:06 +00:00
Navigation.go supports full URLs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory 'Navigation', ($location) ->
|
||||
Darkswarm.factory 'Navigation', ($location, $window) ->
|
||||
new class Navigation
|
||||
path: null
|
||||
|
||||
@@ -10,7 +10,6 @@ Darkswarm.factory 'Navigation', ($location) ->
|
||||
$location.path(@path)
|
||||
|
||||
toggle: (path = false)=>
|
||||
console.log "toggling"
|
||||
@path = path || @path
|
||||
if $location.path() == @path
|
||||
$location.path("/")
|
||||
@@ -18,4 +17,7 @@ Darkswarm.factory 'Navigation', ($location) ->
|
||||
@navigate(path)
|
||||
|
||||
go: (path)->
|
||||
window.location.pathname = path
|
||||
if path.match /^http/
|
||||
$window.location.href = path
|
||||
else
|
||||
$window.location.pathname = path
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
describe 'Navigation service', ->
|
||||
Navigation = null
|
||||
|
||||
window =
|
||||
location:
|
||||
href: null
|
||||
pathname: null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
module 'Darkswarm', ($provide) ->
|
||||
$provide.value "$window", window
|
||||
null
|
||||
inject ($injector)->
|
||||
Navigation = $injector.get("Navigation")
|
||||
|
||||
|
||||
it "caches the path provided", ->
|
||||
Navigation.navigate "/foo"
|
||||
expect(Navigation.path).toEqual "/foo"
|
||||
|
||||
describe "redirecting", ->
|
||||
it "redirects to full URLs", ->
|
||||
Navigation.go "http://google.com"
|
||||
expect(window.location.href).toEqual "http://google.com"
|
||||
|
||||
it "redirects to paths", ->
|
||||
Navigation.go "/woo/yeah"
|
||||
expect(window.location.pathname).toEqual "/woo/yeah"
|
||||
|
||||
Reference in New Issue
Block a user