mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-14 23:47:48 +00:00
Show inline errors for product fields
The form helper () doesn't work for this case, but it seems we can call it directly like this instead. I'd like to fix the helper, but got stuck this time.
This commit is contained in:
committed by
Rachel Arnould
parent
5e478b8a76
commit
3b19a19776
@@ -41,8 +41,10 @@
|
||||
%td.align-left.header
|
||||
= product_form.hidden_field :id
|
||||
= product_form.text_field :name, 'aria-label': t('admin.products_page.columns.name')
|
||||
= error_message_on product, :name
|
||||
%td.align-right
|
||||
= product_form.text_field :sku, 'aria-label': t('admin.products_page.columns.sku')
|
||||
= error_message_on product, :sku
|
||||
%td.align-right
|
||||
.content
|
||||
= product.variant_unit.upcase_first
|
||||
|
||||
@@ -201,7 +201,7 @@ describe 'As an admin, I can see the new product page' do
|
||||
visit admin_products_v3_index_url
|
||||
end
|
||||
|
||||
it "can update product and variant fields" do
|
||||
it "updates product and variant fields" do
|
||||
within row_containing_name("Apples") do
|
||||
fill_in "Name", with: "Pommes"
|
||||
fill_in "SKU", with: "POM-00"
|
||||
@@ -236,7 +236,7 @@ describe 'As an admin, I can see the new product page' do
|
||||
expect(page).to have_content "Changes saved"
|
||||
end
|
||||
|
||||
it "can discard changes and reload latest data" do
|
||||
it "discards changes and reloads latest data" do
|
||||
within row_containing_name("Apples") do
|
||||
fill_in "Name", with: "Pommes"
|
||||
end
|
||||
@@ -262,6 +262,28 @@ describe 'As an admin, I can see the new product page' do
|
||||
expect(page).to have_field "SKU", with: "APL-10" # Updated value shown
|
||||
end
|
||||
end
|
||||
|
||||
it "shows errors for product fields" do
|
||||
within row_containing_name("Apples") do
|
||||
fill_in "Name", with: ""
|
||||
fill_in "SKU", with: "A" * 256
|
||||
end
|
||||
|
||||
expect {
|
||||
click_button "Save changes"
|
||||
product_a.reload
|
||||
}.to_not change { product_a.name }
|
||||
|
||||
# (there's no identifier displayed, so the user must remember which product it is..)
|
||||
within row_containing_name("") do
|
||||
expect(page).to have_field "Name", with: ""
|
||||
expect(page).to have_content "can't be blank"
|
||||
expect(page).to have_field "SKU", with: "A" * 256
|
||||
expect(page).to have_content "is too long"
|
||||
end
|
||||
pending
|
||||
expect(page).to have_content "Please review the errors and try again"
|
||||
end
|
||||
end
|
||||
|
||||
def expect_page_to_be(page_number)
|
||||
|
||||
Reference in New Issue
Block a user