Sha256: 8e2bd172aa4ea5a7c00ae06293c96afb09e52cab5f0a343c46b126b8f4e4dcef

Contents?: true

Size: 1.96 KB

Versions: 10

Compression:

Stored size: 1.96 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(:blacklight_config) do
    Blacklight::Configuration.new.configure do |config|
      config.add_facet_field :z
    end
  end

  let(:search_state) do
    Blacklight::SearchState.new({}, blacklight_config)
  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: nokogiri_mediated_href(facet_item.href)
    expect(rendered).to have_selector '.facet-count', text: '10'
  end

  it 'has the facet hierarchy' do
    pending
    expect(rendered).to have_selector 'li ul.pivot-facet'
    expect(rendered).to have_link 'x:1', href: nokogiri_mediated_href(facet_item.facet_item_presenters.first.href)
  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

10 entries across 10 versions & 2 rubygems

Version Path
blacklight-7.40.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.39.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.38.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.37.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.36.2 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.36.1 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.36.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.35.0 spec/components/blacklight/facet_item_pivot_component_spec.rb
blacklight-7.34.0 spec/components/blacklight/facet_item_pivot_component_spec.rb