Sha256: 18a33f507b8f384c39bb62ecfcf7ee7620121b5e6b463502f054a0714063df9c

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

RSpec.describe Blacklight::Component, type: :component do
  let(:component_class) { Blacklight::System::ModalComponent }

  before do
    component_class.reset_compiler!
    ViewComponent::CompileCache.invalidate!

    component_class.class_eval do
      undef :call if method_defined?(:call)
    end
  end

  after do
    component_class.reset_compiler!
    ViewComponent::CompileCache.invalidate!

    component_class.class_eval do
      undef :call if method_defined?(:call)
    end
  end

  context "without overrides" do
    it "renders the engine template" do
      render_inline(component_class.new)
      expect(page).to have_css('.modal-header')
    end
  end

  context "with overrides" do
    around do |ex|
      FileUtils.mkdir_p(Rails.root.join('app/components/blacklight/system'))
      Rails.root.join("app/components/blacklight/system/modal_component.html.erb").open("w") do |f|
        f.puts '<div class="custom-modal">Overridden</div>'
      end

      ex.run
    ensure
      Rails.root.join('app/components/blacklight/system/modal_component.html.erb').unlink
    end

    it "renders to application template" do
      render_inline(component_class.new)
      expect(page).to have_css('.custom-modal')
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-8.8.4 spec/lib/blacklight/component_spec.rb
blacklight-8.8.3 spec/lib/blacklight/component_spec.rb
blacklight-8.8.2 spec/lib/blacklight/component_spec.rb
blacklight-9.0.0.beta1 spec/lib/blacklight/component_spec.rb
blacklight-8.8.1 spec/lib/blacklight/component_spec.rb
blacklight-8.8.0 spec/lib/blacklight/component_spec.rb
blacklight-8.7.0 spec/lib/blacklight/component_spec.rb
blacklight-8.6.1 spec/lib/blacklight/component_spec.rb
blacklight-7.40.0 spec/lib/blacklight/component_spec.rb
blacklight-8.6.0 spec/lib/blacklight/component_spec.rb
blacklight-8.5.1 spec/lib/blacklight/component_spec.rb
blacklight-8.5.0 spec/lib/blacklight/component_spec.rb