From 6c92fdf16731f793377bcbc10c643fc162b35bc6 Mon Sep 17 00:00:00 2001 From: jtruong2 Date: Mon, 12 Feb 2018 15:48:06 +0100 Subject: [PATCH 1/3] fixes issue if admin and handling == 0 then do not render row --- app/views/spree/orders/_form.html.haml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/spree/orders/_form.html.haml b/app/views/spree/orders/_form.html.haml index 9813ff8642..2d25df71e2 100644 --- a/app/views/spree/orders/_form.html.haml +++ b/app/views/spree/orders/_form.html.haml @@ -35,13 +35,13 @@ %td.text-right %span.order-total.item-total= display_checkout_subtotal(@order) %td - - %tr - %td.text-right{colspan:"3"} - = t :orders_form_admin - %td.text-right - %span.order-total.distribution-total= display_checkout_admin_and_handling_adjustments_total_for(@order) - %td + -if display_checkout_admin_and_handling_adjustments_total_for(@order) != Spree::Money.new(0 , currency: @order.currency) + %tr + %td.text-right{colspan:"3"} + = t :orders_form_admin + %td.text-right + %span.order-total.distribution-total= display_checkout_admin_and_handling_adjustments_total_for(@order) + %td - checkout_adjustments_for(@order, exclude: [:line_item, :admin_and_handling]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| %tr.order-adjustment From 689aed70808b4192e3cd46d4a7669d6a8f11449f Mon Sep 17 00:00:00 2001 From: jtruong2 Date: Mon, 12 Feb 2018 15:13:32 +0100 Subject: [PATCH 2/3] Add spec for admin & handling --- spec/features/consumer/shopping/cart_spec.rb | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index 04acf0847a..49168bed9e 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -143,5 +143,26 @@ feature "full-page cart", js: true do expect(page).to have_content item2.variant.name end end + + context "Admin & Handling" do + it "hides row if order includes no adjustments" do + add_product_to_cart order, product_fee, quantity: 1 + visit spree.cart_path + + expect(page).to have_selector('#cart-detail') + expect(page).to_not have_content('Admin & Handling') + end + + it "shows row if order includes adjustments" do + coordinator_fee = create(:enterprise_fee, enterprise: order_cycle.coordinator, fee_type: 'admin', calculator: Spree::Calculator::FlatRate.new(preferred_amount: 1)) + order_cycle.coordinator_fees << coordinator_fee + + add_product_to_cart order, product_fee, quantity: 1 + visit spree.cart_path + + expect(page).to have_selector('#cart-detail') + expect(page).to have_content('Admin & Handling') + end + end end end From fa68dd0bccd4596086a2716581c11f7af8862ad3 Mon Sep 17 00:00:00 2001 From: Maxime Lalisse Date: Fri, 16 Mar 2018 01:15:49 +0100 Subject: [PATCH 3/3] refactor spec and check price --- spec/features/consumer/shopping/cart_spec.rb | 59 ++++++++++++-------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index 49168bed9e..485de5b70a 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -28,7 +28,7 @@ feature "full-page cart", js: true do end end - describe "fees" do + describe "percentage fees" do let(:percentage_fee) { create(:enterprise_fee, calculator: Calculator::FlatPercentPerItem.new(preferred_flat_percent: 20)) } before do @@ -47,6 +47,42 @@ feature "full-page cart", js: true do end end + describe "admin and handling flat fees" do + context 'when there are fees' do + let(:handling_fee) { create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 1), + enterprise: order_cycle.coordinator, fee_type: 'admin') } + + before do + add_enterprise_fee handling_fee + add_product_to_cart order, product_fee, quantity: 3 + visit spree.cart_path + end + + it 'shows admin and handlings row' do + expect(page).to have_selector('#cart-detail') + expect(page).to have_content('Admin & Handling') + expect(page).to have_selector '.cart-item-price', text: with_currency(0.86) + expect(page).to have_selector '.order-total.item-total', text: with_currency(2.58) + expect(page).to have_selector '.order-total.distribution-total', text: with_currency(1.00) + expect(page).to have_selector '.order-total.grand-total', text: with_currency(3.58) # price * 3 + 1 + end + end + + context 'when there are no admin and handling fees' do + before do + add_product_to_cart order, product_fee, quantity: 2 + visit spree.cart_path + end + + it 'hides admin and handlings row' do + expect(page).to have_selector('#cart-detail') + expect(page).to_not have_content('Admin & Handling') + expect(page).to have_selector '.cart-item-price', text: with_currency(0.86) + expect(page).to have_selector '.order-total.grand-total', text: with_currency(1.72) # price * 3 + end + end + end + describe "tax" do before do add_enterprise_fee enterprise_fee @@ -143,26 +179,5 @@ feature "full-page cart", js: true do expect(page).to have_content item2.variant.name end end - - context "Admin & Handling" do - it "hides row if order includes no adjustments" do - add_product_to_cart order, product_fee, quantity: 1 - visit spree.cart_path - - expect(page).to have_selector('#cart-detail') - expect(page).to_not have_content('Admin & Handling') - end - - it "shows row if order includes adjustments" do - coordinator_fee = create(:enterprise_fee, enterprise: order_cycle.coordinator, fee_type: 'admin', calculator: Spree::Calculator::FlatRate.new(preferred_amount: 1)) - order_cycle.coordinator_fees << coordinator_fee - - add_product_to_cart order, product_fee, quantity: 1 - visit spree.cart_path - - expect(page).to have_selector('#cart-detail') - expect(page).to have_content('Admin & Handling') - end - end end end