Browse Source

CLDC-3048 Fix pluralisation for 1 result (#2841)

* Fix pluralisation for 1 result

* Fix world

* Update tests
pull/2857/head
kosiakkatrina 2 months ago committed by GitHub
parent
commit
b8a576d87f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/components/search_result_caption_component.html.erb
  2. 2
      app/views/bulk_upload_shared/uploads.html.erb
  3. 2
      app/views/locations/index.html.erb
  4. 2
      app/views/logs/_log_list.html.erb
  5. 2
      app/views/logs/index.html.erb
  6. 2
      app/views/logs/update_logs.html.erb
  7. 4
      app/views/organisation_relationships/managing_agents.html.erb
  8. 4
      app/views/organisation_relationships/stock_owners.html.erb
  9. 2
      app/views/organisations/_organisation_list.html.erb
  10. 2
      app/views/organisations/index.html.erb
  11. 2
      app/views/organisations/logs.html.erb
  12. 2
      app/views/schemes/_scheme_list.html.erb
  13. 2
      app/views/users/_user_list.html.erb
  14. 26
      spec/components/search_result_caption_component_spec.rb
  15. 4
      spec/requests/lettings_logs_controller_spec.rb
  16. 12
      spec/requests/organisation_relationships_controller_spec.rb
  17. 8
      spec/requests/organisations_controller_spec.rb
  18. 4
      spec/requests/sales_logs_controller_spec.rb

2
app/components/search_result_caption_component.html.erb

@ -7,7 +7,7 @@
<strong><%= count %></strong> <%= item_label.pluralize(count) %> matching filters<br>
<% else %>
<span class="govuk-!-margin-right-4">
<strong><%= count %></strong> total <%= item %>
<strong><%= count %></strong> total <%= item.pluralize(count) %>
</span>
<% end %>
</span>

2
app/views/bulk_upload_shared/uploads.html.erb

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "uploads") %>
<% item_label = format_label(@pagy.count, "upload") %>
<% title = format_title(@searched, bulk_upload_title(controller.controller_name), current_user, item_label, @pagy.count, nil) %>
<% content_for :title, title %>

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

@ -32,7 +32,7 @@
count: @pagy.count,
item_label:,
total_count: @total_count,
item: "locations",
item: "location",
filters_count: applied_filters_count(@filter_type),
)) %>
<% end %>

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

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

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

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "logs") %>
<% item_label = format_label(@pagy.count, "log") %>
<% title = format_title(@searched, "#{log_type_for_controller(controller).capitalize} logs", current_user, item_label, @pagy.count, nil) %>
<% content_for :title, title %>

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

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "logs") %>
<% item_label = format_label(@pagy.count, "log") %>
<% title = "Update logs" %>
<% content_for :title, title %>

4
app/views/organisation_relationships/managing_agents.html.erb

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "managing agents") %>
<% item_label = format_label(@pagy.count, "managing agent") %>
<% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
@ -44,7 +44,7 @@
pagy: @pagy,
searched: @searched,
item_label:,
search_item: "managing agents",
search_item: "managing agent",
total_count: @total_count,
remove_path: ->(org_id) { managing_agents_remove_organisation_path(target_organisation_id: org_id) },
} %>

4
app/views/organisation_relationships/stock_owners.html.erb

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "stock owners") %>
<% item_label = format_label(@pagy.count, "stock owner") %>
<% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
@ -41,7 +41,7 @@
pagy: @pagy,
searched: @searched,
item_label:,
search_item: "stock owners",
search_item: "stock owner",
total_count: @total_count,
remove_path: ->(org_id) { stock_owners_remove_organisation_path(target_organisation_id: org_id) },
} %>

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

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.with_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", filters_count: applied_filters_count(@filter_type))) %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "organisation", filters_count: applied_filters_count(@filter_type))) %>
<% end %>
<%= table.with_head do |head| %>
<%= head.with_row do |row| %>

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

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "organisations") %>
<% item_label = format_label(@pagy.count, "organisation") %>
<% title = format_title(@searched, "Organisations", current_user, item_label, @pagy.count, nil) %>
<% content_for :title, title %>

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

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "logs") %>
<% item_label = format_label(@pagy.count, "log") %>
<% title = format_title(@searched, action_name.humanize, current_user, item_label, @pagy.count, @organisation.name) %>
<% content_for :title, title %>

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

@ -2,7 +2,7 @@
<%= govuk_table do |table| %>
<%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<span class="app-search__caption">
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "schemes", filters_count: applied_filters_count(@filter_type))) %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "scheme", filters_count: applied_filters_count(@filter_type))) %>
<% if @schemes&.any? %>
<%= govuk_link_to "Download schemes (CSV)", schemes_csv_download_url, type: "text/csv", class: "govuk-!-margin-right-4", style: "white-space: nowrap" %>
<%= govuk_link_to "Download locations (CSV)", locations_csv_download_url, type: "text/csv", class: "govuk-!-margin-right-4", style: "white-space: nowrap" %>

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

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.with_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", filters_count: applied_filters_count(@filter_type))) %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "user", filters_count: applied_filters_count(@filter_type))) %>
<% if current_user.support? %>
<% query = searched.present? ? "?search=#{searched}" : nil %>
<%= govuk_link_to "Download (CSV)", "#{request.path}.csv#{query}", type: "text/csv", style: "white-space: nowrap" %>

26
spec/components/search_result_caption_component_spec.rb

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

4
spec/requests/lettings_logs_controller_spec.rb

@ -759,7 +759,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "has search results in the title" do
get "/lettings-logs?search=#{log_to_search.id}", headers:, params: {}
expect(page).to have_title("Lettings logs (1 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
expect(page).to have_title("Lettings logs (1 log matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
it "shows lettings logs matching the id" do
@ -895,7 +895,7 @@ RSpec.describe LettingsLogsController, type: :request do
end
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> total log")
end
it "does not show the pagination links" do

12
spec/requests/organisation_relationships_controller_spec.rb

@ -53,7 +53,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
expect(page).to have_content("1 total stock owners")
expect(page).to have_content("1 total stock owner")
end
context "when adding a stock owner" do
@ -149,7 +149,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
expect(page).to have_content("1 total managing agents")
expect(page).to have_content("1 total managing agent")
end
context "and current organisation is deactivated" do
@ -345,7 +345,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
expect(page).to have_content("1 total stock owners")
expect(page).to have_content("1 total stock owner")
end
end
@ -481,7 +481,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
expect(page).to have_content("1 total managing agents")
expect(page).to have_content("1 total managing agent")
end
end
@ -647,7 +647,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
expect(page).to have_content("1 total stock owners")
expect(page).to have_content("1 total stock owner")
end
context "when adding a stock owner" do
@ -697,7 +697,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
expect(page).to have_content("1 total managing agents")
expect(page).to have_content("1 total managing agent")
end
it "shows remove link(s)" do

8
spec/requests/organisations_controller_spec.rb

@ -1203,7 +1203,7 @@ RSpec.describe OrganisationsController, type: :request do
it "has search results in the title" do
get "/organisations/#{organisation.id}/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {}
expect(page).to have_title("#{organisation.name} (1 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
expect(page).to have_title("#{organisation.name} (1 log matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
it "has search term in the search box" do
@ -1352,7 +1352,7 @@ RSpec.describe OrganisationsController, type: :request do
it "has search results in the title" do
get "/organisations/#{organisation.id}/sales-logs?search=#{log_to_search.id}", headers: headers, params: {}
expect(page).to have_title("#{organisation.name} (1 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
expect(page).to have_title("#{organisation.name} (1 log matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
it "shows sales logs matching the id" do
@ -1616,11 +1616,11 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
expect(page).to have_content("1 organisations matching search")
expect(page).to have_content("1 organisation matching search")
end
it "has search in the title" do
expect(page).to have_title("Organisations (1 organisations matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
expect(page).to have_title("Organisations (1 organisation matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
context "when the search term matches more than 1 result" do

4
spec/requests/sales_logs_controller_spec.rb

@ -610,7 +610,7 @@ RSpec.describe SalesLogsController, type: :request do
it "has search results in the title" do
get "/sales-logs?search=#{log_to_search.id}", headers: headers, params: {}
expect(page).to have_title("Sales logs (1 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
expect(page).to have_title("Sales logs (1 log matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
it "shows sales logs matching the id" do
@ -692,7 +692,7 @@ RSpec.describe SalesLogsController, type: :request do
end
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> total log")
end
it "does not show the pagination links" do

Loading…
Cancel
Save