Merge pull request #11107 from jibees/11085-edit-variant-cant-update-values-on-the-variant-edit-page

Admin, Edit variant: remove unwanted extra space on price (added in certain specific conditions)
This commit is contained in:
Filipe
2023-06-29 16:46:42 +01:00
committed by GitHub
2 changed files with 56 additions and 5 deletions

View File

@@ -23,7 +23,7 @@
= f.text_field :sku, class: 'fullwidth'
.field
= f.label :price, t('.price')
= f.text_field :price, class: 'fullwidth', "ng-model" => "variant.price", "ng-init" => "variant.price = '#{number_to_currency(@variant.price, unit: '')}'"
= f.text_field :price, class: 'fullwidth', "ng-model" => "variant.price", "ng-init" => "variant.price = '#{number_to_currency(@variant.price, unit: '')&.strip}'"
.field
= hidden_field_tag 'product_variant_unit', @product.variant_unit
= hidden_field_tag 'product_variant_unit_name', @product.variant_unit_name
@@ -64,4 +64,4 @@
- value = number_with_precision(@variant.send(field), precision: 2)
= f.number_field field, value: value, class: 'fullwidth', step: 0.01
.clear
.clear

View File

@@ -90,8 +90,6 @@ describe '
login_as_admin
visit spree.admin_product_variants_path(product, filter)
visit spree.admin_product_variants_path(product, filter)
expected_new_url = Regexp.new(
Regexp.escape(spree.new_admin_product_variant_path(product, filter))
)
@@ -179,6 +177,59 @@ describe '
expect(page).to have_content %(Variant "#{product.name}" has been successfully updated!)
expect(variant.reload.unit_description).to eq('bar')
end
context "with ES as a locale" do
let(:product) { create(:simple_product, variant_unit: "weight", variant_unit_scale: "1") }
let(:variant) { product.variants.first }
around do |example|
I18n.default_locale = :es
example.run
I18n.default_locale = :en
end
before do
variant.update( unit_value: 1, unit_description: 'foo' )
# When I view the variant
login_as_admin
visit spree.admin_product_variants_path product
end
shared_examples "with localization" do |localized, decimal_mark, thousands_separator|
context "set to #{localized}" do
before do
allow(Spree::Config).to receive(:enable_localized_number?).and_return localized
Spree::Config[:currency_decimal_mark] = decimal_mark
Spree::Config[:currency_thousands_separator] = thousands_separator
end
it "when variant_unit is weight" do
expect(variant.price).to eq(19.99)
# Given a product with unit-related option types, with a variant
page.find('table.index .icon-edit').click
# assert on the price field
expect(page).to have_field "variant_price", with: "19,99"
# When I update the fields and save the variant
fill_in "variant_price", with: "12,50"
click_button 'Actualizar'
expect(page).to have_content \
%(Variant "#{product.name}" ha sido actualizado exitosamente)
# Then the variant price should have been updated
expect(variant.reload.price).to eq(12.50)
end
end
end
it_behaves_like "with localization", false, ".", ","
it_behaves_like "with localization", true, ".", ","
it_behaves_like "with localization", false, ",", "."
it_behaves_like "with localization", true, ",", "."
end
end
describe "editing on hand and on demand values" do
@@ -224,7 +275,7 @@ describe '
it "soft-deletes variants" do
product = create(:simple_product)
variant = create(:variant, product: product)
variant = create(:variant, product:)
login_as_admin
visit spree.admin_product_variants_path product