When cart clear is declined, revert order cycle selection change

This commit is contained in:
Rohan Mitchell
2015-07-31 11:35:29 +10:00
parent b97bbae00e
commit faa1d0d1c5
4 changed files with 62 additions and 28 deletions

View File

@@ -11,11 +11,19 @@ Darkswarm.controller "OrderCycleCtrl", ($scope, $timeout, OrderCycle) ->
Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Products, Variants, Cart) ->
# Track previous order cycle id for use with revertOrderCycle()
$scope.previous_order_cycle_id = OrderCycle.order_cycle.order_cycle_id
$scope.$watch 'order_cycle.order_cycle_id', (newValue, oldValue)->
$scope.previous_order_cycle_id = oldValue
$scope.changeOrderCycle = ->
OrderCycle.push_order_cycle $scope.orderCycleChanged
$timeout ->
$("#order_cycle_id").trigger("closeTrigger")
$scope.revertOrderCycle = ->
$scope.order_cycle.order_cycle_id = $scope.previous_order_cycle_id
$scope.orderCycleChanged = ->
# push_order_cycle clears the cart server-side. Here we call Cart.clear() to clear the
# client-side cart.

View File

@@ -15,5 +15,8 @@ Darkswarm.directive "ofnChangeOrderCycle", (OrderCycle, Cart, storage) ->
if confirm "Are you sure? This will change your selected order cycle and remove any items in your shopping cart."
Cart.clear()
scope.changeOrderCycle()
else
scope.$apply ->
scope.revertOrderCycle()
else
scope.changeOrderCycle()

View File

@@ -85,32 +85,57 @@ feature "As a consumer I want to shop with a distributor", js: true do
modal_should_be_open_for product
end
it "shows the correct fees after selecting and changing an order cycle" do
enterprise_fee = create(:enterprise_fee, amount: 1001)
exchange2.enterprise_fees << enterprise_fee
exchange2.variants << variant
exchange1.variants << variant
describe "changing order cycle" do
it "shows the correct fees after selecting and changing an order cycle" do
enterprise_fee = create(:enterprise_fee, amount: 1001)
exchange2.enterprise_fees << enterprise_fee
exchange2.variants << variant
exchange1.variants << variant
# -- Selecting an order cycle
visit shop_path
select "turtles", from: "order_cycle_id"
page.should have_content "$1020.99"
# -- Selecting an order cycle
visit shop_path
select "turtles", from: "order_cycle_id"
page.should have_content "$1020.99"
# -- Cart shows correct price
fill_in "variants[#{variant.id}]", with: 1
show_cart
within("li.cart") { page.should have_content "$1020.99" }
# -- Cart shows correct price
fill_in "variants[#{variant.id}]", with: 1
show_cart
within("li.cart") { page.should have_content "$1020.99" }
# -- Changing order cycle
select "frogs", from: "order_cycle_id"
page.should have_content "$19.99"
# -- Changing order cycle
select "frogs", from: "order_cycle_id"
page.should have_content "$19.99"
# -- Cart should be cleared
# ng-animate means that the old product row is likely to be present, so we explicitly
# fill in the quantity in the incoming row
page.should_not have_selector "tr.product-cart"
within('product.ng-enter') { fill_in "variants[#{variant.id}]", with: 1 }
within("li.cart") { page.should have_content "$19.99" }
# -- Cart should be cleared
# ng-animate means that the old product row is likely to be present, so we explicitly
# fill in the quantity in the incoming row
page.should_not have_selector "tr.product-cart"
within('product.ng-enter') { fill_in "variants[#{variant.id}]", with: 1 }
within("li.cart") { page.should have_content "$19.99" }
end
describe "declining to clear the cart" do
before do
exchange2.variants << variant
exchange1.variants << variant
visit shop_path
select "turtles", from: "order_cycle_id"
fill_in "variants[#{variant.id}]", with: 1
end
it "leaves the cart untouched when the user declines" do
handle_js_confirm(false) do
select "frogs", from: "order_cycle_id"
show_cart
page.should have_selector "tr.product-cart"
page.should have_selector 'li.cart', text: '1 item'
# The order cycle choice should not have changed
page.should have_select 'order_cycle_id', selected: 'turtles'
end
end
end
end
end
end

View File

@@ -1,19 +1,17 @@
describe 'OrderCycleCtrl', ->
ctrl = null
scope = null
event = null
product_ctrl = null
OrderCycle = null
beforeEach ->
module 'Darkswarm'
scope = {}
OrderCycle =
order_cycle: "test"
OrderCycle =
order_cycle:
id: 123
inject ($controller) ->
scope = {}
ctrl = $controller 'OrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle}
it "puts the order cycle in scope", ->
expect(scope.order_cycle).toEqual "test"
expect(scope.order_cycle).toEqual {id: 123}