mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
12705 - incorporate old UI behavior
- if unit_value is not present and unit_description then display unit_description only. - if both are not present then display empty fields
This commit is contained in:
@@ -11,19 +11,20 @@ module Admin
|
||||
end
|
||||
|
||||
def prepare_new_variant(product)
|
||||
product.variants.build do |variant|
|
||||
variant.unit_value = 1.0 * (product.variant_unit_scale || 1)
|
||||
variant.unit_presentation = VariantUnits::OptionValueNamer.new(variant).name
|
||||
end
|
||||
product.variants.build
|
||||
end
|
||||
|
||||
def unit_value_with_description(variant)
|
||||
scaled_unit_value = (variant.unit_value || 1) / (variant.product.variant_unit_scale || 1)
|
||||
precised_unit_value = number_with_precision(
|
||||
scaled_unit_value,
|
||||
precision: nil,
|
||||
strip_insignificant_zeros: true
|
||||
)
|
||||
precised_unit_value = nil
|
||||
|
||||
if variant.unit_value
|
||||
scaled_unit_value = variant.unit_value / (variant.product.variant_unit_scale || 1)
|
||||
precised_unit_value = number_with_precision(
|
||||
scaled_unit_value,
|
||||
precision: nil,
|
||||
strip_insignificant_zeros: true
|
||||
)
|
||||
end
|
||||
|
||||
[precised_unit_value, variant.unit_description].compact_blank.join(" ")
|
||||
end
|
||||
|
||||
@@ -18,7 +18,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'), required: true
|
||||
value: unit_value_with_description(variant), 'aria-label': t('admin.products_page.columns.unit_value')
|
||||
.field
|
||||
= f.label :display_as, t('admin.products_page.columns.display_as')
|
||||
= f.text_field :display_as, placeholder: VariantUnits::OptionValueNamer.new(variant).name
|
||||
|
||||
@@ -16,8 +16,8 @@ RSpec.describe Admin::ProductsHelper do
|
||||
context 'when unit_value is nil' do
|
||||
before { variant.update_column(:unit_value, nil) }
|
||||
|
||||
it 'defaults to 1 and returns the scaled unit value with the description' do
|
||||
expect(helper.unit_value_with_description(variant)).to eq('0.001 kg')
|
||||
it 'returns the description' do
|
||||
expect(helper.unit_value_with_description(variant)).to eq('kg')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,8 +40,8 @@ RSpec.describe Admin::ProductsHelper do
|
||||
context 'when both unit_value and unit_description are nil' do
|
||||
before { variant.update_columns(unit_description: nil, unit_value: nil) }
|
||||
|
||||
it 'returns the default unit value without description' do
|
||||
expect(helper.unit_value_with_description(variant)).to eq('0.001')
|
||||
it 'returns empty string' do
|
||||
expect(helper.unit_value_with_description(variant)).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -517,6 +517,7 @@ RSpec.describe 'As an enterprise user, I can update my products' do
|
||||
expect(page).to have_field "SKU", with: "n" * 256
|
||||
expect(page).to have_content "is too long"
|
||||
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