Skip to content

Commit 08481c7

Browse files
committed
Fix Calculator Default Fields
For all calculators except the `PercentWithCap` one we have a custom `calculator_fields` partial. PercentWithCap does not need that - it can fall back to the default calculator fields partial. However, that partial does not render currently, because `name` is a symbol that does not respond to `humanize`. Adds a system spec as well. (cherry picked from commit 7e1de2d) # Conflicts: # promotions/spec/system/solidus_promotions/backend/promotions_spec.rb
1 parent a17aebc commit 08481c7

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

promotions/lib/views/backend/solidus_promotions/admin/calculator_fields/_default_fields.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<%= render "solidus_promotions/admin/shared/preference_fields/#{calculator.preference_type(name)}",
33
name: "#{prefix}[calculator_attributes][preferred_#{name}]",
44
value: calculator.get_preference(name),
5-
label: calculator.class.human_attribute_name("preferred_#{name}", default: I18n.t(name, scope: :spree, default: name.humanize)) %>
5+
label: calculator.class.human_attribute_name("preferred_#{name}", default: I18n.t(name, scope: :spree, default: name.to_s.humanize)) %>
66
<% end %>

promotions/spec/system/solidus_promotions/backend/promotions_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,39 @@
161161
expect(page).to have_content("Benefit has been successfully removed!")
162162
end
163163
end
164+
165+
describe "Adding a benefit condition" do
166+
let!(:promotion_with_benefit) { create(:solidus_promotion, :with_adjustable_benefit) }
167+
let!(:product) { create(:product) }
168+
let!(:option_value) { create(:option_value) }
169+
let!(:variant) { create(:variant, product: product, option_values: [option_value]) }
170+
171+
it "allows adding an option value condition", :js do
172+
visit solidus_promotions.edit_admin_promotion_path(promotion_with_benefit)
173+
click_link "Add Condition"
174+
select("Line Item variant matches option values", from: "Condition Type")
175+
click_button "Add"
176+
expect(page).to have_content("Line Item variant matches option values")
177+
click_link "Add product"
178+
within(".promo-condition-option-value") do
179+
targetted_select2_search(product.name, from: "#s2id_ov-product-picker-0")
180+
targetted_select2_search(option_value.name, from: "#s2id_option-value-picker-0")
181+
end
182+
within("#benefits_adjust_line_item_#{promotion_with_benefit.benefits.first.id}_conditions") do
183+
click_button("Update")
184+
end
185+
expect(page).to have_content("Condition has been successfully updated!")
186+
end
187+
end
188+
189+
describe "Rendering the promotion edit page with the PercentWithCap calculator" do
190+
let(:promotion) { create(:solidus_promotion, name: "My capped promotion", benefits: [benefit]) }
191+
let(:benefit) { SolidusPromotions::Benefits::AdjustLineItem.new(calculator:) }
192+
let(:calculator) { SolidusPromotions::Calculators::PercentWithCap.new(preferred_percent: 10, preferred_max_amount: 100) }
193+
194+
it "renders without errors" do
195+
visit solidus_promotions.edit_admin_promotion_path(promotion)
196+
expect(page).to have_content("My capped promotion")
197+
end
198+
end
164199
end

0 commit comments

Comments
 (0)