Sha256: e4887e6d3af8c56b35ed9691e875aebe09578ecf9eadb0d8bfc0ef53b82a45a0

Contents?: true

Size: 1.78 KB

Versions: 7

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::Response::ViewTypeComponent, type: :component do
  subject(:render) do
    render_inline(described_class.new(response: response, views: views, search_state: search_state))
  end

  let(:response) { instance_double(Blacklight::Solr::Response, empty?: false) }
  let(:search_state) { instance_double(Blacklight::SearchState, to_h: { controller: 'catalog', action: 'index' }) }
  let(:view_config) { Blacklight::Configuration::ViewConfig.new }

  describe "when some views exist" do
    let(:views) do
      {
        abc: view_config,
        def: view_config
      }
    end

    it "draws the group" do
      expect(render.css('.view-type-group')).to be_present
    end
  end

  context 'with a icon component class' do
    let(:views) do
      { abc: Blacklight::Configuration::ViewConfig.new(icon: Blacklight::Icons::ListComponent), def: view_config }
    end

    it 'draws the icon' do
      expect(render.css('.view-type-abc svg')).to be_present
    end
  end

  context 'with a icon component instance' do
    let(:views) do
      { abc: Blacklight::Configuration::ViewConfig.new(icon: Blacklight::Icons::ListComponent.new), def: view_config }
    end

    it 'draws the icon' do
      expect(render.css('.view-type-abc svg')).to be_present
    end
  end

  context 'with a icon with the svg given in-line' do
    let(:views) do
      { abc: Blacklight::Configuration::ViewConfig.new(icon: Blacklight::Icons::IconComponent.new(svg: 'blah')), def: view_config }
    end

    it 'draws the icon' do
      expect(render.css('.view-type-abc').text).to include 'blah'
    end
  end

  describe "when no views exist" do
    let(:views) do
      {}
    end

    it "draws nothing" do
      expect(render.to_html).to be_blank
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
blacklight-8.0.0.beta7 spec/components/blacklight/response/view_type_component_spec.rb
blacklight-8.0.0.beta6 spec/components/blacklight/response/view_type_component_spec.rb
blacklight-8.0.0.beta5 spec/components/blacklight/response/view_type_component_spec.rb
blacklight-8.0.0.beta4 spec/components/blacklight/response/view_type_component_spec.rb
blacklight-8.0.0.beta3 spec/components/blacklight/response/view_type_component_spec.rb
blacklight-8.0.0.beta2 spec/components/blacklight/response/view_type_component_spec.rb
blacklight-8.0.0.beta1 spec/components/blacklight/response/view_type_component_spec.rb