mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Merge remote-tracking branch 'origin/master' into HEAD
This commit is contained in:
@@ -13,7 +13,7 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE
|
||||
submit: =>
|
||||
Loading.message = t 'submitting_order'
|
||||
$http.put('/checkout.json', {order: @preprocess()}).success (data, status)=>
|
||||
Navigation.goWithoutHashFragments data.path
|
||||
Navigation.go data.path
|
||||
.error (response, status)=>
|
||||
if response.path
|
||||
Navigation.go response.path
|
||||
|
||||
@@ -16,15 +16,10 @@ Darkswarm.factory 'Navigation', ($location, $window) ->
|
||||
else
|
||||
@navigate(path)
|
||||
|
||||
goWithoutHashFragments: (path) ->
|
||||
# Redirects to specified path, without Angular hash fragments such as '#/login'
|
||||
$window.location.href = $window.location.origin + path
|
||||
|
||||
go: (path)->
|
||||
if path.match /^http/
|
||||
$window.location.href = path
|
||||
else
|
||||
$window.location.pathname = path
|
||||
# The browser treats this like clicking on a link.
|
||||
# It works for absolute paths, relative paths and URLs alike.
|
||||
$window.location.href = path
|
||||
|
||||
reload: ->
|
||||
$window.location.reload()
|
||||
|
||||
@@ -95,6 +95,12 @@ describe 'Checkout service', ->
|
||||
Checkout.submit()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "Redirects to the returned path", ->
|
||||
$httpBackend.expectPUT("/checkout.json", {order: Checkout.preprocess()}).respond 200, {path: "/test"}
|
||||
Checkout.submit()
|
||||
$httpBackend.flush()
|
||||
expect(Navigation.go).toHaveBeenCalledWith '/test'
|
||||
|
||||
describe "when there is an error", ->
|
||||
it "redirects when a redirect is given", ->
|
||||
$httpBackend.expectPUT("/checkout.json").respond 400, {path: 'path'}
|
||||
|
||||
@@ -3,7 +3,6 @@ describe 'Navigation service', ->
|
||||
window =
|
||||
location:
|
||||
href: null
|
||||
pathname: null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm', ($provide) ->
|
||||
@@ -24,5 +23,4 @@ describe 'Navigation service', ->
|
||||
|
||||
it "redirects to paths", ->
|
||||
Navigation.go "/woo/yeah"
|
||||
expect(window.location.pathname).toEqual "/woo/yeah"
|
||||
|
||||
expect(window.location.href).toEqual "/woo/yeah"
|
||||
|
||||
Reference in New Issue
Block a user