diff --git a/admin/app/components/solidus_admin/products/stock/component.rb b/admin/app/components/solidus_admin/products/stock/component.rb index c4365664c82..32aecdecd40 100644 --- a/admin/app/components/solidus_admin/products/stock/component.rb +++ b/admin/app/components/solidus_admin/products/stock/component.rb @@ -8,6 +8,13 @@ def self.from_product(product) ) end + def self.from_variant(variant) + new( + on_hand: variant.total_on_hand, + variants_count: nil, + ) + end + def initialize(on_hand:, variants_count:) @on_hand = on_hand @variants_count = variants_count @@ -24,8 +31,8 @@ def call tag.span t('.stock.in_stock', on_hand: @on_hand), class: 'text-red-500' end - variant_info = t('.for_variants', count: @variants_count) + variant_info = t('.for_variants', count: @variants_count) if @variants_count - tag.div safe_join([stock_info, variant_info], ' ') + tag.span safe_join([stock_info, variant_info], ' ') end end diff --git a/admin/spec/components/solidus_admin/products/stock/component_spec.rb b/admin/spec/components/solidus_admin/products/stock/component_spec.rb index 88b099c45dc..6c73a56be8e 100644 --- a/admin/spec/components/solidus_admin/products/stock/component_spec.rb +++ b/admin/spec/components/solidus_admin/products/stock/component_spec.rb @@ -6,4 +6,30 @@ it "renders the overview preview" do render_preview(:overview) end + + describe ".from_variant" do + it "has an empty variants count" do + allow(described_class).to receive(:new) + + described_class.from_variant(instance_double(Spree::Variant, total_on_hand: 123)) + + expect(described_class).to have_received(:new).with( + on_hand: 123, + variants_count: nil, + ) + end + end + + describe ".from_product" do + it "has an empty variants count" do + allow(described_class).to receive(:new) + + described_class.from_product(instance_double(Spree::Product, total_on_hand: 123, variants: [])) + + expect(described_class).to have_received(:new).with( + on_hand: 123, + variants_count: 0, + ) + end + end end