From 7aefa834bf44dbcc9168070d149a8b2e856ec4f5 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 10 Nov 2023 16:21:13 +1100 Subject: [PATCH] Add on_hand input --- app/views/admin/products_v3/_table.html.haml | 6 ++++-- spec/reflexes/products_reflex_spec.rb | 9 ++++----- spec/system/admin/products_v3/products_spec.rb | 10 +++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index eadb11d1f2..da8de1bf3b 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -85,8 +85,10 @@ %td.field = variant_form.text_field :price, 'aria-label': t('admin.products_page.columns.price'), value: number_to_currency(variant.price, unit: '')&.strip # TODO: add a spec to prove that this formatting is necessary. If so, it should be in a shared form helper for currency inputs = error_message_on variant, :price - %td.align-right - .content= variant.on_hand || 0 #TODO: spec for this according to requirements. + %td.field + %div.on-hand__wrapper + = variant_form.number_field :on_hand, 'aria-label': t('admin.products_page.columns.on_hand') + = error_message_on variant, :on_hand %td.align-left .content= variant.product.supplier&.name # same as product %td.align-left diff --git a/spec/reflexes/products_reflex_spec.rb b/spec/reflexes/products_reflex_spec.rb index ba22d41b84..792d9667bd 100644 --- a/spec/reflexes/products_reflex_spec.rb +++ b/spec/reflexes/products_reflex_spec.rb @@ -30,11 +30,8 @@ describe ProductsReflex, type: :reflex, feature: :admin_style_v3 do describe '#bulk_update' do let!(:variant_a1) { - create(:variant, - product: product_a, - display_name: "Medium box", - sku: "APL-01", - price: 5.25) + create(:variant, product: product_a, display_name: "Medium box", sku: "APL-01", price: 5.25, + on_hand: 5) } let!(:product_c) { create(:simple_product, name: "Carrots", sku: "CAR-00") } let!(:product_b) { create(:simple_product, name: "Bananas", sku: "BAN-00") } @@ -73,6 +70,7 @@ describe ProductsReflex, type: :reflex, feature: :admin_style_v3 do "display_name" => "Large box", "sku" => "POM-01", "price" => "10.25", + "on_hand" => "6", } ], } @@ -87,6 +85,7 @@ describe ProductsReflex, type: :reflex, feature: :admin_style_v3 do .and change{ variant_a1.display_name }.to("Large box") .and change{ variant_a1.sku }.to("POM-01") .and change{ variant_a1.price }.to(10.25) + .and change{ variant_a1.on_hand }.to(6) end describe "sorting" do diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index c9f35240d2..e1560d3ee3 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -194,11 +194,8 @@ describe 'As an admin, I can see the new product page', feature: :admin_style_v3 describe "updating" do let!(:variant_a1) { - create(:variant, - product: product_a, - display_name: "Medium box", - sku: "APL-01", - price: 5.25) + create(:variant, product: product_a, display_name: "Medium box", sku: "APL-01", price: 5.25, + on_hand: 5) } let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-00") } before do @@ -214,6 +211,7 @@ describe 'As an admin, I can see the new product page', feature: :admin_style_v3 fill_in "Name", with: "Large box" fill_in "SKU", with: "POM-01" fill_in "Price", with: "10.25" + fill_in "On Hand", with: "6" end expect { @@ -225,6 +223,7 @@ describe 'As an admin, I can see the new product page', feature: :admin_style_v3 .and change{ variant_a1.display_name }.to("Large box") .and change{ variant_a1.sku }.to("POM-01") .and change{ variant_a1.price }.to(10.25) + .and change{ variant_a1.on_hand }.to(6) within row_containing_name("Pommes") do expect(page).to have_field "Name", with: "Pommes" @@ -234,6 +233,7 @@ describe 'As an admin, I can see the new product page', feature: :admin_style_v3 expect(page).to have_field "Name", with: "Large box" expect(page).to have_field "SKU", with: "POM-01" expect(page).to have_field "Price", with: "10.25" + expect(page).to have_field "On Hand", with: "6" end pending