Browse Source

amend presenter and associated calls from view, tests, to ensure support user always sees sales data

pull/2408/head
Arthur Campbell 8 months ago
parent
commit
1d85822bc8
  1. 18
      app/presenters/homepage_presenter.rb
  2. 6
      app/views/home/index.html.erb
  3. 3
      spec/factories/user.rb
  4. 8
      spec/presenters/homepage_presenter_spec.rb

18
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

6
app/views/home/index.html.erb

@ -12,7 +12,7 @@
<div class="app-data-box-group">
<h2 class="govuk-heading-m govuk-!-margin-bottom-2"><%= @homepage_presenter.subheading_for_last_year %></h2>
<div class="app-data-box-group-row">
<% 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 @@
<div class="app-data-box-group">
<h2 class="govuk-heading-m govuk-!-margin-bottom-2"><%= @homepage_presenter.subheading_for_current_year %></h2>
<div class="app-data-box-group-row">
<% 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 @@
<div class="app-data-box-one-half">
<%= render partial: "home/blue_box_link", locals: { text: "View all lettings", path: clear_filters_path(filter_type: "lettings_logs") } %>
</div>
<% if @homepage_presenter.organisation_logs_sales? %>
<% if @homepage_presenter.display_sales? %>
<div class="app-data-box-one-half">
<%= render partial: "home/blue_box_link", locals: { text: "View all sales", path: clear_filters_path(filter_type: "sales_logs") } %>
</div>

3
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

8
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

Loading…
Cancel
Save