From 98adefbd6792fa73fa3e682240d30dc302a535fa Mon Sep 17 00:00:00 2001 From: kernal053 Date: Sat, 4 Jan 2025 14:26:02 +0530 Subject: [PATCH 1/2] Add 'Voucher:' before voucher code on edit cart page. Add spec correspondigly --- app/views/spree/orders/_form.html.haml | 5 +++- config/locales/en.yml | 1 + .../views/spree/orders/edit.html.haml_spec.rb | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/views/spree/orders/_form.html.haml b/app/views/spree/orders/_form.html.haml index 778e7540cfa..3df13e7c3ca 100644 --- a/app/views/spree/orders/_form.html.haml +++ b/app/views/spree/orders/_form.html.haml @@ -34,7 +34,10 @@ - checkout_adjustments_for(@order, exclude: [:line_item]).reverse_each do |adjustment| %tr.order-adjustment %td.text-right{:colspan => "3"} - = adjustment.label + - if adjustment.originator_type == "Voucher" + = t(:order_voucher_label, code: adjustment.label) + - else + = adjustment.label %td.text-right.total %span= adjustment.display_amount.to_html %td diff --git a/config/locales/en.yml b/config/locales/en.yml index ad27ac5884e..a22d527edc0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2455,6 +2455,7 @@ en: order_back_to_store: Back To Store order_back_to_cart: Back To Cart order_back_to_website: Back To Website + order_voucher_label: "Voucher: %{code}" checkout_details_title: Checkout Details checkout_payment_title: Checkout Payment checkout_summary_title: Checkout Summary diff --git a/spec/views/spree/orders/edit.html.haml_spec.rb b/spec/views/spree/orders/edit.html.haml_spec.rb index cb1186592bf..c4c9fcf1d46 100644 --- a/spec/views/spree/orders/edit.html.haml_spec.rb +++ b/spec/views/spree/orders/edit.html.haml_spec.rb @@ -31,4 +31,28 @@ expect(rendered).to have_selector(".unit-price") end end + + describe "display adjustments" do + let(:voucher) { create(:voucher, enterprise: order.distributor) } + + before do + voucher.create_adjustment(voucher.code, order) + OrderManagement::Order::Updater.new(order).update_voucher + render + end + + it "includes Voucher text with label" do + expect(rendered).to include("Voucher: #{voucher.code}") + end + + # shipping fee is derived from 'completed_order_with_fees' factory, it applies when using shipping method such as Home Delivery. + it "includes Shipping label" do + expect(rendered).to include("Shipping") + end + + # transaction fee is derived from 'completed_order_with_fees' factory, it applies when using payment methods such as Check & Stripe. + it "includes Transaction fee label" do + expect(rendered).to include("Transaction fee") + end + end end From 45a4b339202230dc9a87152786f8b9d4840b2a66 Mon Sep 17 00:00:00 2001 From: kernal053 Date: Tue, 7 Jan 2025 09:17:24 +0530 Subject: [PATCH 2/2] Ensure existing format 'Voucher: Code' on edit cart page. Handle rubocop warning --- app/views/spree/orders/_form.html.haml | 3 ++- config/locales/en.yml | 1 - spec/views/spree/orders/edit.html.haml_spec.rb | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/views/spree/orders/_form.html.haml b/app/views/spree/orders/_form.html.haml index 3df13e7c3ca..414961c1ff1 100644 --- a/app/views/spree/orders/_form.html.haml +++ b/app/views/spree/orders/_form.html.haml @@ -35,7 +35,8 @@ %tr.order-adjustment %td.text-right{:colspan => "3"} - if adjustment.originator_type == "Voucher" - = t(:order_voucher_label, code: adjustment.label) + = "#{t(:voucher)}:" + = adjustment.label - else = adjustment.label %td.text-right.total diff --git a/config/locales/en.yml b/config/locales/en.yml index a22d527edc0..ad27ac5884e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2455,7 +2455,6 @@ en: order_back_to_store: Back To Store order_back_to_cart: Back To Cart order_back_to_website: Back To Website - order_voucher_label: "Voucher: %{code}" checkout_details_title: Checkout Details checkout_payment_title: Checkout Payment checkout_summary_title: Checkout Summary diff --git a/spec/views/spree/orders/edit.html.haml_spec.rb b/spec/views/spree/orders/edit.html.haml_spec.rb index c4c9fcf1d46..2d1b6b65fd8 100644 --- a/spec/views/spree/orders/edit.html.haml_spec.rb +++ b/spec/views/spree/orders/edit.html.haml_spec.rb @@ -42,17 +42,19 @@ end it "includes Voucher text with label" do - expect(rendered).to include("Voucher: #{voucher.code}") + expect(rendered).to have_content("Voucher:\n#{voucher.code}") end - # shipping fee is derived from 'completed_order_with_fees' factory, it applies when using shipping method such as Home Delivery. + # Shipping fee is derived from 'completed_order_with_fees' factory. + # It applies when using shipping method such as Home Delivery. it "includes Shipping label" do - expect(rendered).to include("Shipping") + expect(rendered).to have_content("Shipping") end - # transaction fee is derived from 'completed_order_with_fees' factory, it applies when using payment methods such as Check & Stripe. + # Transaction fee is derived from 'completed_order_with_fees' factory. + # It applies when using payment methods such as Check & Stripe. it "includes Transaction fee label" do - expect(rendered).to include("Transaction fee") + expect(rendered).to have_content("Transaction fee") end end end