Skip to content

Commit

Permalink
Fix rebase issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rioug committed Aug 19, 2024
1 parent e1c9831 commit 55e4d7c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/helpers/admin/products_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def product_image_form_path(product)
end

def unit_value_with_description(variant)
return "" if variant.unit_value.nil?
return variant.unit_description.to_s if variant.unit_value.nil?

scaled_unit_value = variant.unit_value / (variant.product.variant_unit_scale || 1)
scaled_unit_value = variant.unit_value / (variant.variant_unit_scale || 1)
precised_unit_value = number_with_precision(
scaled_unit_value,
precision: nil,
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/products_v3/_variant_row.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
= f.hidden_field :unit_value
= f.hidden_field :unit_description
= f.text_field :unit_value_with_description,
value: unit_value_with_description(variant), 'aria-label': t('admin.products_page.columns.unit_value')
value: unit_value_with_description(variant), 'aria-label': t('admin.products_page.columns.unit_value'), required: true
.field
= f.label :display_as, t('admin.products_page.columns.display_as')
= f.text_field :display_as, placeholder: VariantUnits::OptionValueNamer.new(variant).name
Expand Down
7 changes: 4 additions & 3 deletions spec/helpers/admin/products_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

RSpec.describe Admin::ProductsHelper do
describe '#unit_value_with_description' do
let(:product) { create(:product, variant_unit_scale: 1000.0) }
let(:variant) { create(:variant, product:, unit_value: 2000.0, unit_description: 'kg') }
let(:variant) {
create(:variant, variant_unit_scale: 1000.0, unit_value: 2000.0, unit_description: 'kg')
}

context 'when unit_value and unit_description are present' do
it 'returns the scaled unit value with the description' do
Expand All @@ -30,7 +31,7 @@
end

context 'when variant_unit_scale is nil' do
before { product.update_column(:variant_unit_scale, nil) }
before { variant.update_column(:variant_unit_scale, nil) }

it 'uses default scale of 1 and returns the unscaled unit value with the description' do
expect(helper.unit_value_with_description(variant)).to eq('2000 kg')
Expand Down
31 changes: 15 additions & 16 deletions spec/system/admin/products_v3/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,34 @@
fill_in "Name", with: "Pommes"
fill_in "SKU", with: "POM-00"
end

within row_containing_name("Medium box") do
fill_in "Name", with: "Large box"
fill_in "SKU", with: "POM-01"

tomselect_select "Volume (mL)", from: "Unit scale"
click_on "Unit" # activate popout
end

# Unit popout
# have to use below method to trigger the +change+ event,
# +fill_in "Unit value", with: ""+ does not trigger +change+ event
find_field('Unit value').send_keys(:control, 'a', :backspace) # empty the field
click_button "Save changes" # attempt to save and should fail with below error
expect(page).to have_content "must be greater than 0"
click_on "Unit" # activate popout
fill_in "Unit value", with: "500.1"

within row_containing_name("Medium box") do
fill_in "Name", with: "Large box"
fill_in "SKU", with: "POM-01"
# Unit popout
click_on "Unit" # activate popout
# have to use below method to trigger the +change+ event,
# +fill_in "Unit value", with: ""+ does not trigger +change+ event
find_field('Unit value').send_keys(:control, 'a', :backspace) # empty the field
# In CI we get "Please fill out this field." and locally we get
# "Please fill in this field."
expect_browser_validation('input[aria-label="Unit value"]',
/Please fill (in|out) this field./)

fill_in "Unit value", with: "500.1"
fill_in "Price", with: "10.25"

# Stock popout
click_on "On Hand" # activate popout
fill_in "On Hand", with: "-1"
end

# Stock popout
fill_in "On Hand", with: "-1"
click_button "Save changes" # attempt to save or close the popout
expect(page).to have_field "On Hand", with: "-1" # popout is still open

fill_in "On Hand", with: "6"

expect {
Expand Down

0 comments on commit 55e4d7c

Please sign in to comment.