Browse Source

Update search/filter caption content

pull/1999/head
Kat 3 years ago
parent
commit
f90128a9a6
  1. 10
      app/components/search_result_caption_component.html.erb
  2. 5
      app/components/search_result_caption_component.rb
  3. 4
      app/helpers/filters_helper.rb
  4. 2
      app/views/locations/index.html.erb
  5. 2
      app/views/logs/_log_list.html.erb
  6. 2
      app/views/organisations/_organisation_list.html.erb
  7. 2
      app/views/schemes/_scheme_list.html.erb
  8. 2
      app/views/users/_user_list.html.erb
  9. 44
      spec/components/search_result_caption_component_spec.rb
  10. 4
      spec/requests/lettings_logs_controller_spec.rb
  11. 4
      spec/requests/locations_controller_spec.rb
  12. 28
      spec/requests/organisations_controller_spec.rb
  13. 4
      spec/requests/sales_logs_controller_spec.rb
  14. 8
      spec/requests/schemes_controller_spec.rb
  15. 10
      spec/requests/users_controller_spec.rb

10
app/components/search_result_caption_component.html.erb

@ -1,7 +1,11 @@
<span class="govuk-!-margin-right-4"> <span class="govuk-!-margin-right-4">
<% if searched.present? %> <% if searched.present? && filters_count&.positive? %>
<strong><%= count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total <%= item %>. <strong><%= count %></strong> <%= item_label.pluralize(count) %> matching search and filters
<% elsif searched.present? %>
<strong><%= count %></strong> <%= item_label.pluralize(count) %> matching search
<% elsif filters_count&.positive? %>
<strong><%= count %></strong> <%= item_label.pluralize(count) %> matching filters
<% else %> <% else %>
<strong><%= count %></strong> total <%= item %> <strong><%= count %></strong> matching <%= item %>
<% end %> <% end %>
</span> </span>

5
app/components/search_result_caption_component.rb

@ -1,12 +1,13 @@
class SearchResultCaptionComponent < ViewComponent::Base class SearchResultCaptionComponent < ViewComponent::Base
attr_reader :searched, :count, :item_label, :total_count, :item, :path attr_reader :searched, :count, :item_label, :total_count, :item, :filters_count
def initialize(searched:, count:, item_label:, total_count:, item:) def initialize(searched:, count:, item_label:, total_count:, item:, filters_count:)
@searched = searched @searched = searched
@count = count @count = count
@item_label = item_label @item_label = item_label
@total_count = total_count @total_count = total_count
@item = item @item = item
@filters_count = filters_count
super super
end end
end end

4
app/helpers/filters_helper.rb

@ -139,12 +139,12 @@ module FiltersHelper
request.path.include?("/lettings-logs") request.path.include?("/lettings-logs")
end end
private
def applied_filters_count(filter_type) def applied_filters_count(filter_type)
filters_count(applied_filters(filter_type)) filters_count(applied_filters(filter_type))
end end
private
def applied_filters(filter_type) def applied_filters(filter_type)
return {} unless session[session_name_for(filter_type)] return {} unless session[session_name_for(filter_type)]

2
app/views/locations/index.html.erb

@ -24,7 +24,7 @@
<%= govuk_table do |table| %> <%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched: @searched, count: @pagy.count, item_label:, total_count: @total_count, item: "locations")) %> <%= render(SearchResultCaptionComponent.new(searched: @searched, count: @pagy.count, item_label:, total_count: @total_count, item: "locations", filters_count: applied_filters_count(@filter_type))) %>
<% end %> <% end %>
<%= table.head do |head| %> <%= table.head do |head| %>
<%= head.row do |row| %> <%= head.row do |row| %>

2
app/views/logs/_log_list.html.erb

@ -1,7 +1,7 @@
<h2 class="govuk-body"> <h2 class="govuk-body">
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters"> <div class="govuk-grid-column-three-quarters">
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "logs")) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "logs", filters_count: applied_filters_count(@filter_type))) %>
<% if logs&.any? %> <% if logs&.any? %>
<%= govuk_link_to "Download (CSV)", csv_download_url, type: "text/csv", class: "govuk-!-margin-right-4" %> <%= govuk_link_to "Download (CSV)", csv_download_url, type: "text/csv", class: "govuk-!-margin-right-4" %>
<% if @current_user.support? %> <% if @current_user.support? %>

2
app/views/organisations/_organisation_list.html.erb

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> <section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %> <%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "organisations")) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "organisations", filters_count: applied_filters_count(@filter_type))) %>
<% end %> <% end %>
<%= table.head do |head| %> <%= table.head do |head| %>
<%= head.row do |row| %> <%= head.row do |row| %>

2
app/views/schemes/_scheme_list.html.erb

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> <section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %> <%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "schemes")) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "schemes", filters_count: applied_filters_count(@filter_type))) %>
<% end %> <% end %>
<%= table.head do |head| %> <%= table.head do |head| %>
<%= head.row do |row| %> <%= head.row do |row| %>

2
app/views/users/_user_list.html.erb

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> <section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %> <%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "users")) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "users", filters_count: applied_filters_count(@filter_type))) %>
<% if current_user.support? %> <% if current_user.support? %>
<% query = searched.present? ? "?search=#{searched}" : nil %> <% query = searched.present? ? "?search=#{searched}" : nil %>
<%= govuk_link_to "Download (CSV)", "#{request.path}.csv#{query}", type: "text/csv" %> <%= govuk_link_to "Download (CSV)", "#{request.path}.csv#{query}", type: "text/csv" %>

44
spec/components/search_result_caption_component_spec.rb

@ -6,19 +6,53 @@ RSpec.describe SearchResultCaptionComponent, type: :component do
let(:item_label) { "user" } let(:item_label) { "user" }
let(:total_count) { 3 } let(:total_count) { 3 }
let(:item) { "schemes" } let(:item) { "schemes" }
let(:filters_count) { 1 }
let(:result) { render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, filters_count:)) }
context "when search and filter results are found" do
it "renders table caption including the search results and total" do 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>2</strong> users matching search and filters\n</span>\n")
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}.\n") end
end
context "when search results are found" do
let(:filters_count) { nil }
it "renders table caption including the search results and total" do
expect(result.to_html).to eq("<span class=\"govuk-!-margin-right-4\">\n <strong>2</strong> users matching search\n</span>\n")
end
end end
context "when no search results are found" do context "when filter results are found" do
let(:searched) { nil } let(:searched) { nil }
it "renders table caption including the search results and total" do
expect(result.to_html).to eq("<span class=\"govuk-!-margin-right-4\">\n <strong>2</strong> users matching filters\n</span>\n")
end
end
context "when no search/filter is applied" do
let(:searched) { nil }
let(:filters_count) { nil }
it "renders table caption with total count only" do
expect(result.to_html).to eq("<span class=\"govuk-!-margin-right-4\">\n <strong>#{count}</strong> matching #{item}\n</span>\n")
end
end
context "when nothing is found" do
let(:count) { 0 }
it "renders table caption with total count only" do 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>0</strong> users matching search and filters\n</span>\n")
end
end
expect(result.to_html).to eq("<span class=\"govuk-!-margin-right-4\">\n <strong>#{count}</strong> total #{item}\n</span>\n") context "when 1 record is found" do
let(:count) { 1 }
it "renders table caption with total count only" do
expect(result.to_html).to eq("<span class=\"govuk-!-margin-right-4\">\n <strong>1</strong> user matching search and filters\n</span>\n")
end end
end end
end end

4
spec/requests/lettings_logs_controller_spec.rb

@ -774,7 +774,7 @@ RSpec.describe LettingsLogsController, type: :request do
end end
it "shows the total log count" do it "shows the total log count" do
expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> total logs") expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> matching logs")
end end
it "does not show the pagination links" do it "does not show the pagination links" do
@ -868,7 +868,7 @@ RSpec.describe LettingsLogsController, type: :request do
end end
it "shows the total log count" do it "shows the total log count" do
expect(CGI.unescape_html(response.body)).to match("<strong>26</strong> total logs") expect(CGI.unescape_html(response.body)).to match("<strong>26</strong> matching logs")
end end
it "has pagination links" do it "has pagination links" do

4
spec/requests/locations_controller_spec.rb

@ -274,7 +274,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 location found matching #{search_param}") expect(page).to have_content("1 location matching search")
end end
it "has search in the title" do it "has search in the title" do
@ -402,7 +402,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 location found matching #{search_param}") expect(page).to have_content("1 location matching search")
end end
it "has search in the title" do it "has search in the title" do

28
spec/requests/organisations_controller_spec.rb

@ -89,7 +89,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 scheme found matching #{search_param}") expect(page).to have_content("1 scheme matching search")
end end
it "has search in the title" do it "has search in the title" do
@ -171,7 +171,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 scheme found matching #{search_param}") expect(page).to have_content("1 scheme matching search")
end end
it "has search in the title" do it "has search in the title" do
@ -332,7 +332,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("#{user.organisation.users.count} total users") expect(page).to have_content("#{user.organisation.users.count} matching users")
end end
end end
@ -716,7 +716,7 @@ RSpec.describe OrganisationsController, type: :request do
total_number_of_orgs = Organisation.all.count total_number_of_orgs = Organisation.all.count
expect(page).to have_link organisation.name, href: "organisations/#{organisation.id}/lettings-logs" expect(page).to have_link organisation.name, href: "organisations/#{organisation.id}/lettings-logs"
expect(page).to have_link unauthorised_organisation.name, href: "organisations/#{unauthorised_organisation.id}/lettings-logs" expect(page).to have_link unauthorised_organisation.name, href: "organisations/#{unauthorised_organisation.id}/lettings-logs"
expect(page).to have_content("#{total_number_of_orgs} total organisations") expect(page).to have_content("#{total_number_of_orgs} matching organisations")
end end
it "shows a search bar" do it "shows a search bar" do
@ -745,7 +745,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "only shows logs for that organisation" do it "only shows logs for that organisation" do
expect(page).to have_content("#{total_number_of_org1_logs} total logs") expect(page).to have_content("#{total_number_of_org1_logs} matching logs")
organisation.lettings_logs.visible.map(&:id).each do |lettings_log_id| organisation.lettings_logs.visible.map(&:id).each do |lettings_log_id|
expect(page).to have_link lettings_log_id.to_s, href: "/lettings-logs/#{lettings_log_id}" expect(page).to have_link lettings_log_id.to_s, href: "/lettings-logs/#{lettings_log_id}"
@ -899,7 +899,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "only shows logs for that organisation" do it "only shows logs for that organisation" do
expect(page).to have_content("#{number_of_org1_sales_logs} total logs") expect(page).to have_content("#{number_of_org1_sales_logs} matching logs")
organisation.sales_logs.map(&:id).each do |sales_log_id| organisation.sales_logs.map(&:id).each do |sales_log_id|
expect(page).to have_link sales_log_id.to_s, href: "/sales-logs/#{sales_log_id}" expect(page).to have_link sales_log_id.to_s, href: "/sales-logs/#{sales_log_id}"
end end
@ -1033,7 +1033,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 user found matching #{search_param}’ of #{org_user_count} total users.") expect(page).to have_content("1 user matching search")
end end
context "when we need case insensitive search" do context "when we need case insensitive search" do
@ -1053,7 +1053,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 user found matching #{search_param}’ of #{org_user_count} total users.") expect(page).to have_content("1 user matching search")
end end
end end
end end
@ -1075,13 +1075,13 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 user found matching #{search_param}’ of #{org_user_count} total users.") expect(page).to have_content("1 user matching search")
end end
context "when our search term matches an email and a name" do context "when our search term matches an email and a name" do
let!(:matching_user) { create(:user, organisation:, name: "Foobar", email: "some@example.com") } let!(:matching_user) { create(:user, organisation:, name: "Foobar", email: "some@example.com") }
let!(:another_matching_user) { create(:user, organisation:, name: "Joe", email: "foobar@example.com") } let!(:another_matching_user) { create(:user, organisation:, name: "Joe", email: "foobar@example.com") }
let!(:org_user_count) { User.where(organisation:).count } let(:org_user_count) { User.where(organisation:).count }
let(:search_param) { "Foobar" } let(:search_param) { "Foobar" }
before do before do
@ -1103,7 +1103,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("2 users found matching #{search_param}’ of #{org_user_count} total users.") expect(page).to have_content("2 users matching search")
end end
end end
end end
@ -1160,7 +1160,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "shows the total organisations count" do it "shows the total organisations count" do
expect(CGI.unescape_html(response.body)).to match("<strong>#{total_organisations_count}</strong> total organisations") expect(CGI.unescape_html(response.body)).to match("<strong>#{total_organisations_count}</strong> matching organisations")
end end
it "has pagination links" do it "has pagination links" do
@ -1194,7 +1194,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 organisations found matching #{search_param}") expect(page).to have_content("1 organisations matching search")
end end
it "has search in the title" do it "has search in the title" do
@ -1210,7 +1210,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("2 organisations found matching #{search_param}") expect(page).to have_content("2 organisations matching search")
end end
it "has search in the title" do it "has search in the title" do

4
spec/requests/sales_logs_controller_spec.rb

@ -655,7 +655,7 @@ RSpec.describe SalesLogsController, type: :request do
end end
it "shows the total log count" do it "shows the total log count" do
expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> total logs") expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> matching logs")
end end
it "does not show the pagination links" do it "does not show the pagination links" do
@ -708,7 +708,7 @@ RSpec.describe SalesLogsController, type: :request do
end end
it "shows the total log count" do it "shows the total log count" do
expect(CGI.unescape_html(response.body)).to match("<strong>26</strong> total logs") expect(CGI.unescape_html(response.body)).to match("<strong>26</strong> matching logs")
end end
it "has pagination links" do it "has pagination links" do

8
spec/requests/schemes_controller_spec.rb

@ -234,7 +234,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "shows the total organisations count" do it "shows the total organisations count" do
expect(CGI.unescape_html(response.body)).to match("<strong>#{schemes.count}</strong> total schemes") expect(CGI.unescape_html(response.body)).to match("<strong>#{schemes.count}</strong> matching schemes")
end end
context "when paginating over 20 results" do context "when paginating over 20 results" do
@ -250,7 +250,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "shows the total schemes count" do it "shows the total schemes count" do
expect(CGI.unescape_html(response.body)).to match("<strong>#{total_schemes_count}</strong> total schemes") expect(CGI.unescape_html(response.body)).to match("<strong>#{total_schemes_count}</strong> matching schemes")
end end
it "shows which schemes are being shown on the current page" do it "shows which schemes are being shown on the current page" do
@ -275,7 +275,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "shows the total schemes count" do it "shows the total schemes count" do
expect(CGI.unescape_html(response.body)).to match("<strong>#{total_schemes_count}</strong> total schemes") expect(CGI.unescape_html(response.body)).to match("<strong>#{total_schemes_count}</strong> matching schemes")
end end
it "has pagination links" do it "has pagination links" do
@ -321,7 +321,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 scheme found matching #{search_param}") expect(page).to have_content("1 scheme matching search")
end end
it "has search in the title" do it "has search in the title" do

10
spec/requests/users_controller_spec.rb

@ -430,7 +430,7 @@ RSpec.describe UsersController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 user found matching ‘filter’ of 4 total users.") expect(page).to have_content("1 user matching search")
end end
end end
@ -466,7 +466,7 @@ RSpec.describe UsersController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("2 users found matching ‘joe’ of 4 total users.") expect(page).to have_content("2 users matching search")
end end
end end
end end
@ -1136,7 +1136,7 @@ RSpec.describe UsersController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("4 total users") expect(page).to have_content("4 matching users")
end end
it "shows the download csv link" do it "shows the download csv link" do
@ -1164,7 +1164,7 @@ RSpec.describe UsersController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("1 user found matching #{search_param}’ of 4 total users.") expect(page).to have_content("1 user matching search")
end end
it "includes the search term in the CSV download link" do it "includes the search term in the CSV download link" do
@ -1207,7 +1207,7 @@ RSpec.describe UsersController, type: :request do
end end
it "updates the table caption" do it "updates the table caption" do
expect(page).to have_content("2 users found matching ‘joe’ of 4 total users.") expect(page).to have_content("2 users matching search")
end end
end end
end end

Loading…
Cancel
Save