Browse Source

Set checked status of filters correctly

pull/522/head
baarkerlounger 3 years ago
parent
commit
06fa37002e
  1. 2
      app/helpers/filters_helper.rb
  2. 30
      spec/helpers/filters_helper_spec.rb

2
app/helpers/filters_helper.rb

@ -4,6 +4,8 @@ module FiltersHelper
selected_filters = JSON.parse(session[:case_logs_filters])
return true if selected_filters.blank? && filter == "user" && value == :all
return true if selected_filters.blank? && filter == "organisation_select" && value == :all
return true if selected_filters["organisation"].present? && filter == "organisation_select" && value == :specific_org
return false if selected_filters[filter].blank?
selected_filters[filter].include?(value.to_s)

30
spec/helpers/filters_helper_spec.rb

@ -16,8 +16,8 @@ RSpec.describe FiltersHelper do
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
expect(filter_selected?("user", :all)).to be true
expect(filter_selected?("user", :yours)).to be false
end
end
end
@ -28,11 +28,33 @@ RSpec.describe FiltersHelper do
end
it "returns false for non selected filters" do
expect(filter_selected?("status", "completed")).to be_falsey
expect(filter_selected?("status", "completed")).to be false
end
it "returns true for selected filter" do
expect(filter_selected?("status", "in_progress")).to be_truthy
expect(filter_selected?("status", "in_progress")).to be true
end
end
context "when support user is using the organisation filter" do
before do
session[:case_logs_filters] = { "organisation": "1" }.to_json
end
it "returns true for the parent organisation_select filter" do
expect(filter_selected?("organisation_select", :specific_org)).to be true
expect(filter_selected?("organisation_select", :all)).to be false
end
end
context "when support user has not set the organisation_select filter" do
before do
session[:case_logs_filters] = {}.to_json
end
it "defaults to all organisations" do
expect(filter_selected?("organisation_select", :all)).to be true
expect(filter_selected?("organisation_select", :specific_org)).to be false
end
end
end

Loading…
Cancel
Save