Sha256: 897c0fe0632f124f050814bbe5851068d0498ad00f03ce86b8ad66a98a67855c

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BlacklightRangeLimit::FacetItemPresenter, type: :presenter do
  subject(:presenter) do
    described_class.new(facet_item, facet_config, view_context, facet_field, search_state)
  end

  let(:facet_item) { instance_double(Blacklight::Solr::Response::Facets::FacetItem) }
  let(:filter_field) { instance_double(Blacklight::SearchState::FilterField, include?: true) }
  let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'key') }
  let(:facet_field) { instance_double(Blacklight::Solr::Response::Facets::FacetField) }
  let(:view_context) { controller.view_context }
  let(:search_state) { instance_double(Blacklight::SearchState, filter: filter_field) }

  describe '#label' do
    context 'with a single value' do
      let(:facet_item) { 'blah' }

      it 'uses the normal logic for item values' do
        expect(presenter.label).to eq 'blah'
      end
    end

    context 'with a range' do
      let(:facet_item) { 1234..2345 }

      it 'translates the range into some nice, human-readable html' do
        expect(Capybara.string(presenter.label))
          .to have_text('1234 to 2345')
          .and have_css('span.from[data-blrl-begin=1234]', text: '1234')
          .and have_css('span.to[data-blrl-end=2345]', text: '2345')
      end
    end

    context 'with a range that has the same start + end values' do
      let(:facet_item) { 2021..2021 }

      it 'translates the range into some nice, human-readable html' do
        expect(Capybara.string(presenter.label))
          .to have_text('2021')
          .and have_css('span.single[data-blrl-single=2021]', text: '2021')
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
blacklight_range_limit-9.0.0.beta1 spec/presenters/facet_item_presenter_spec.rb
blacklight_range_limit-8.5.0 spec/presenters/facet_item_presenter_spec.rb
blacklight_range_limit-8.4.0 spec/presenters/facet_item_presenter_spec.rb
blacklight_range_limit-8.3.0 spec/presenters/facet_item_presenter_spec.rb
blacklight_range_limit-8.2.3 spec/presenters/facet_item_presenter_spec.rb
blacklight_range_limit-8.2.2 spec/presenters/facet_item_presenter_spec.rb
blacklight_range_limit-8.2.1 spec/presenters/facet_item_presenter_spec.rb
blacklight_range_limit-8.2.0 spec/presenters/facet_item_presenter_spec.rb