From c89f98600cedd8a1105770cb57cee46786e5a765 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 23 Feb 2024 12:15:51 +0000 Subject: [PATCH] Link to in progress logs for open collections only --- app/helpers/home_helper.rb | 19 +++++---- spec/features/home_page_spec.rb | 73 +++++++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index bd03f9eca..4aeb18f4f 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -1,15 +1,17 @@ module HomeHelper def data_count(user, type) + years = FormHandler.instance.lettings_in_crossover_period? ? [current_collection_start_year, previous_collection_start_year] : [current_collection_start_year] + if user.data_provider? case type - when "lettings" then user.lettings_logs.where(created_by: user).where(status: %i[not_started in_progress]).count - when "sales" then user.sales_logs.where(created_by: user).where(status: %i[not_started in_progress]).count + when "lettings" then user.lettings_logs.where(created_by: user).where(status: %i[in_progress]).filter_by_years(years).count + when "sales" then user.sales_logs.where(created_by: user).where(status: %i[in_progress]).filter_by_years(years).count when "misc" then user.lettings_logs.completed.where(created_by: user).count end else case type - when "lettings" then user.lettings_logs.where(status: %i[not_started in_progress]).count - when "sales" then user.sales_logs.where(status: %i[not_started in_progress]).count + when "lettings" then user.lettings_logs.where(status: %i[in_progress]).filter_by_years(years).count + when "sales" then user.sales_logs.where(status: %i[in_progress]).filter_by_years(years).count when "schemes" then user.schemes.incomplete.count end end @@ -31,16 +33,17 @@ module HomeHelper end def data_path(user, type) + years = FormHandler.instance.lettings_in_crossover_period? ? [current_collection_start_year, previous_collection_start_year] : [current_collection_start_year] if user.data_provider? case type - when "lettings" then lettings_logs_path(status: %i[not_started in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all") - when "sales" then sales_logs_path(status: %i[not_started in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all") + when "lettings" then lettings_logs_path(status: %i[in_progress], assigned_to: "you", years:, owning_organisation_select: "all", managing_organisation_select: "all") + when "sales" then sales_logs_path(status: %i[in_progress], assigned_to: "you", years:, owning_organisation_select: "all", managing_organisation_select: "all") when "misc" then lettings_logs_path(status: [:completed], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all") end else case type - when "lettings" then lettings_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all") - when "sales" then sales_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all") + when "lettings" then lettings_logs_path(status: %i[in_progress], assigned_to: "all", years:, owning_organisation_select: "all", managing_organisation_select: "all") + when "sales" then sales_logs_path(status: %i[in_progress], assigned_to: "all", years:, owning_organisation_select: "all", managing_organisation_select: "all") when "schemes" then schemes_path(status: [:incomplete], owning_organisation_select: "all") end end diff --git a/spec/features/home_page_spec.rb b/spec/features/home_page_spec.rb index 355c7b2b2..1477a10df 100644 --- a/spec/features/home_page_spec.rb +++ b/spec/features/home_page_spec.rb @@ -130,6 +130,7 @@ RSpec.describe "Home Page Features" do create_list(:lettings_log, 2, :in_progress, owning_organisation: user.organisation) create_list(:lettings_log, 4, :completed, owning_organisation: user.organisation, created_by: user) create_list(:lettings_log, 2, :completed) + create_list(:lettings_log, 2, :not_started) sign_in user visit(root_path) end @@ -144,16 +145,58 @@ RSpec.describe "Home Page Features" do before do create_list(:sales_log, 5, :in_progress, owning_organisation: user.organisation, created_by: user) create_list(:sales_log, 3, :completed, owning_organisation: user.organisation, created_by: user) + create_list(:sales_log, 2, :not_started) visit(root_path) end - it "displays correct data boxes, counts and links" do - data_boxes = page.find_all(class: "app-data-box-one-half") - expect(data_boxes.count).to eq(2) - expect(data_boxes[0].all("a").map(&:text)).to eq(["6", "Your lettings in progress", "View all lettings"]) - expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[not_started in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[not_started in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) - expect(data_boxes[1].all("a").map(&:text)).to eq(["5", "Your sales in progress", "View all sales"]) - expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: %i[not_started in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: %i[not_started in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) + context "and it is not a crossover" do + before do + Timecop.freeze(Time.zone.local(2024, 1, 1)) + Singleton.__init__(FormHandler) + closed_period_in_progress_log = build(:lettings_log, :in_progress, owning_organisation: user.organisation, created_by: user, startdate: Time.zone.local(2022, 4, 1)) + closed_period_in_progress_log.save!(validate: false) + visit(root_path) + end + + after do + Timecop.return + Singleton.__init__(FormHandler) + end + + it "displays correct data boxes, counts and links" do + data_boxes = page.find_all(class: "app-data-box-one-half") + expect(data_boxes.count).to eq(2) + expect(data_boxes[0].all("a").map(&:text)).to eq(["6", "Your lettings in progress", "View all lettings"]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[1].all("a").map(&:text)).to eq(["5", "Your sales in progress", "View all sales"]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) + end + end + + context "and it is a crossover" do + before do + Timecop.freeze(Time.zone.local(2024, 4, 1)) + Singleton.__init__(FormHandler) + closed_period_in_progress_log = build(:lettings_log, :in_progress, owning_organisation: user.organisation, created_by: user, startdate: Time.zone.local(2022, 4, 1)) + closed_period_in_progress_log.save!(validate: false) + sign_in user + visit(root_path) + end + + after do + Timecop.return + Singleton.__init__(FormHandler) + end + + it "displays correct data boxes, counts and links" do + data_boxes = page.find_all(class: "app-data-box-one-half") + + expect(data_boxes.count).to eq(2) + expect(data_boxes[0].all("a").map(&:text)).to eq(["6", "Your lettings in progress", "View all lettings"]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2024 2023], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2024 2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[1].all("a").map(&:text)).to eq(["5", "Your sales in progress", "View all sales"]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2024 2023], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2024 2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) + end end end @@ -166,7 +209,7 @@ RSpec.describe "Home Page Features" do data_boxes = page.find_all(class: "app-data-box-one-half") expect(data_boxes.count).to eq(2) expect(data_boxes[0].all("a").map(&:text)).to eq(["6", "Your lettings in progress", "View all lettings"]) - expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[not_started in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[not_started in_progress], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[in_progress], assigned_to: "you", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) expect(data_boxes[1].all("a").map(&:text)).to eq(["4", "Your completed lettings", "View all schemes"]) expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: [:completed], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: [:completed], assigned_to: "you", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "schemes")]) end @@ -179,6 +222,7 @@ RSpec.describe "Home Page Features" do create_list(:lettings_log, 2, :in_progress, owning_organisation: user.organisation, created_by: user) create_list(:lettings_log, 4, :completed, owning_organisation: user.organisation) create_list(:lettings_log, 2, :completed) + create_list(:lettings_log, 2, :not_started) create_list(:scheme, 1, :incomplete, owning_organisation: user.organisation) sign_in user visit(root_path) @@ -196,6 +240,7 @@ RSpec.describe "Home Page Features" do before do create_list(:sales_log, 5, :in_progress, owning_organisation: user.organisation) create_list(:sales_log, 3, :completed, owning_organisation: user.organisation) + create_list(:sales_log, 2, :not_started) visit(root_path) end @@ -203,9 +248,9 @@ RSpec.describe "Home Page Features" do data_boxes = page.find_all(class: "app-data-box-one-third") expect(data_boxes.count).to eq(3) expect(data_boxes[0].all("a").map(&:text)).to eq(["8", "Lettings in progress", "View all lettings"]) - expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) expect(data_boxes[1].all("a").map(&:text)).to eq(["5", "Sales in progress", "View all sales"]) - expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) expect(data_boxes[2].all("a").map(&:text)).to eq(["1", "Incomplete schemes", "View all schemes"]) expect(data_boxes[2].all("a").map { |line| line["href"] }).to eq([schemes_path(status: [:incomplete], owning_organisation_select: "all"), schemes_path(status: [:incomplete], owning_organisation_select: "all"), clear_filters_path(filter_type: "schemes")]) end @@ -220,7 +265,7 @@ RSpec.describe "Home Page Features" do data_boxes = page.find_all(class: "app-data-box-one-half") expect(data_boxes.count).to eq(2) expect(data_boxes[0].all("a").map(&:text)).to eq(["8", "Lettings in progress", "View all lettings"]) - expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) expect(data_boxes[1].all("a").map(&:text)).to eq(["1", "Incomplete schemes", "View all schemes"]) expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([schemes_path(status: [:incomplete], owning_organisation_select: "all"), schemes_path(status: [:incomplete], owning_organisation_select: "all"), clear_filters_path(filter_type: "schemes")]) end @@ -237,8 +282,10 @@ RSpec.describe "Home Page Features" do before do create_list(:lettings_log, 2, :in_progress) create_list(:lettings_log, 1, :completed) + create_list(:lettings_log, 2, :not_started) create_list(:sales_log, 3, :in_progress) create_list(:sales_log, 1, :completed) + create_list(:sales_log, 2, :not_started) create_list(:scheme, 1, :incomplete) completed_scheme = create(:scheme) create(:location, scheme: completed_scheme) @@ -266,9 +313,9 @@ RSpec.describe "Home Page Features" do data_boxes = page.find_all(class: "app-data-box-one-third") expect(data_boxes.count).to eq(3) expect(data_boxes[0].all("a").map(&:text)).to eq(["2", "Lettings in progress", "View all lettings"]) - expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) + expect(data_boxes[0].all("a").map { |line| line["href"] }).to eq([lettings_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), lettings_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "lettings_logs")]) expect(data_boxes[1].all("a").map(&:text)).to eq(["3", "Sales in progress", "View all sales"]) - expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: %i[not_started in_progress], assigned_to: "all", years: [""], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) + expect(data_boxes[1].all("a").map { |line| line["href"] }).to eq([sales_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), sales_logs_path(status: %i[in_progress], assigned_to: "all", years: %w[2023], owning_organisation_select: "all", managing_organisation_select: "all"), clear_filters_path(filter_type: "sales_logs")]) expect(data_boxes[2].all("a").map(&:text)).to eq(["1", "Incomplete schemes", "View all schemes"]) expect(data_boxes[2].all("a").map { |line| line["href"] }).to eq([schemes_path(status: [:incomplete], owning_organisation_select: "all"), schemes_path(status: [:incomplete], owning_organisation_select: "all"), clear_filters_path(filter_type: "schemes")]) end