Skip to content

Commit

Permalink
Merge pull request #5443 from solidusio/elia/admin/stock-component-fixes
Browse files Browse the repository at this point in the history
SolidusAdmin `products/stock` component fixes
  • Loading branch information
elia authored Oct 19, 2023
2 parents e097f4a + cbcbb90 commit de6030b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
11 changes: 9 additions & 2 deletions admin/app/components/solidus_admin/products/stock/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit de6030b

Please sign in to comment.