From 1d85822bc8587f3440372db07c0f03f723ca8d8d Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Wed, 15 May 2024 10:36:04 +0100 Subject: [PATCH] amend presenter and associated calls from view, tests, to ensure support user always sees sales data --- app/presenters/homepage_presenter.rb | 18 +++++++++--------- app/views/home/index.html.erb | 6 +++--- spec/factories/user.rb | 3 +++ spec/presenters/homepage_presenter_spec.rb | 8 ++++++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/presenters/homepage_presenter.rb b/app/presenters/homepage_presenter.rb index e05045e23..9fe388308 100644 --- a/app/presenters/homepage_presenter.rb +++ b/app/presenters/homepage_presenter.rb @@ -5,18 +5,18 @@ class HomepagePresenter def initialize(user) @user = user - @organisation_logs_sales = organisation_has_ever_logged_sales? + @display_sales = should_display_sales? @in_crossover_period = FormHandler.instance.in_crossover_period? @current_year = FormHandler.instance.current_lettings_form.start_date.year @current_year_in_progress_lettings_data = data_box_data(:lettings, @current_year, :in_progress) @current_year_completed_lettings_data = data_box_data(:lettings, @current_year, :completed) - @current_year_in_progress_sales_data = data_box_data(:sales, @current_year, :in_progress) if organisation_logs_sales? - @current_year_completed_sales_data = data_box_data(:sales, @current_year, :completed) if organisation_logs_sales? + @current_year_in_progress_sales_data = data_box_data(:sales, @current_year, :in_progress) if display_sales? + @current_year_completed_sales_data = data_box_data(:sales, @current_year, :completed) if display_sales? @last_year = @current_year - 1 @last_year_in_progress_lettings_data = data_box_data(:lettings, @last_year, :in_progress) if in_crossover_period? @last_year_completed_lettings_data = data_box_data(:lettings, @last_year, :completed) - @last_year_in_progress_sales_data = data_box_data(:sales, @last_year, :in_progress) if in_crossover_period? && organisation_logs_sales? - @last_year_completed_sales_data = data_box_data(:sales, @last_year, :completed) if organisation_logs_sales? + @last_year_in_progress_sales_data = data_box_data(:sales, @last_year, :in_progress) if in_crossover_period? && display_sales? + @last_year_completed_sales_data = data_box_data(:sales, @last_year, :completed) if display_sales? if display_schemes? @incomplete_schemes_data = { count: @user.schemes.incomplete.count, @@ -36,8 +36,8 @@ class HomepagePresenter end end - def organisation_logs_sales? - @organisation_logs_sales + def display_sales? + @display_sales end def in_crossover_period? @@ -104,7 +104,7 @@ private .count end - def organisation_has_ever_logged_sales? - @user.organisation.sales_logs.exists? + def should_display_sales? + @user.support? || @user.organisation.sales_logs.exists? end end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 4ad19abc1..99f80a12b 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -12,7 +12,7 @@

<%= @homepage_presenter.subheading_for_last_year %>

- <% if @homepage_presenter.organisation_logs_sales? %> + <% if @homepage_presenter.display_sales? %> <%= render partial: "home/data_box_two_by_two", locals: { top_left_data_box: @homepage_presenter.last_year_in_progress_lettings_data, bottom_left_data_box: @homepage_presenter.last_year_completed_lettings_data, @@ -32,7 +32,7 @@

<%= @homepage_presenter.subheading_for_current_year %>

- <% if @homepage_presenter.organisation_logs_sales? %> + <% if @homepage_presenter.display_sales? %> <%= render partial: "home/data_box_two_by_two", locals: { top_left_data_box: @homepage_presenter.current_year_in_progress_lettings_data, bottom_left_data_box: @homepage_presenter.current_year_completed_lettings_data, @@ -64,7 +64,7 @@
<%= render partial: "home/blue_box_link", locals: { text: "View all lettings", path: clear_filters_path(filter_type: "lettings_logs") } %>
- <% if @homepage_presenter.organisation_logs_sales? %> + <% if @homepage_presenter.display_sales? %>
<%= render partial: "home/blue_box_link", locals: { text: "View all sales", path: clear_filters_path(filter_type: "sales_logs") } %>
diff --git a/spec/factories/user.rb b/spec/factories/user.rb index f898c5504..f746a62ba 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -6,6 +6,9 @@ FactoryBot.define do organisation { association :organisation } role { "data_provider" } phone { "1234512345123" } + trait :data_provider do + role { "data_provider" } + end trait :data_coordinator do role { "data_coordinator" } end diff --git a/spec/presenters/homepage_presenter_spec.rb b/spec/presenters/homepage_presenter_spec.rb index 1251432c1..e717d3fb3 100644 --- a/spec/presenters/homepage_presenter_spec.rb +++ b/spec/presenters/homepage_presenter_spec.rb @@ -23,6 +23,10 @@ RSpec.describe HomepagePresenter do it "returns that schemes should be displayed" do expect(presenter.display_schemes?).to be true end + + it "returns that sales logs should be displayed" do + expect(presenter.display_sales?).to be true + end end context "when the user is a data coordinator" do @@ -51,7 +55,7 @@ RSpec.describe HomepagePresenter do context "when the user's organisation has never submitted sales logs" do it "shows the user's organisation does not log sales" do - expect(presenter.organisation_logs_sales?).to be false + expect(presenter.display_sales?).to be false end context "when in the crossover period" do @@ -89,7 +93,7 @@ RSpec.describe HomepagePresenter do end it "shows the user's organisation logs sales" do - expect(presenter.organisation_logs_sales?).to be true + expect(presenter.display_sales?).to be true end context "when in the crossover period" do