mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Fixing up bugs in the Checkout form
This commit is contained in:
@@ -10,6 +10,7 @@ describe "CheckoutCtrl", ->
|
||||
Order =
|
||||
submit: ->
|
||||
navigate: ->
|
||||
bindFieldsToLocalStorage: ->
|
||||
order:
|
||||
id: 1
|
||||
public: "public"
|
||||
@@ -20,6 +21,7 @@ describe "CheckoutCtrl", ->
|
||||
beforeEach ->
|
||||
inject ($controller, $rootScope) ->
|
||||
scope = $rootScope.$new()
|
||||
spyOn(Order, "bindFieldsToLocalStorage")
|
||||
ctrl = $controller 'CheckoutCtrl', {$scope: scope, Order: Order, CurrentUser: {}}
|
||||
|
||||
it "delegates to the service on submit", ->
|
||||
@@ -32,6 +34,9 @@ describe "CheckoutCtrl", ->
|
||||
it "is enabled", ->
|
||||
expect(scope.enabled).toEqual true
|
||||
|
||||
it "triggers localStorage binding", ->
|
||||
expect(Order.bindFieldsToLocalStorage).toHaveBeenCalled()
|
||||
|
||||
describe "without user", ->
|
||||
beforeEach ->
|
||||
inject ($controller, $rootScope) ->
|
||||
|
||||
@@ -2,9 +2,9 @@ describe 'Order service', ->
|
||||
Order = null
|
||||
orderData = null
|
||||
$httpBackend = null
|
||||
CheckoutFormState = null
|
||||
Navigation = null
|
||||
flash = null
|
||||
storage = null
|
||||
|
||||
beforeEach ->
|
||||
orderData =
|
||||
@@ -15,6 +15,7 @@ describe 'Order service', ->
|
||||
firstname: "Robert"
|
||||
lastname: "Harrington"
|
||||
ship_address: {test: "bar"}
|
||||
user_id: 901
|
||||
shipping_methods:
|
||||
7:
|
||||
require_ship_address: true
|
||||
@@ -34,18 +35,29 @@ describe 'Order service', ->
|
||||
angular.module('Darkswarm').value('order', orderData)
|
||||
module 'Darkswarm'
|
||||
|
||||
inject ($injector, _$httpBackend_)->
|
||||
inject ($injector, _$httpBackend_, _storage_)->
|
||||
$httpBackend = _$httpBackend_
|
||||
storage = _storage_
|
||||
Order = $injector.get("Order")
|
||||
Navigation = $injector.get("Navigation")
|
||||
flash = $injector.get("flash")
|
||||
CheckoutFormState = $injector.get("CheckoutFormState")
|
||||
spyOn(Navigation, "go") # Stubbing out writes to window.location
|
||||
|
||||
it "defaults to no shipping method", ->
|
||||
expect(Order.order.shipping_method_id).toEqual null
|
||||
expect(Order.shippingMethod()).toEqual undefined
|
||||
|
||||
it "has a shipping price of zero with no shipping method", ->
|
||||
expect(Order.shippingPrice()).toEqual 0.0
|
||||
|
||||
it "binds to localStorage when given a scope", ->
|
||||
spyOn(storage, "bind")
|
||||
Order.fieldsToBind = ["testy"]
|
||||
Order.bindFieldsToLocalStorage({})
|
||||
prefix = "order_#{Order.order.id}#{Order.order.user_id}"
|
||||
expect(storage.bind).toHaveBeenCalledWith({}, "Order.order.testy", {storeName: "#{prefix}_testy"})
|
||||
expect(storage.bind).toHaveBeenCalledWith({}, "Order.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: true})
|
||||
|
||||
|
||||
describe "with shipping method", ->
|
||||
beforeEach ->
|
||||
@@ -100,9 +112,9 @@ describe 'Order service', ->
|
||||
expect(Order.preprocess().ship_address).toBe(undefined)
|
||||
|
||||
it "munges the order attributes to clone ship address from bill address", ->
|
||||
CheckoutFormState.ship_address_same_as_billing = false
|
||||
Order.ship_address_same_as_billing = false
|
||||
expect(Order.preprocess().ship_address_attributes).toEqual(orderData.ship_address)
|
||||
CheckoutFormState.ship_address_same_as_billing = true
|
||||
Order.ship_address_same_as_billing = true
|
||||
expect(Order.preprocess().ship_address_attributes).toEqual(orderData.bill_address)
|
||||
|
||||
it "creates attributes for card fields", ->
|
||||
|
||||
Reference in New Issue
Block a user