|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +RSpec.describe Blacklight::SkipLinkComponent, type: :component do |
| 6 | + subject(:rendered) do |
| 7 | + render_inline_to_capybara_node(described_class.new) |
| 8 | + end |
| 9 | + |
| 10 | + before do |
| 11 | + allow(controller).to receive(:blacklight_config).and_return(blacklight_config) |
| 12 | + end |
| 13 | + |
| 14 | + context 'with no search fields' do |
| 15 | + let(:blacklight_config) do |
| 16 | + Blacklight::Configuration.new.configure do |config| |
| 17 | + config.search_fields = {} |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + it 'renders skip links with correct link to search' do |
| 22 | + expect(rendered).to have_link("Skip to main content", href: '#main-container') |
| 23 | + expect(rendered).to have_link("Skip to search", href: "#q") |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + context 'with one search field' do |
| 28 | + let(:blacklight_config) do |
| 29 | + Blacklight::Configuration.new.configure do |config| |
| 30 | + config.search_fields = { "all_fields" => "" } |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + it 'renders skip links with correct link to search' do |
| 35 | + expect(rendered).to have_link("Skip to main content", href: "#main-container") |
| 36 | + expect(rendered).to have_link("Skip to search", href: "#q") |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context 'with two search field' do |
| 41 | + let(:blacklight_config) do |
| 42 | + Blacklight::Configuration.new.configure do |config| |
| 43 | + config.search_fields = { "all_fields" => "", "title_field" => "" } |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + it 'renders skip links with correct link to search' do |
| 48 | + expect(rendered).to have_link("Skip to main content", href: "#main-container") |
| 49 | + expect(rendered).to have_link("Skip to search", href: "#search_field") |
| 50 | + end |
| 51 | + end |
| 52 | +end |
0 commit comments