Merge remote-tracking branch 'origin/master' into HEAD

This commit is contained in:
Buildkite
2018-06-22 00:59:28 +00:00
4 changed files with 11 additions and 12 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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'}

View File

@@ -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"