mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Fix rebase issue
This commit is contained in:
@@ -18,9 +18,9 @@ module Admin
|
||||
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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,8 +4,9 @@ require "spec_helper"
|
||||
|
||||
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 @@ RSpec.describe Admin::ProductsHelper do
|
||||
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')
|
||||
|
||||
@@ -49,35 +49,34 @@ RSpec.describe 'As an enterprise user, I can update my products' do
|
||||
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"
|
||||
|
||||
# Unit popout
|
||||
click_on "Unit" # activate popout
|
||||
end
|
||||
# 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./)
|
||||
|
||||
# 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"
|
||||
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 {
|
||||
@@ -553,8 +552,6 @@ RSpec.describe 'As an enterprise user, I can update my products' do
|
||||
expect(page).to have_content "is too long"
|
||||
expect(page.find('.col-producer')).to have_content('must exist')
|
||||
expect(page.find('.col-category')).to have_content('must exist')
|
||||
expect(page.find_button("Unit")).to have_text "" # have_button selector don't work here
|
||||
expect(page).to have_content "can't be blank"
|
||||
expect(page).to have_field "Price", with: "10.25" # other updated value is retained
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user