diff --git a/app/helpers/admin/products_helper.rb b/app/helpers/admin/products_helper.rb index 1dd31174e8df..8f7d1ea014b3 100644 --- a/app/helpers/admin/products_helper.rb +++ b/app/helpers/admin/products_helper.rb @@ -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, diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index 2d3fd6789676..fa423bbce75a 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -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 diff --git a/spec/helpers/admin/products_helper_spec.rb b/spec/helpers/admin/products_helper_spec.rb index cdd4df9e2a16..cfd04180d99a 100644 --- a/spec/helpers/admin/products_helper_spec.rb +++ b/spec/helpers/admin/products_helper_spec.rb @@ -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 @@ -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') diff --git a/spec/system/admin/products_v3/update_spec.rb b/spec/system/admin/products_v3/update_spec.rb index 608ce46fa636..6b4307368dff 100644 --- a/spec/system/admin/products_v3/update_spec.rb +++ b/spec/system/admin/products_v3/update_spec.rb @@ -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 {