Sha256: dde621eaf145b2c14e77ec65864419e5852aeb7922dcee329610460c0bb0f3b4

Contents?: true

Size: 1.77 KB

Versions: 12

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::FacetItemPivotComponent, type: :component do
  subject(:rendered) do
    render_inline_to_capybara_node(described_class.new(facet_item: facet_item))
  end

  let(:search_state) do
    Blacklight::SearchState.new({}, Blacklight::Configuration.new)
  end

  let(:facet_item) do
    instance_double(
      Blacklight::FacetItemPresenter,
      facet_config: Blacklight::Configuration::FacetField.new(key: 'z'),
      facet_field: 'z',
      label: 'x',
      hits: 10,
      href: '/catalog?f[z]=x',
      selected?: false,
      search_state: search_state,
      items: [OpenStruct.new(value: 'x:1', hits: 5)]
    )
  end

  it 'links to the facet and shows the number of hits' do
    expect(rendered).to have_selector 'li'
    expect(rendered).to have_link 'x', href: '/catalog?f%5Bz%5D=x'
    expect(rendered).to have_selector '.facet-count', text: '10'
  end

  it 'has the facet hierarchy' do
    expect(rendered).to have_selector 'li ul.pivot-facet'
    expect(rendered).to have_link 'x:1', href: /f%5Bz%5D%5B%5D=x%3A1/
  end

  context 'with a selected facet' do
    let(:facet_item) do
      instance_double(
        Blacklight::FacetItemPresenter,
        facet_config: Blacklight::Configuration::FacetField.new,
        facet_field: 'z',
        label: 'x',
        hits: 10,
        href: '/catalog',
        selected?: true,
        search_state: search_state,
        items: []
      )
    end

    it 'links to the facet and shows the number of hits' do
      expect(rendered).to have_selector 'li'
      expect(rendered).to have_selector '.selected', text: 'x'
      expect(rendered).to have_link '[remove]', href: '/catalog'
      expect(rendered).to have_selector '.selected.facet-count', text: '10'
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-7.24.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.23.0.1 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.23.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.22.2 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.22.1 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.22.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.21.2 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.21.1 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.21.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.20.1 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.20.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.19.2 spec/components/blacklight/facet_item_pivot_component_spec.rb