Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SolidusAdmin products/stock component fixes #5443

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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