mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Enable editing of variant display_name
Best viewed with whitespace ignored. Using Rails' nested attributes feature, which ModelSet already supports.
This commit is contained in:
@@ -59,22 +59,24 @@
|
||||
%td.align-left
|
||||
.line-clamp-1= product.inherits_properties ? 'YES' : 'NO' #TODO: consider using https://github.com/RST-J/human_attribute_values, else use I18n.t (also below)
|
||||
- product.variants.each do |variant|
|
||||
%tr.condensed
|
||||
%td.align-left
|
||||
.line-clamp-1= variant.display_name
|
||||
%td.align-right
|
||||
.line-clamp-1= variant.sku
|
||||
%td.align-right
|
||||
.line-clamp-1= variant.unit_to_display
|
||||
%td.align-right
|
||||
.line-clamp-1= number_to_currency(variant.price)
|
||||
%td.align-right
|
||||
.line-clamp-1= variant.on_hand || 0 #TODO: spec for this according to requirements.
|
||||
%td.align-left
|
||||
.line-clamp-1= variant.product.supplier.name # same as product
|
||||
%td.align-left
|
||||
-# empty
|
||||
%td.align-left
|
||||
.line-clamp-1= variant.tax_category&.name || "None" # TODO: convert to dropdown, else translate hardcoded string.
|
||||
%td.align-left
|
||||
-# empty
|
||||
= form.fields_for(variant) do |variant_form|
|
||||
%tr.condensed
|
||||
%td.align-left
|
||||
= variant_form.hidden_field :id, name: "[products][#{i}][variants_attributes][][id]"
|
||||
= variant_form.text_field :display_name, name: "[products][#{i}][variants_attributes][][display_name]", 'aria-label': t('admin.products_page.columns.name'), placeholder: product.name
|
||||
%td.align-right
|
||||
.line-clamp-1= variant.sku
|
||||
%td.align-right
|
||||
.line-clamp-1= variant.unit_to_display
|
||||
%td.align-right
|
||||
.line-clamp-1= number_to_currency(variant.price)
|
||||
%td.align-right
|
||||
.line-clamp-1= variant.on_hand || 0 #TODO: spec for this according to requirements.
|
||||
%td.align-left
|
||||
.line-clamp-1= variant.product.supplier.name # same as product
|
||||
%td.align-left
|
||||
-# empty
|
||||
%td.align-left
|
||||
.line-clamp-1= variant.tax_category&.name || "None" # TODO: convert to dropdown, else translate hardcoded string.
|
||||
%td.align-left
|
||||
-# empty
|
||||
|
||||
@@ -36,10 +36,11 @@ describe ProductsReflex, type: :reflex do
|
||||
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") }
|
||||
|
||||
it "saves valid changes" do
|
||||
params = {
|
||||
# '[products][<i>][name]'
|
||||
# '[products][][name]'
|
||||
"products" => [
|
||||
{
|
||||
"id" => product_a.id.to_s,
|
||||
@@ -53,7 +54,33 @@ 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-01")
|
||||
end
|
||||
|
||||
it "saves valid changes to nested variants" do
|
||||
params = {
|
||||
# '[products][][name]'
|
||||
# '[products][][variants_attributes][][display_name]'
|
||||
"products" => [
|
||||
{
|
||||
"id" => product_a.id.to_s,
|
||||
"name" => "Pommes",
|
||||
"variants_attributes" => [
|
||||
{
|
||||
"id" => variant_a1.id.to_s,
|
||||
"display_name" => "Large box",
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
expect{
|
||||
run_reflex(:bulk_update, params:)
|
||||
product_a.reload
|
||||
variant_a1.reload
|
||||
}.to change{ product_a.name }.to("Pommes")
|
||||
.and change{ variant_a1.display_name }.to("Large box")
|
||||
end
|
||||
|
||||
describe "sorting" do
|
||||
|
||||
@@ -158,30 +158,40 @@ 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") }
|
||||
|
||||
before do
|
||||
visit admin_products_v3_index_url
|
||||
end
|
||||
|
||||
it "can update product fields" 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"
|
||||
end
|
||||
within row_containing_name("Medium box") do
|
||||
fill_in "Name", with: "Large box"
|
||||
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")
|
||||
.and change{ variant_a1.display_name }.to("Large box")
|
||||
)
|
||||
|
||||
within row_containing_name("Pommes") do
|
||||
expect(page).to have_field "Name", with: "Pommes"
|
||||
expect(page).to have_field "SKU", with: "POM-01"
|
||||
end
|
||||
within row_containing_name("Large box") do
|
||||
expect(page).to have_field "Name", with: "Large box"
|
||||
end
|
||||
|
||||
pending
|
||||
expect(page).to have_content "Changes saved"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user