diff --git a/app/components/search_result_caption_component.html.erb b/app/components/search_result_caption_component.html.erb index f011a6b37..49ffbdc07 100644 --- a/app/components/search_result_caption_component.html.erb +++ b/app/components/search_result_caption_component.html.erb @@ -1,6 +1,6 @@ <% if searched.present? %> - <%= count %> <%= item_label %> found matching ‘<%= searched %>’ of <%= total_count %> total <%= item %>. <%= govuk_link_to("Clear search", request.path) %> + <%= count %> <%= item_label %> found matching '<%= searched %>' of <%= total_count %> total <%= item %>. <%= govuk_link_to("Clear search", path) %> <% else %> <%= count %> total <%= item %>. <% end %> diff --git a/app/components/search_result_caption_component.rb b/app/components/search_result_caption_component.rb index a6bf9cd63..8565c125d 100644 --- a/app/components/search_result_caption_component.rb +++ b/app/components/search_result_caption_component.rb @@ -1,13 +1,13 @@ class SearchResultCaptionComponent < ViewComponent::Base - attr_reader :searched, :count, :item_label, :total_count, :item, :request + attr_reader :searched, :count, :item_label, :total_count, :item, :path - def initialize(searched:, count:, item_label:, total_count:, item:, request:) + def initialize(searched:, count:, item_label:, total_count:, item:, path:) @searched = searched @count = count @item_label = item_label @total_count = total_count @item = item - @request = request + @path = path super end end diff --git a/spec/components/search_result_caption_component_spec.rb b/spec/components/search_result_caption_component_spec.rb new file mode 100644 index 000000000..3eb351b6d --- /dev/null +++ b/spec/components/search_result_caption_component_spec.rb @@ -0,0 +1,23 @@ +require "rails_helper" + +RSpec.describe SearchResultCaptionComponent, type: :component do + let(:page) { Capybara::Node::Simple.new(rendered_component) } + let(:searched) { "search item" } + let(:count) { 2 } + let(:item_label) { "user" } + let(:total_count) { 3 } + let(:item) { "schemes" } + let(:path) { "path" } + + it "all of the nav tabs specified in the items hash are passed to it" do + result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:)) + expect(result.to_html).to eq(" \n #{count} #{item_label} found matching '#{searched}' of #{total_count} total #{item}. Clear search\n\n") + end + + context "when no search results are found" do + it "all of the nav tabs specified in the items hash are passed to it" do + result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:)) + expect(result.to_html).to eq(" \n #{count} #{item_label} found matching '#{searched}' of #{total_count} total #{item}. Clear search\n\n") + end + end +end