Show either investments header or results summary

We were showing the header when there were no search terms but there
were advanced search filters, unlike what we do for debates and
proposals. Besides, we were already hiding the header when there were
search terms, so it makes sense to hide it when using the advanced
search too.

We're using the `@search_terms` and `@advanced_search_terms` instance
variables in order to be consistent with what we do in the debates and
proposals sections.
This commit is contained in:
Javi Martín
2022-04-11 15:23:30 +02:00
parent 1c93a3cebb
commit 2684fc70d3
2 changed files with 22 additions and 8 deletions

View File

@@ -16,17 +16,14 @@
<% end %> <% end %>
<main id="budget-investments-main"> <main id="budget-investments-main">
<% if @search_terms || @advanced_search_terms %>
<% unless params[:search].present? %>
<%= render "/budgets/investments/header" %>
<% end %>
<% if params[:search].present? || params[:advanced_search].present? %>
<%= render Shared::SearchResultsSummaryComponent.new( <%= render Shared::SearchResultsSummaryComponent.new(
results: @investments, results: @investments,
search_terms: params[:search], search_terms: @search_terms,
advanced_search_terms: params[:advanced_search] advanced_search_terms: @advanced_search_terms
) %> ) %>
<% else %>
<%= render "/budgets/investments/header" %>
<% end %> <% end %>
<div class="row"> <div class="row">

View File

@@ -219,6 +219,23 @@ describe "Budget Investments" do
expect(page).not_to have_content "Feasible health" expect(page).not_to have_content "Feasible health"
expect(page).not_to have_content "Unfeasible health" expect(page).not_to have_content "Unfeasible health"
end end
scenario "Advanced search without search terms" do
create(:budget_heading, group: heading.group)
create(:budget_investment, heading: heading, title: "Old thing", created_at: 2.years.ago)
create(:budget_investment, heading: heading, title: "Newest thing", created_at: 1.hour.ago)
visit budget_investments_path(budget, heading: heading)
click_button "Advanced search"
select "Last year", from: "By date"
click_button "Filter"
expect(page).to have_content "There is 1 investment"
expect(page).to have_content "Newest thing"
expect(page).not_to have_content "Old thing"
within("main") { expect(page).not_to have_content "Participatory budgeting" }
end
end end
context("Filters") do context("Filters") do