Simplify form code

The form elements shouldn't need an `id` attribute.
This commit is contained in:
David Cook
2023-08-29 16:20:58 +10:00
parent dea96fd3ab
commit aff33b79ae
2 changed files with 14 additions and 3 deletions

View File

@@ -38,7 +38,7 @@
%tr
%td.align-left.header
= product_form.hidden_field :id, name: "[products][#{i}][id]" #todo: can we remove #{i} and implicitly pop?
.line-clamp-1= product_form.text_field :name, name: "[products][#{i}][name]", id: "_product_name_#{product.id}", 'aria-label': t('admin.products_page.columns.name')
.line-clamp-1= product_form.text_field :name, name: "[products][#{i}][name]", 'aria-label': t('admin.products_page.columns.name')
%td.align-right
.line-clamp-1= product.sku
%td.align-right

View File

@@ -163,7 +163,9 @@ describe 'As an admin, I can see the new product page' do
end
it "can update product fields" do
fill_in id: "_product_name_#{product_1.id}", with: "An updated name"
within row_containing_name("product 1") do
fill_in "Name", with: "An updated name"
end
expect {
click_button "Save changes"
@@ -172,7 +174,9 @@ describe 'As an admin, I can see the new product page' do
change { product_1.name }.to("An updated name")
)
expect(page).to have_field id: "_product_name_#{product_1.id}", with: "An updated name"
within row_containing_name("An updated name") do
expect(page).to have_field "Name", with: "An updated name"
end
pending
expect(page).to have_content "Changes saved"
end
@@ -205,4 +209,11 @@ describe 'As an admin, I can see the new product page' do
select category, from: "category_id"
click_button "Search"
end
# Selector for table row that has an input with this value.
# Because there are no visible labels, the user has to assume which product it is, based on the
# visible name.
def row_containing_name(value)
"tr:has(input[aria-label=Name][value='#{value}'])"
end
end