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 diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index 04acf0847a..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