Browse Source

CLDC-2743 Search improvements (#1999)

* Move clear search, pass search when filtering

* Update search/filter caption content

* Put download links on the next line

* set filters_count to 0 where there are no filters

* Correctly display delete logs for support

* Update tests

* persist search after clearing filters
demo-branch
kosiakkatrina 1 year ago committed by GitHub
parent
commit
55ae6692bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/components/search_component.html.erb
  2. 10
      app/components/search_result_caption_component.html.erb
  3. 6
      app/components/search_result_caption_component.rb
  4. 2
      app/controllers/sessions_controller.rb
  5. 4
      app/helpers/filters_helper.rb
  6. 6
      app/views/locations/_location_filters.html.erb
  7. 2
      app/views/locations/index.html.erb
  8. 6
      app/views/logs/_log_filters.html.erb
  9. 13
      app/views/logs/_log_list.html.erb
  10. 2
      app/views/organisation_relationships/_managing_agent_list.erb
  11. 2
      app/views/organisation_relationships/_stock_owner_list.erb
  12. 2
      app/views/organisations/_organisation_list.html.erb
  13. 6
      app/views/schemes/_scheme_filters.html.erb
  14. 2
      app/views/schemes/_scheme_list.html.erb
  15. 7
      app/views/users/_user_filters.html.erb
  16. 2
      app/views/users/_user_list.html.erb
  17. 45
      spec/components/search_result_caption_component_spec.rb
  18. 6
      spec/features/lettings_log_spec.rb
  19. 4
      spec/features/organisation_spec.rb
  20. 6
      spec/features/sales_log_spec.rb
  21. 16
      spec/features/schemes_spec.rb
  22. 6
      spec/features/user_spec.rb
  23. 4
      spec/requests/lettings_logs_controller_spec.rb
  24. 4
      spec/requests/locations_controller_spec.rb
  25. 12
      spec/requests/organisation_relationships_controller_spec.rb
  26. 33
      spec/requests/organisations_controller_spec.rb
  27. 4
      spec/requests/sales_logs_controller_spec.rb
  28. 8
      spec/requests/schemes_controller_spec.rb
  29. 10
      spec/requests/users_controller_spec.rb

3
app/components/search_component.html.erb

@ -10,6 +10,7 @@
autocomplete: "off", autocomplete: "off",
class: "app-search__input" %> class: "app-search__input" %>
<%= f.govuk_submit "Search", classes: "app-search__button govuk-button--secondary" %> <%= f.govuk_submit "Search", classes: "app-search__button" %>
<%= govuk_button_link_to "Clear search", path(current_user), secondary: true, class: "app-search__button" %>
</div> </div>
<% end %> <% end %>

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 %>. <%= govuk_link_to("Clear search", path) %> <strong><%= count %></strong> <%= item_label.pluralize(count) %> matching search and filters<br>
<% elsif searched.present? %>
<strong><%= count %></strong> <%= item_label.pluralize(count) %> matching search<br>
<% elsif filters_count&.positive? %>
<strong><%= count %></strong> <%= item_label.pluralize(count) %> matching filters<br>
<% else %> <% else %>
<strong><%= count %></strong> total <%= item %> <strong><%= count %></strong> matching <%= item %>
<% end %> <% end %>
</span> </span>

6
app/components/search_result_caption_component.rb

@ -1,13 +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:, path:) 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
@path = path @filters_count = filters_count
super super
end end
end end

2
app/controllers/sessions_controller.rb

@ -3,7 +3,7 @@ class SessionsController < ApplicationController
session[session_name_for(params[:filter_type])] = "{}" session[session_name_for(params[:filter_type])] = "{}"
path_params = params[:path_params].presence || {} path_params = params[:path_params].presence || {}
redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id]) redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search])
end end
private private

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)]

6
app/views/locations/_location_filters.html.erb

@ -11,7 +11,7 @@
<%= filters_applied_text(@filter_type) %> <%= filters_applied_text(@filter_type) %>
</p> </p>
<p class="govuk-!-text-align-right govuk-grid-column-one-half"> <p class="govuk-!-text-align-right govuk-grid-column-one-half">
<%= reset_filters_link(@filter_type, { scheme_id: @scheme.id }) %> <%= reset_filters_link(@filter_type, { scheme_id: @scheme.id, search: request.params["search"] }.compact) %>
</p> </p>
</div> </div>
@ -23,6 +23,10 @@
category: "status", category: "status",
} %> } %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %>
<% end %> <% end %>
</div> </div>

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", path: request.path)) %> <%= 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| %>

6
app/views/logs/_log_filters.html.erb

@ -12,7 +12,7 @@
<%= filters_applied_text(@filter_type) %> <%= filters_applied_text(@filter_type) %>
</p> </p>
<p class="govuk-!-text-align-right govuk-grid-column-one-half"> <p class="govuk-!-text-align-right govuk-grid-column-one-half">
<%= reset_filters_link(@filter_type) %> <%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %>
</p> </p>
</div> </div>
<% if bulk_upload_options(@bulk_upload).present? %> <% if bulk_upload_options(@bulk_upload).present? %>
@ -113,6 +113,10 @@
} %> } %>
<% end %> <% end %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %>
<% end %> <% end %>
</div> </div>

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

@ -1,19 +1,22 @@
<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", path: request.path)) %> <%= 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? %>
<%= govuk_link_to "Download (CSV, codes only)", csv_codes_only_download_url, type: "text/csv", class: "govuk-!-margin-right-4" %> <%= govuk_link_to "Download (CSV, codes only)", csv_codes_only_download_url, type: "text/csv", class: "govuk-!-margin-right-4" %>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
<div class="govuk-grid-column-one-quarter govuk-!-text-align-right"> <div class="govuk-grid-column-one-quarter govuk-!-text-align-right">
<% if searched || applied_filters_count(@filter_type).positive? %>
<br>
<% end %>
<% if logs&.any? && (display_delete_logs?(@current_user, searched, filter_type) || in_organisations_tab?) %> <% if logs&.any? && (display_delete_logs?(@current_user, searched, filter_type) || in_organisations_tab?) %>
<%= govuk_link_to "Delete logs", delete_logs_path, class: "app-!-colour-red" %> <%= govuk_link_to "Delete logs", delete_logs_path, class: "app-!-colour-red" %>
<% end %> <% end %>
</div> </div>
</div> </div>
</h2> </h2>
<% logs.map do |log| %> <% logs.map do |log| %>

2
app/views/organisation_relationships/_managing_agent_list.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: "agents", path: request.path)) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "agents", filters_count: 0)) %>
<% end %> <% end %>
<% @managing_agents.each do |managing_agent| %> <% @managing_agents.each do |managing_agent| %>
<%= table.body do |body| %> <%= table.body do |body| %>

2
app/views/organisation_relationships/_stock_owner_list.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: "stock owners", path: request.path)) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "stock owners", filters_count: 0)) %>
<% end %> <% end %>
<% @stock_owners.each do |stock_owner| %> <% @stock_owners.each do |stock_owner| %>
<%= table.body do |body| %> <%= table.body do |body| %>

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", path: request.path)) %> <%= 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| %>

6
app/views/schemes/_scheme_filters.html.erb

@ -11,7 +11,7 @@
<%= filters_applied_text(@filter_type) %> <%= filters_applied_text(@filter_type) %>
</p> </p>
<p class="govuk-!-text-align-right govuk-grid-column-one-half"> <p class="govuk-!-text-align-right govuk-grid-column-one-half">
<%= reset_filters_link(@filter_type) %> <%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %>
</p> </p>
</div> </div>
@ -43,6 +43,10 @@
} %> } %>
<% end %> <% end %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %>
<% end %> <% end %>
</div> </div>

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", path: request.path)) %> <%= 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| %>

7
app/views/users/_user_filters.html.erb

@ -11,7 +11,7 @@
<%= filters_applied_text(@filter_type) %> <%= filters_applied_text(@filter_type) %>
</p> </p>
<p class="govuk-!-text-align-right govuk-grid-column-one-half"> <p class="govuk-!-text-align-right govuk-grid-column-one-half">
<%= reset_filters_link(@filter_type) %> <%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %>
</p> </p>
</div> </div>
@ -22,6 +22,11 @@
label: "Status", label: "Status",
category: "status", category: "status",
} %> } %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %>
<% end %> <% end %>
</div> </div>

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", path: request.path)) %> <%= 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" %>

45
spec/components/search_result_caption_component_spec.rb

@ -6,20 +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(:path) { "path" } 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<br>\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}. <a class=\"govuk-link\" href=\"path\">Clear search</a>\n</span>\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<br>\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<br>\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<br>\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<br>\n</span>\n")
end end
end end
end end

6
spec/features/lettings_log_spec.rb

@ -79,7 +79,7 @@ RSpec.describe "Lettings Log Features" do
context "when no filters are selected" do context "when no filters are selected" do
it "displays the filters component with no clear button" do it "displays the filters component with no clear button" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs")
end end
end end
@ -97,7 +97,7 @@ RSpec.describe "Lettings Log Features" do
it "displays the filters component with a correct count and clear button" do it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("5 filters applied") expect(page).to have_content("5 filters applied")
expect(page).to have_content("Clear") expect(page).to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs")
end end
context "when clearing the filters" do context "when clearing the filters" do
@ -107,7 +107,7 @@ RSpec.describe "Lettings Log Features" do
it "clears the filters and displays the filter component as before" do it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs")
end end
end end
end end

4
spec/features/organisation_spec.rb

@ -189,7 +189,7 @@ RSpec.describe "User Features" do
end end
it "has correct page details" do it "has correct page details" do
expect(page).to have_content("#{number_of_lettings_logs} total logs") expect(page).to have_content("#{number_of_lettings_logs} matching logs")
organisation.lettings_logs.map(&:id).each do |lettings_log_id| organisation.lettings_logs.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}"
end end
@ -237,7 +237,7 @@ RSpec.describe "User Features" do
end end
it "can filter sales logs" do it "can filter sales logs" do
expect(page).to have_content("#{number_of_sales_logs} total logs") expect(page).to have_content("#{number_of_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

6
spec/features/sales_log_spec.rb

@ -108,7 +108,7 @@ RSpec.describe "Sales Log Features" do
context "when no filters are selected" do context "when no filters are selected" do
it "displays the filters component with no clear button" do it "displays the filters component with no clear button" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=sales_logs")
end end
end end
@ -122,7 +122,7 @@ RSpec.describe "Sales Log Features" do
it "displays the filters component with a correct count and clear button" do it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("3 filters applied") expect(page).to have_content("3 filters applied")
expect(page).to have_content("Clear") expect(page).to have_link("Clear", href: "/clear-filters?filter_type=sales_logs")
end end
context "when clearing the filters" do context "when clearing the filters" do
@ -132,7 +132,7 @@ RSpec.describe "Sales Log Features" do
it "clears the filters and displays the filter component as before" do it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=sales_logs")
end end
end end
end end

16
spec/features/schemes_spec.rb

@ -68,7 +68,7 @@ RSpec.describe "Schemes scheme Features" do
context "when no filters are selected" do context "when no filters are selected" do
it "displays the filters component with no clear button" do it "displays the filters component with no clear button" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=schemes")
end end
end end
@ -81,7 +81,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays the filters component with a correct count and clear button" do it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("2 filters applied") expect(page).to have_content("2 filters applied")
expect(page).to have_content("Clear") expect(page).to have_link("Clear", href: "/clear-filters?filter_type=schemes")
end end
context "when clearing the filters" do context "when clearing the filters" do
@ -91,7 +91,7 @@ RSpec.describe "Schemes scheme Features" do
it "clears the filters and displays the filter component as before" do it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=schemes")
end end
end end
end end
@ -292,7 +292,7 @@ RSpec.describe "Schemes scheme Features" do
context "when no filters are selected" do context "when no filters are selected" do
it "displays the filters component with no clear button" do it "displays the filters component with no clear button" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/)
end end
end end
@ -305,7 +305,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays the filters component with a correct count and clear button" do it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("2 filters applied") expect(page).to have_content("2 filters applied")
expect(page).to have_content("Clear") expect(page).to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/)
end end
context "when clearing the filters" do context "when clearing the filters" do
@ -315,7 +315,7 @@ RSpec.describe "Schemes scheme Features" do
it "clears the filters and displays the filter component as before" do it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/)
end end
end end
end end
@ -572,7 +572,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays information about a single location" do it "displays information about a single location" do
expect(page).to have_content "Locations" expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} total location" expect(page).to have_content "#{scheme.locations.count} matching location"
end end
it "displays information about the first created location" do it "displays information about the first created location" do
@ -585,7 +585,7 @@ RSpec.describe "Schemes scheme Features" do
fill_in_and_save_second_location fill_in_and_save_second_location
click_button "Save and return to locations" click_button "Save and return to locations"
expect(page).to have_content "Locations" expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} total location" expect(page).to have_content "#{scheme.locations.count} matching location"
end end
it "displays information about newly created location" do it "displays information about newly created location" do

6
spec/features/user_spec.rb

@ -233,7 +233,7 @@ RSpec.describe "User Features" do
context "when no filters are selected" do context "when no filters are selected" do
it "displays the filters component with no clear button" do it "displays the filters component with no clear button" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=users")
end end
end end
@ -246,7 +246,7 @@ RSpec.describe "User Features" do
it "displays the filters component with a correct count and clear button" do it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("2 filters applied") expect(page).to have_content("2 filters applied")
expect(page).to have_content("Clear") expect(page).to have_link("Clear", href: "/clear-filters?filter_type=users")
end end
context "when clearing the filters" do context "when clearing the filters" do
@ -256,7 +256,7 @@ RSpec.describe "User Features" do
it "clears the filters and displays the filter component as before" do it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied") expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear") expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=users")
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

12
spec/requests/organisation_relationships_controller_spec.rb

@ -47,7 +47,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total stock owners") expect(page).to have_content("1 matching stock owners")
end end
context "when adding a stock owner" do context "when adding a stock owner" do
@ -113,7 +113,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total agents") expect(page).to have_content("1 matching agents")
end end
end end
@ -285,7 +285,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total stock owners") expect(page).to have_content("1 matching stock owners")
end end
end end
@ -421,7 +421,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total agents") expect(page).to have_content("1 matching agents")
end end
end end
@ -587,7 +587,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total stock owners") expect(page).to have_content("1 matching stock owners")
end end
context "when adding a stock owner" do context "when adding a stock owner" do
@ -637,7 +637,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total agents") expect(page).to have_content("1 matching agents")
end end
it "shows remove link(s)" do it "shows remove link(s)" do

33
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}"
@ -784,6 +784,11 @@ RSpec.describe OrganisationsController, type: :request do
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 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end end
it "has search term in the search box" do
get "/organisations/#{organisation.id}/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {}
expect(page).to have_field("search", with: log_to_search.id.to_s)
end
it "shows lettings logs matching the id" do it "shows lettings logs matching the id" do
get "/organisations/#{organisation.id}/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {} get "/organisations/#{organisation.id}/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {}
expect(page).to have_link(log_to_search.id.to_s) expect(page).to have_link(log_to_search.id.to_s)
@ -894,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
@ -1028,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
@ -1048,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
@ -1070,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
@ -1098,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
@ -1155,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
@ -1189,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
@ -1205,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