From 1feecfafeb7283e4da070f08a40828e427855a40 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 20 Oct 2023 15:50:02 +0100 Subject: [PATCH] feat: add needstype test and slight refactor --- spec/features/organisation_spec.rb | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index 15e6642d1..dc4f6dc39 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -126,7 +126,8 @@ RSpec.describe "User Features" do context "when viewing lettings logs for specific organisation" do let(:first_log) { organisation.lettings_logs.first } let!(:log_to_search) { FactoryBot.create(:lettings_log, created_by: user) } - let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, created_by: user) } + let!(:other_general_needs_logs) { FactoryBot.create_list(:lettings_log, 4, created_by: user, needstype: 1) } + let!(:other_supported_housing_logs) { FactoryBot.create_list(:lettings_log, 4, created_by: user, needstype: 2) } let(:number_of_lettings_logs) { LettingsLog.count } before do @@ -148,7 +149,7 @@ RSpec.describe "User Features" do context "when searching for specific logs" do it "displays the logs belonging to the same organisation" do expect(page).to have_content(log_to_search.id) - other_logs.each do |log| + (other_general_needs_logs + other_supported_housing_logs).each do |log| expect(page).to have_content(log.id) end end @@ -168,7 +169,7 @@ RSpec.describe "User Features" do it "displays log matching the log ID" do expect(page).to have_link(log_to_search.id.to_s) - other_logs.each do |log| + (other_general_needs_logs + other_supported_housing_logs).each do |log| expect(page).not_to have_link(log.id.to_s) end end @@ -187,16 +188,32 @@ RSpec.describe "User Features" do end end - it "can filter lettings logs" do + it "has correct page details" do expect(page).to have_content("#{number_of_lettings_logs} total logs") organisation.lettings_logs.map(&:id).each do |lettings_log_id| expect(page).to have_link lettings_log_id.to_s, href: "/lettings-logs/#{lettings_log_id}" end + end + + it "can filter lettings logs by year" do check("years-2021-field") click_button("Apply filters") - expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2021&status[]=&assigned_to=all&user=&owning_organisation_select=all&owning_organisation=&managing_organisation_select=all&managing_organisation=") + expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2021&status[]=&needstypes[]=&assigned_to=all&user=&owning_organisation_select=all&owning_organisation=&managing_organisation_select=all&managing_organisation=") expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}" end + + it "can filter lettings logs by needstype" do + check("needstypes-1-field") + click_button("Apply filters") + expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&status[]=&needstypes[]=&needstypes[]=1&assigned_to=all&user=&owning_organisation_select=all&owning_organisation=&managing_organisation_select=all&managing_organisation=") + other_general_needs_logs.each do |general_needs_log| + expect(page).to have_link general_needs_log.id.to_s, href: "/lettings-logs/#{general_needs_log.id}" + end + other_supported_housing_logs.each do |supported_housing_log| + expect(page).not_to have_link supported_housing_log.id.to_s, href: "/lettings-logs/#{supported_housing_log.id}" + end + + end end context "when viewing sales logs for specific organisation" do