Sha256: f98a3a49ebae621559a351dc43c8089c46e017f31e0631817a5485a74795b860

Contents?: true

Size: 1.29 KB

Versions: 42

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::Document::ActionComponent, type: :component do
  subject(:component) { described_class.new(document: document, action: action, **attr) }

  let(:action) { Blacklight::Configuration::ToolConfig.new(key: 'some_tool', name: 'some_tool', component: true) }
  let(:attr) { {} }
  let(:view_context) { controller.view_context }
  let(:render) do
    component.render_in(view_context)
  end

  let(:rendered) do
    Capybara::Node::Simple.new(render)
  end

  let(:document) do
    SolrDocument.new(
      id: 'x'
    )
  end

  it 'renders an action link' do
    if Rails.version >= '6'
      allow(view_context).to receive(:some_tool_solr_document_path).with(document, { only_path: true }).and_return('/asdf')
    else
      allow(view_context).to receive(:some_tool_solr_document_path).with(document).and_return('/asdf')
    end

    expect(rendered).to have_link 'Some tool', href: '/asdf'
  end

  context 'with a partial configured' do
    let(:action) { Blacklight::Configuration::ToolConfig.new(name: '', partial: '/some/tool') }

    it 'render the partial' do
      allow(view_context).to receive(:render).with(hash_including(partial: '/some/tool')).and_return('tool')

      expect(rendered).to have_content 'tool'
    end
  end
end

Version data entries

42 entries across 41 versions & 2 rubygems

Version Path
blacklight-7.38.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/spec/components/blacklight/document/action_component_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/spec/components/blacklight/document/action_component_spec.rb
blacklight-8.3.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.2.2 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.2.1 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.2.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-7.37.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-7.36.2 spec/components/blacklight/document/action_component_spec.rb
blacklight-7.36.1 spec/components/blacklight/document/action_component_spec.rb
blacklight-7.36.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-7.35.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.1.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-7.34.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.0.1 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.0.0 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.0.0.beta8 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.0.0.beta7 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.0.0.beta6 spec/components/blacklight/document/action_component_spec.rb
blacklight-8.0.0.beta5 spec/components/blacklight/document/action_component_spec.rb