Skip to content

Commit

Permalink
Use configurable adjustment promotion source types in Thumbnail.for
Browse files Browse the repository at this point in the history
There's a View Component for rendering icons, and it's got a convenience
method for rendering adjustables to adjustments.

This uses the `Spree::Config.adjustment_promotion_source_types`
configuration option to figure out whether an adjustable needs a
megaphone as an icon.

With the legacy promotion system extracted, `Spree::Promotion` will not
necessarily be available.
  • Loading branch information
mamhoff committed Jun 7, 2024
1 parent dc780f6 commit 5bc370a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def call

def self.for(record, **attrs)
case record
when Spree::PromotionAction then new(icon: "megaphone-line", **attrs)
when *Spree::Config.adjustment_promotion_source_types then new(icon: "megaphone-line", **attrs)
when Spree::UnitCancel then new(icon: "close-circle-line", **attrs)
when Spree::TaxRate then new(icon: "percent-line", **attrs)
when Spree::LineItem then self.for(record.variant, **attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<% attachment = Object.new.tap { def _1.url(*) "https://placekitten.com/280/200"; end } %>
<% image = Spree::Image.new.tap { _1.define_singleton_method(:attachment) { attachment } } %>
<% [
Spree::PromotionAction.new,
Spree::UnitCancel.new,
Spree::TaxRate.new,
image,
Expand Down
1 change: 1 addition & 0 deletions core/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
lib_name: 'solidus_core'
)

require 'solidus_admin'
require 'rspec/rails'
require 'rspec-activemodel-mocks'
require 'database_cleaner'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe SolidusAdmin::UI::Thumbnail::Component, type: :component do
describe ".for" do
let(:promotion_action) { Spree::PromotionAction.new }

subject { render_inline described_class.for(promotion_action) }

it "displays a megaphone" do
subject
expect(page).to have_xpath("//use[contains(@*, '#ri-megaphone')]")
end
end
end
6 changes: 6 additions & 0 deletions legacy_promotions/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@

Capybara.javascript_driver = (ENV['CAPYBARA_DRIVER'] || :selenium_chrome_headless).to_sym

# VIEW COMPONENTS
Rails.application.config.view_component.test_controller = "SolidusAdmin::BaseController"
require "view_component/test_helpers"

RSpec.configure do |config|
config.fixture_path = File.join(__dir__, "fixtures")

Expand All @@ -101,6 +105,8 @@
DummyApp.use_solidus_admin = false
end

config.include ViewComponent::TestHelpers, type: :component

config.include Spree::TestingSupport::JobHelpers
config.include SolidusAdmin::TestingSupport::FeatureHelpers, type: :feature
config.include FactoryBot::Syntax::Methods
Expand Down

0 comments on commit 5bc370a

Please sign in to comment.