From 52e9d73594b8e918eaa8503ece1f0a9d76b6556a Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 12 Jul 2023 09:41:28 +0100 Subject: [PATCH] feat: add more tests --- spec/features/lettings_log_spec.rb | 45 +++++++++++++++++++++++++++++ spec/helpers/filters_helper_spec.rb | 43 ++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb index 993c7e82c..f74091f5b 100644 --- a/spec/features/lettings_log_spec.rb +++ b/spec/features/lettings_log_spec.rb @@ -57,6 +57,51 @@ RSpec.describe "Lettings Log Features" do end end + context "when filtering logs" do + let(:user) { create(:user, last_sign_in_at: Time.zone.now) } + + context "when I am signed in" do + before do + visit("/lettings-logs") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: user.password) + click_button("Sign in") + end + + 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("Not started") + check("In progress") + choose("Yours") + click_button("Apply filters") + end + + 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("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 + context "when the signed is user is a Support user" do let(:organisation) { create(:organisation, name: "User org") } let(:support_user) { create(:user, :support, last_sign_in_at: Time.zone.now, organisation:) } diff --git a/spec/helpers/filters_helper_spec.rb b/spec/helpers/filters_helper_spec.rb index 622fd71f8..65d0c2c6b 100644 --- a/spec/helpers/filters_helper_spec.rb +++ b/spec/helpers/filters_helper_spec.rb @@ -132,7 +132,7 @@ RSpec.describe FiltersHelper do end end - context "when a range of filters are applied" do + context "when a range of filters is applied" do let(:filters) do { "user" => "all", @@ -204,4 +204,45 @@ RSpec.describe FiltersHelper do ) end end + + describe "#filters_applied_text" do + let(:filter_type) { "lettings_logs" } + let(:result) { filters_applied_text(filter_type) } + let(:serialised_filters) { filters&.to_json } + let(:filters) { nil } + + before do + session[:lettings_logs_filters] = serialised_filters if serialised_filters + end + + context "when no filters are applied" do + let(:filters) do + { + "user" => "all", + "status" => [""], + "years" => [""], + "organisation" => "all", + } + end + + it "returns the correct filters count" do + expect(result).to eq "No filters applied" + end + end + + context "when a range of filters is applied" do + let(:filters) do + { + "user" => "all", + "status" => %w[in_progress completed], + "years" => [""], + "organisation" => 2, + } + end + + it "returns the correct filters count" do + expect(result).to eq "3 filters applied" + end + end + end end