Browse Source
* Added repeated code to view component for table in orgs, schemes, users and logs * linted and changed component file name * Fixed typos which fixed failing tests * added unit testing to view component * defined 'path' variable in view component * push for review * fixed hyphons * fixed * another fix * lint * rubocop * renamed expectations in test Co-authored-by: JG <moarpheus@gmail.com>pull/678/head
Ted-U
3 years ago
committed by
GitHub
7 changed files with 53 additions and 29 deletions
@ -0,0 +1,7 @@ |
|||||||
|
<span class="govuk-!-margin-right-4"> |
||||||
|
<% if searched.present? %> |
||||||
|
<strong><%= count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total <%= item %>. <%= govuk_link_to("Clear search", path) %> |
||||||
|
<% else %> |
||||||
|
<strong><%= count %></strong> total <%= item %>. |
||||||
|
<% end %> |
||||||
|
</span> |
@ -0,0 +1,13 @@ |
|||||||
|
class SearchResultCaptionComponent < ViewComponent::Base |
||||||
|
attr_reader :searched, :count, :item_label, :total_count, :item, :path |
||||||
|
|
||||||
|
def initialize(searched:, count:, item_label:, total_count:, item:, path:) |
||||||
|
@searched = searched |
||||||
|
@count = count |
||||||
|
@item_label = item_label |
||||||
|
@total_count = total_count |
||||||
|
@item = item |
||||||
|
@path = path |
||||||
|
super |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,26 @@ |
|||||||
|
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 "renders table caption including the search results and total" do |
||||||
|
result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:)) |
||||||
|
expect(result.to_html).to eq(" <span class=\"govuk-!-margin-right-4\">\n <strong>#{count}</strong> #{item_label} found matching ‘#{searched}’ of <strong>#{total_count}</strong> total #{item}. <a class=\"govuk-link\" href=\"path\">Clear search</a>\n</span>\n") |
||||||
|
end |
||||||
|
|
||||||
|
context "when no search results are found" do |
||||||
|
let(:searched) { nil } |
||||||
|
|
||||||
|
it "renders table caption with total count only" do |
||||||
|
result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:)) |
||||||
|
|
||||||
|
expect(result.to_html).to eq(" <span class=\"govuk-!-margin-right-4\">\n <strong>#{count}</strong> total #{item}.\n</span>\n") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue