mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Enable editing of variant SKU
I'm not sure what the point of the product SKU was to be honest.. it will probably be removed in the product refactor.
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
= variant_form.hidden_field :id, name: "#{prefix}[id]"
|
||||
= variant_form.text_field :display_name, name: "#{prefix}[display_name]", 'aria-label': t('admin.products_page.columns.name'), placeholder: product.name
|
||||
%td.align-right
|
||||
.line-clamp-1= variant.sku
|
||||
= variant_form.text_field :sku, name: "#{prefix}[sku]", 'aria-label': t('admin.products_page.columns.sku')
|
||||
%td.align-right
|
||||
.line-clamp-1= variant.unit_to_display
|
||||
%td.align-right
|
||||
|
||||
@@ -34,9 +34,14 @@ describe ProductsReflex, type: :reflex do
|
||||
end
|
||||
|
||||
describe '#bulk_update' do
|
||||
let!(:product_b) { create(:simple_product, name: "Bananas", sku: "BAN-01") }
|
||||
let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-01") }
|
||||
let(:variant_a1) { create(:variant, product: product_a, display_name: "Medium box") }
|
||||
let!(:variant_a1) {
|
||||
create(:variant,
|
||||
product: product_a,
|
||||
display_name: "Medium box",
|
||||
sku: "APL-01")
|
||||
}
|
||||
let!(:product_b) { create(:simple_product, name: "Bananas", sku: "BAN-00") }
|
||||
let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-00") }
|
||||
|
||||
it "saves valid changes" do
|
||||
params = {
|
||||
@@ -45,7 +50,7 @@ describe ProductsReflex, type: :reflex do
|
||||
{
|
||||
"id" => product_a.id.to_s,
|
||||
"name" => "Pommes",
|
||||
"sku" => "POM-01",
|
||||
"sku" => "POM-00",
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -54,10 +59,10 @@ describe ProductsReflex, type: :reflex do
|
||||
run_reflex(:bulk_update, params:)
|
||||
product_a.reload
|
||||
}.to change{ product_a.name }.to("Pommes")
|
||||
.and change{ product_a.sku }.to("POM-01")
|
||||
.and change{ product_a.sku }.to("POM-00")
|
||||
end
|
||||
|
||||
it "saves valid changes to nested variants" do
|
||||
it "saves valid changes to products and nested variants" do
|
||||
params = {
|
||||
# '[products][][name]'
|
||||
# '[products][][variants_attributes][][display_name]'
|
||||
@@ -69,6 +74,7 @@ describe ProductsReflex, type: :reflex do
|
||||
{
|
||||
"id" => variant_a1.id.to_s,
|
||||
"display_name" => "Large box",
|
||||
"sku" => "POM-01",
|
||||
}
|
||||
],
|
||||
}
|
||||
@@ -81,6 +87,7 @@ describe ProductsReflex, type: :reflex do
|
||||
variant_a1.reload
|
||||
}.to change{ product_a.name }.to("Pommes")
|
||||
.and change{ variant_a1.display_name }.to("Large box")
|
||||
.and change{ variant_a1.sku }.to("POM-01")
|
||||
end
|
||||
|
||||
describe "sorting" do
|
||||
|
||||
@@ -158,8 +158,13 @@ describe 'As an admin, I can see the new product page' do
|
||||
end
|
||||
|
||||
describe "updating" do
|
||||
let!(:variant_a1) { create(:variant, product: product_a, display_name: "Medium box") }
|
||||
let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-01") }
|
||||
let!(:variant_a1) {
|
||||
create(:variant,
|
||||
product: product_a,
|
||||
display_name: "Medium box",
|
||||
sku: "APL-01")
|
||||
}
|
||||
let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-00") }
|
||||
|
||||
before do
|
||||
visit admin_products_v3_index_url
|
||||
@@ -168,28 +173,29 @@ describe 'As an admin, I can see the new product page' do
|
||||
it "can update product and variant fields" do
|
||||
within row_containing_name("Apples") do
|
||||
fill_in "Name", with: "Pommes"
|
||||
fill_in "SKU", with: "POM-01"
|
||||
fill_in "SKU", with: "POM-00"
|
||||
end
|
||||
within row_containing_name("Medium box") do
|
||||
fill_in "Name", with: "Large box"
|
||||
fill_in "SKU", with: "POM-01"
|
||||
end
|
||||
|
||||
expect {
|
||||
click_button "Save changes"
|
||||
product_a.reload
|
||||
variant_a1.reload
|
||||
}.to(
|
||||
change { product_a.name }.to("Pommes")
|
||||
.and change{ product_a.sku }.to("POM-01")
|
||||
}.to change { product_a.name }.to("Pommes")
|
||||
.and change{ product_a.sku }.to("POM-00")
|
||||
.and change{ variant_a1.display_name }.to("Large box")
|
||||
)
|
||||
.and change{ variant_a1.sku }.to("POM-01")
|
||||
|
||||
within row_containing_name("Pommes") do
|
||||
expect(page).to have_field "Name", with: "Pommes"
|
||||
expect(page).to have_field "SKU", with: "POM-01"
|
||||
expect(page).to have_field "SKU", with: "POM-00"
|
||||
end
|
||||
within row_containing_name("Large box") do
|
||||
expect(page).to have_field "Name", with: "Large box"
|
||||
expect(page).to have_field "SKU", with: "POM-01"
|
||||
end
|
||||
|
||||
pending
|
||||
|
||||
Reference in New Issue
Block a user