Enable editing of product SKU

This commit is contained in:
David Cook
2023-08-29 17:36:47 +10:00
parent 9fe9d8557c
commit 5356e42efc
3 changed files with 17 additions and 10 deletions

View File

@@ -40,7 +40,7 @@
= product_form.hidden_field :id, name: "[products][#{i}][id]" #todo: can we remove #{i} and implicitly pop?
= 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
= product_form.text_field :sku, name: "[products][#{i}][sku]", 'aria-label': t('admin.products_page.columns.sku')
%td.align-right
.line-clamp-1
= product.variant_unit.upcase_first

View File

@@ -34,8 +34,8 @@ describe ProductsReflex, type: :reflex do
end
describe '#bulk_update' do
let!(:product_b) { create(:simple_product, name: "Bananas") }
let!(:product_a) { create(:simple_product, name: "Apples") }
let!(:product_b) { create(:simple_product, name: "Bananas", sku: "BAN-01") }
let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-01") }
it "saves valid changes" do
params = {
@@ -44,6 +44,7 @@ describe ProductsReflex, type: :reflex do
{
"id" => product_a.id.to_s,
"name" => "Pommes",
"sku" => "POM-01",
}
]
}
@@ -51,7 +52,8 @@ describe ProductsReflex, type: :reflex do
expect{
run_reflex(:bulk_update, params:)
product_a.reload
}.to change(product_a, :name).to("Pommes")
}.to change{ product_a.name }.to("Pommes")
.and change{ product_a.sku }.to("POM-01")
end
describe "sorting" do

View File

@@ -158,24 +158,29 @@ describe 'As an admin, I can see the new product page' do
end
describe "updating" do
let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-01") }
before do
visit admin_products_v3_index_url
end
it "can update product fields" do
within row_containing_name("product 1") do
fill_in "Name", with: "An updated name"
within row_containing_name("Apples") do
fill_in "Name", with: "Pommes"
fill_in "SKU", with: "POM-01"
end
expect {
click_button "Save changes"
product_1.reload
product_a.reload
}.to(
change { product_1.name }.to("An updated name")
change { product_a.name }.to("Pommes")
.and change{ product_a.sku }.to("POM-01")
)
within row_containing_name("An updated name") do
expect(page).to have_field "Name", with: "An updated name"
within row_containing_name("Pommes") do
expect(page).to have_field "Name", with: "Pommes"
expect(page).to have_field "SKU", with: "POM-01"
end
pending
expect(page).to have_content "Changes saved"