# frozen_string_literal: true
RSpec.describe BlacklightHelper do
before do
allow(helper).to receive(:current_or_guest_user).and_return(User.new)
allow(helper).to receive(:search_action_path) do |*args|
search_catalog_url *args
end
end
describe "#application_name" do
before do
allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::NullStore.new)
end
it "defaults to 'Blacklight'" do
expect(application_name).to eq "Blacklight"
end
context "when the language is not english" do
around do |example|
I18n.locale = :de
example.run
I18n.locale = :en
end
context "and no translation exists for that language" do
it "defaults to 'Blacklight'" do
expect(application_name).to eq "Blacklight"
end
end
context "and a translation exists for that language" do
around do |example|
I18n.backend.store_translations(:de, 'blacklight' => { 'application_name' => 'Schwarzlicht' })
example.run
I18n.backend.reload!
end
it "uses the provided value" do
expect(application_name).to eq "Schwarzlicht"
end
end
end
end
describe "#render_page_title" do
it "looks in content_for(:page_title)" do
helper.content_for(:page_title) { "xyz" }
expect(helper.render_page_title).to eq "xyz"
end
it "looks in the @page_title ivar" do
assign(:page_title, "xyz")
expect(helper.render_page_title).to eq "xyz"
end
it "defaults to the application name" do
expect(helper.render_page_title).to eq helper.application_name
end
end
describe "render_link_rel_alternates" do
let(:document) { instance_double(SolrDocument) }
let(:result) { double }
let(:view_context) { double(blacklight_config: blacklight_config, document_index_view_type: 'index') }
let(:presenter) { Blacklight::IndexPresenter.new(document, view_context) }
let(:blacklight_config) do
Blacklight::Configuration.new.configure do |config|
config.index.title_field = 'title_tsim'
config.index.display_type_field = 'format'
end
end
before do
allow(helper).to receive(:document_presenter).and_return(presenter)
allow(helper).to receive(:blacklight_config).and_return(blacklight_config)
end
it "generates tags" do
expect(presenter).to receive(:link_rel_alternates).and_return(result)
expect(helper.render_link_rel_alternates(document)).to eq result
end
it "sends parameters" do
expect(presenter).to receive(:link_rel_alternates).with({ unique: true }).and_return(result)
expect(helper.render_link_rel_alternates(document, unique: true)).to eq result
end
end
describe "with a config" do
let(:config) do
Blacklight::Configuration.new.configure do |config|
config.index.title_field = 'title_tsim'
config.index.display_type_field = 'format'
end
end
let(:document) { SolrDocument.new('title_tsim' => "A Fake Document", 'id' => '8') }
before do
config.add_show_tools_partial(:bookmark, partial: 'catalog/bookmark_control')
config.add_results_document_tool(:bookmark, partial: 'catalog/bookmark_control', if: :render_bookmarks_control?)
config.add_nav_action(:bookmark, partial: 'blacklight/nav/bookmark')
allow(helper).to receive(:blacklight_config).and_return(config)
allow(helper).to receive_messages(current_bookmarks: [])
end
describe "render_nav_actions" do
it "renders partials" do
buff = String.new
helper.render_nav_actions { |_config, item| buff << "