From 07e3bad429b934e15cd5cfdbda545fd0d530920e Mon Sep 17 00:00:00 2001
From: Ted-U <92022120+Ted-U@users.noreply.github.com>
Date: Fri, 6 May 2022 12:17:19 +0100
Subject: [PATCH] Radio button on log filter is now preset to "All" (#552)
* Radio button on log filter is now preset to "All"
* lint fixes
* removed instance @ variable
---
app/helpers/filters_helper.rb | 1 +
app/views/case_logs/_log_filters.erb | 3 ++-
spec/helpers/filters_helper_spec.rb | 13 +++++++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb
index f448bbeb5..c142b6e6d 100644
--- a/app/helpers/filters_helper.rb
+++ b/app/helpers/filters_helper.rb
@@ -3,6 +3,7 @@ module FiltersHelper
return false unless session[:case_logs_filters]
selected_filters = JSON.parse(session[:case_logs_filters])
+ return true if selected_filters.blank? && filter == "user" && value == :all
return false if selected_filters[filter].blank?
selected_filters[filter].include?(value.to_s)
diff --git a/app/views/case_logs/_log_filters.erb b/app/views/case_logs/_log_filters.erb
index 893a8607d..4e294c81e 100644
--- a/app/views/case_logs/_log_filters.erb
+++ b/app/views/case_logs/_log_filters.erb
@@ -6,9 +6,10 @@
<%= form_with url: "/logs", html: { method: :get } do |f| %>
<% years = {"2021": "2021/22", "2022": "2022/23"} %>
+ <% all_or_yours = {"all": "All", "yours": "Yours"} %>
<%= render partial: "filters/checkbox_filter", locals: { f: f, options: years, label: "Collection year", category: "years" } %>
<%= render partial: "filters/checkbox_filter", locals: { f: f, options: status_filters, label: "Status", category: "status" } %>
- <%= render partial: "filters/radio_filter", locals: { f: f, options: {"all": "All", "yours": "Yours"}, label: "Logs", category: "user" } %>
+ <%= render partial: "filters/radio_filter", locals: { f: f, options: all_or_yours, label: "Logs", category: "user", } %>
<%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %>
<% end %>
diff --git a/spec/helpers/filters_helper_spec.rb b/spec/helpers/filters_helper_spec.rb
index 739b2e937..296e336a4 100644
--- a/spec/helpers/filters_helper_spec.rb
+++ b/spec/helpers/filters_helper_spec.rb
@@ -9,6 +9,19 @@ RSpec.describe FiltersHelper do
end
end
+ context "when the filter is the user filter but session filters is empty" do
+ before do
+ session[:case_logs_filters] = {}.to_json
+ end
+
+ context "when looking at the all value" do
+ it "returns true if no filters have been set yet" do
+ expect(filter_selected?("user", :all)).to be_truthy
+ expect(filter_selected?("user", :yours)).to be_falsey
+ end
+ end
+ end
+
context "when one filter is selected" do
before do
session[:case_logs_filters] = { "status": "in_progress" }.to_json