From 35d94642fbe4e2f2525ae02ccadcd5c7abd08ef5 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 21 Jul 2023 12:04:23 +0100 Subject: [PATCH] Add status filter to schemes pages --- app/helpers/filters_helper.rb | 10 +++++++ app/views/organisations/schemes.html.erb | 33 ++++++++++++---------- app/views/schemes/_scheme_filters.html.erb | 29 +++++++++++++++++++ app/views/schemes/index.html.erb | 14 +++++---- spec/features/schemes_spec.rb | 33 ++++++++++++++++++++++ 5 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 app/views/schemes/_scheme_filters.html.erb diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 7ac1277bd..a9d536996 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -46,6 +46,16 @@ module FiltersHelper }.freeze end + def scheme_status_filters + { + "incomplete" => "Incomplete", + "active" => "Active", + "deactivating_soon" => "Deactivating soon", + "reactivating_soon" => "Reactivating soon", + "deactivated" => "Deactivated", + }.freeze + end + def selected_option(filter, filter_type) return false unless session[session_name_for(filter_type)] diff --git a/app/views/organisations/schemes.html.erb b/app/views/organisations/schemes.html.erb index 6dac0f3a7..20fc40886 100644 --- a/app/views/organisations/schemes.html.erb +++ b/app/views/organisations/schemes.html.erb @@ -11,21 +11,24 @@ ) %>

Supported housing schemes

<% end %> +
+ <% if SchemePolicy.new(current_user, nil).create? %> + <%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %> + <% end %> + + <%= govuk_details( + classes: "govuk-!-width-two-thirds", + summary_text: "What is a supported housing scheme?", + text: "A supported housing scheme (also known as a ‘supported housing service’) provides shared or self-contained housing for a particular client group, for example younger or vulnerable people. A single scheme can contain multiple units, for example bedrooms in shared houses or a bungalow with 3 bedrooms.", + ) %> + <%= render partial: "schemes/scheme_filters" %> +
+ <%= render SearchComponent.new(current_user:, search_label: "Search by scheme name, code, postcode or location name", value: @searched) %> -<% if SchemePolicy.new(current_user, nil).create? %> - <%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %> -<% end %> - -<%= govuk_details( - classes: "govuk-!-width-two-thirds", - summary_text: "What is a supported housing scheme?", - text: "A supported housing scheme (also known as a ‘supported housing service’) provides shared or self-contained housing for a particular client group, for example younger or vulnerable people. A single scheme can contain multiple units, for example bedrooms in shared houses or a bungalow with 3 bedrooms.", -) %> - -<%= render SearchComponent.new(current_user:, search_label: "Search by scheme name, code, postcode or location name", value: @searched) %> - -
+
-<%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> -<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "schemes" } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "schemes" } %> +
+
diff --git a/app/views/schemes/_scheme_filters.html.erb b/app/views/schemes/_scheme_filters.html.erb new file mode 100644 index 000000000..086d6fd84 --- /dev/null +++ b/app/views/schemes/_scheme_filters.html.erb @@ -0,0 +1,29 @@ +
+
+
+

Filters

+
+ +
+ <%= form_with url: schemes_path, html: { method: :get } do |f| %> +
+

+ <%= filters_applied_text(@filter_type) %> +

+

+ <%= reset_filters_link(@filter_type) %> +

+
+ + <%= render partial: "filters/checkbox_filter", + locals: { + f:, + options: scheme_status_filters, + label: "Status", + category: "status", + } %> + <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> + <% end %> +
+
+
diff --git a/app/views/schemes/index.html.erb b/app/views/schemes/index.html.erb index fa900ca8d..a1c2041ff 100644 --- a/app/views/schemes/index.html.erb +++ b/app/views/schemes/index.html.erb @@ -8,11 +8,15 @@ <% if SchemePolicy.new(current_user, nil).create? %> <%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %> <% end %> +
+ <%= render partial: "schemes/scheme_filters" %> +
+ <%= render SearchComponent.new(current_user:, search_label: "Search by scheme name, code, postcode or location name", value: @searched) %> -<%= render SearchComponent.new(current_user:, search_label: "Search by scheme name, code, postcode or location name", value: @searched) %> +
-
+ <%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> -<%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> - -<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "schemes" } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "schemes" } %> +
+
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 886a71176..c88b831ec 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -63,6 +63,39 @@ RSpec.describe "Schemes scheme Features" do end end end + + context "when filtering schemes" do + context "when no filters are selected" do + it "displays the filters component with no clear button" do + expect(page).to have_content("No filters applied") + expect(page).not_to have_content("Clear") + end + end + + context "when I have selected filters" do + before do + check("Active") + check("Incomplete") + click_button("Apply filters") + end + + 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("Clear") + end + + context "when clearing the filters" do + before do + click_link("Clear") + end + + it "clears the filters and displays the filter component as before" do + expect(page).to have_content("No filters applied") + expect(page).not_to have_content("Clear") + end + end + end + end end end end