Sha256: 0bbaee37a77495d7654aac8347ce971e1589a39706c473b38945f7a4812fc518

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::Document::GroupComponent, type: :component do
  subject(:component) { described_class.new(group: group, **attr) }

  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(:docs) { 10.times.map { double } }

  let(:group) do
    instance_double(Blacklight::Solr::Response::Group, key: 'group1', field: 'group_field', total: 15, docs: docs)
  end

  before do
    allow(view_context).to receive(:render_document_index).with(docs).and_return('results')
  end

  it 'renders the group with a header' do
    expect(rendered).to have_css 'div.group'
    expect(rendered).to have_css 'h2', text: 'group1'
    expect(rendered).to have_no_link 'more'
  end

  it 'renders the group documents' do
    expect(rendered).to have_content 'results'
  end

  context 'with a limit applied' do
    let(:attr) { { group_limit: 5 } }

    it 'renders a control to see more results' do
      expect(rendered).to have_link 'more'
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
blacklight-8.6.1 spec/components/blacklight/document/group_component_spec.rb
blacklight-8.6.0 spec/components/blacklight/document/group_component_spec.rb
blacklight-8.5.1 spec/components/blacklight/document/group_component_spec.rb
blacklight-8.5.0 spec/components/blacklight/document/group_component_spec.rb
blacklight-8.4.0 spec/components/blacklight/document/group_component_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/spec/components/blacklight/document/group_component_spec.rb
blacklight-8.3.0 spec/components/blacklight/document/group_component_spec.rb