Improve validation feedback on new variant page and add test coverage

This commit is contained in:
Matt-Yorkley
2023-05-22 20:20:09 +01:00
parent 618900767f
commit 8247dce2dc
2 changed files with 14 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ module Spree
flash[:success] = flash_message_for(@object, :successfully_created)
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
else
flash[:error] = @object.errors.full_messages.to_sentence if @object.errors.any?
redirect_to spree.new_admin_product_variant_url(params[:product_id], @url_filters)
end

View File

@@ -60,11 +60,24 @@ describe '
# Expect variant_weight to accept 3 decimal places
fill_in 'variant_weight', with: '1.234'
fill_in 'unit_value_human', with: 1
click_button 'Create'
# Then the variant should have been created
expect(page).to have_content "Variant \"#{product.name}\" has been successfully created!"
end
it "show validation errors if present" do
product = create(:simple_product, variant_unit: "volume", variant_unit_scale: "1")
login_as_admin
visit spree.admin_product_variants_path product
click_link 'New Variant'
fill_in 'unit_value_human', with: 0
click_button 'Create'
expect(page).to have_content "Unit value must be greater than 0"
end
end
describe "viewing product variant" do