From 356d652db13de264e1debec9c76eb0a72af87bf7 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Wed, 10 Jul 2024 17:38:15 +0100 Subject: [PATCH] CLDC-3532: Make BU guidance back link depend on referrer (#2482) * CLDC-3532: Make BU guidance back link depend on referrer * Add tests for back_path * Add guidance to homepage * CLDC-3526: Update back_path --------- Co-authored-by: Kat --- .../bulk_upload_lettings_logs_controller.rb | 2 +- .../bulk_upload_sales_logs_controller.rb | 2 +- .../forms/bulk_upload_lettings/guidance.rb | 10 ++++- .../forms/bulk_upload_sales/guidance.rb | 10 ++++- .../forms/prepare_your_file_2023.html.erb | 2 +- .../forms/prepare_your_file_2024.html.erb | 2 +- .../forms/prepare_your_file_2023.html.erb | 2 +- .../forms/prepare_your_file_2024.html.erb | 2 +- .../layouts/_collection_resources.html.erb | 1 + app/views/start/guidance.html.erb | 2 +- .../bulk_upload_lettings/guidance_spec.rb | 43 +++++++++++++++++++ .../forms/bulk_upload_sales/guidance_spec.rb | 43 +++++++++++++++++++ 12 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 spec/models/forms/bulk_upload_lettings/guidance_spec.rb create mode 100644 spec/models/forms/bulk_upload_sales/guidance_spec.rb diff --git a/app/controllers/bulk_upload_lettings_logs_controller.rb b/app/controllers/bulk_upload_lettings_logs_controller.rb index 4ab636e7a..465bbc5f6 100644 --- a/app/controllers/bulk_upload_lettings_logs_controller.rb +++ b/app/controllers/bulk_upload_lettings_logs_controller.rb @@ -47,7 +47,7 @@ private when "prepare-your-file" Forms::BulkUploadLettings::PrepareYourFile.new(form_params) when "guidance" - Forms::BulkUploadLettings::Guidance.new(form_params) + Forms::BulkUploadLettings::Guidance.new(form_params.merge(referrer: params[:referrer])) when "needstype" Forms::BulkUploadLettings::Needstype.new(form_params) when "upload-your-file" diff --git a/app/controllers/bulk_upload_sales_logs_controller.rb b/app/controllers/bulk_upload_sales_logs_controller.rb index 18f1e89c8..56bd1d4de 100644 --- a/app/controllers/bulk_upload_sales_logs_controller.rb +++ b/app/controllers/bulk_upload_sales_logs_controller.rb @@ -47,7 +47,7 @@ private when "prepare-your-file" Forms::BulkUploadSales::PrepareYourFile.new(form_params) when "guidance" - Forms::BulkUploadSales::Guidance.new(form_params) + Forms::BulkUploadSales::Guidance.new(form_params.merge(referrer: params[:referrer])) when "upload-your-file" Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:)) when "checking-file" diff --git a/app/models/forms/bulk_upload_lettings/guidance.rb b/app/models/forms/bulk_upload_lettings/guidance.rb index 66683eb9b..b6cf5bf74 100644 --- a/app/models/forms/bulk_upload_lettings/guidance.rb +++ b/app/models/forms/bulk_upload_lettings/guidance.rb @@ -6,13 +6,21 @@ module Forms include Rails.application.routes.url_helpers attribute :year, :integer + attribute :referrer def view_path "bulk_upload_shared/guidance" end def back_path - bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: }) + case referrer + when "prepare-your-file" + bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: }) + when "home" + root_path + else + guidance_path + end end def lettings_legacy_template_path diff --git a/app/models/forms/bulk_upload_sales/guidance.rb b/app/models/forms/bulk_upload_sales/guidance.rb index 44987cd87..28ca6c3b5 100644 --- a/app/models/forms/bulk_upload_sales/guidance.rb +++ b/app/models/forms/bulk_upload_sales/guidance.rb @@ -6,13 +6,21 @@ module Forms include Rails.application.routes.url_helpers attribute :year, :integer + attribute :referrer def view_path "bulk_upload_shared/guidance" end def back_path - bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) + case referrer + when "prepare-your-file" + bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) + when "home" + root_path + else + guidance_path + end end def lettings_legacy_template_path diff --git a/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb b/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb index 41564c7b2..21d19dba8 100644 --- a/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb +++ b/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2023.html.erb @@ -9,7 +9,7 @@ Upload lettings logs in bulk (<%= @form.year_combo %>)

Prepare your file

-

<%= govuk_link_to "Read the full guidance", bulk_upload_lettings_log_path(id: "guidance", form: { year: @form.year }) %> before you start if you have not used bulk upload before.

+

<%= govuk_link_to "Read the full guidance", bulk_upload_lettings_log_path(id: "guidance", form: { year: @form.year }, referrer: "prepare-your-file") %> before you start if you have not used bulk upload before.

Download template

diff --git a/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2024.html.erb b/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2024.html.erb index 8bc375450..6413d70cb 100644 --- a/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2024.html.erb +++ b/app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2024.html.erb @@ -9,7 +9,7 @@ Upload lettings logs in bulk (<%= @form.year_combo %>)

Prepare your file

-

<%= govuk_link_to "Read the full guidance", bulk_upload_lettings_log_path(id: "guidance", form: { year: @form.year }) %> before you start if you have not used bulk upload before.

+

<%= govuk_link_to "Read the full guidance", bulk_upload_lettings_log_path(id: "guidance", form: { year: @form.year }, referrer: "prepare-your-file") %> before you start if you have not used bulk upload before.

Download template

diff --git a/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb b/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb index 9b25b67ef..b9d0990be 100644 --- a/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb +++ b/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2023.html.erb @@ -9,7 +9,7 @@ Upload sales logs in bulk (<%= @form.year_combo %>)

Prepare your file

-

<%= govuk_link_to "Read the full guidance", bulk_upload_sales_log_path(id: "guidance", form: { year: @form.year }) %> before you start if you have not used bulk upload before.

+

<%= govuk_link_to "Read the full guidance", bulk_upload_sales_log_path(id: "guidance", form: { year: @form.year }, referrer: "prepare-your-file") %> before you start if you have not used bulk upload before.

Download template

diff --git a/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2024.html.erb b/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2024.html.erb index 15d63a957..81c947e15 100644 --- a/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2024.html.erb +++ b/app/views/bulk_upload_sales_logs/forms/prepare_your_file_2024.html.erb @@ -9,7 +9,7 @@ Upload sales logs in bulk (<%= @form.year_combo %>)

Prepare your file

-

<%= govuk_link_to "Read the full guidance", bulk_upload_sales_log_path(id: "guidance", form: { year: @form.year }) %> before you start if you have not used bulk upload before.

+

<%= govuk_link_to "Read the full guidance", bulk_upload_sales_log_path(id: "guidance", form: { year: @form.year }, referrer: "prepare-your-file") %> before you start if you have not used bulk upload before.

Download template

diff --git a/app/views/layouts/_collection_resources.html.erb b/app/views/layouts/_collection_resources.html.erb index bc0e07360..acdc5cb88 100644 --- a/app/views/layouts/_collection_resources.html.erb +++ b/app/views/layouts/_collection_resources.html.erb @@ -1,6 +1,7 @@ <% if current_user %>

Collection resources

<%= govuk_link_to "Guidance for submitting social housing lettings and sales data (CORE)", guidance_path %>

+

<%= govuk_link_to "How to upload logs in bulk", bulk_upload_lettings_log_path(id: "guidance", form: { year: current_collection_start_year }, referrer: "home") %>

<% else %>

Collection resources

<% end %> diff --git a/app/views/start/guidance.html.erb b/app/views/start/guidance.html.erb index 127b56b3b..6fbd157f0 100644 --- a/app/views/start/guidance.html.erb +++ b/app/views/start/guidance.html.erb @@ -9,7 +9,7 @@ <%= accordion.with_section(heading_text: "How to create logs", expanded: true) do %>

There are 2 ways to create logs on CORE.

You can create logs one at a time by answering questions using the online form. Click the “Create a new log” button on the logs page to create logs this way.

-

You can also create many logs at once by uploading a CSV file. This might be faster than creating logs individually if your organisation has its own database and a way to export the data. Click the “Upload logs in bulk” button on the logs page to create logs this way. For more information, <%= govuk_link_to "read the full guidance on bulk upload", bulk_upload_lettings_log_path(id: "guidance", form: { year: current_collection_start_year }) %>.

+

You can also create many logs at once by uploading a CSV file. This might be faster than creating logs individually if your organisation has its own database and a way to export the data. Click the “Upload logs in bulk” button on the logs page to create logs this way. For more information, <%= govuk_link_to "read the full guidance on bulk upload", bulk_upload_lettings_log_path(id: "guidance", form: { year: current_collection_start_year }, referrer: "guidance") %>.

Once you have created and completed a log, there is nothing more you need to do to submit the data.

<% end %> diff --git a/spec/models/forms/bulk_upload_lettings/guidance_spec.rb b/spec/models/forms/bulk_upload_lettings/guidance_spec.rb new file mode 100644 index 000000000..271ff8b27 --- /dev/null +++ b/spec/models/forms/bulk_upload_lettings/guidance_spec.rb @@ -0,0 +1,43 @@ +require "rails_helper" + +RSpec.describe Forms::BulkUploadLettings::Guidance do + include Rails.application.routes.url_helpers + + subject(:bu_guidance) { described_class.new(year:, referrer:) } + + let(:year) { 2024 } + + describe "#back_path" do + context "when referrer is prepare-your-file" do + let(:referrer) { "prepare-your-file" } + + it "returns the prepare your file path" do + expect(bu_guidance.back_path).to eq bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: }) + end + end + + context "when referrer is home" do + let(:referrer) { "home" } + + it "returns the root path" do + expect(bu_guidance.back_path).to eq root_path + end + end + + context "when referrer is guidance" do + let(:referrer) { "guidance" } + + it "returns the main guidance page path" do + expect(bu_guidance.back_path).to eq guidance_path + end + end + + context "when referrer is absent" do + let(:referrer) { nil } + + it "returns the main guidance page path" do + expect(bu_guidance.back_path).to eq guidance_path + end + end + end +end diff --git a/spec/models/forms/bulk_upload_sales/guidance_spec.rb b/spec/models/forms/bulk_upload_sales/guidance_spec.rb new file mode 100644 index 000000000..6eacf6d0c --- /dev/null +++ b/spec/models/forms/bulk_upload_sales/guidance_spec.rb @@ -0,0 +1,43 @@ +require "rails_helper" + +RSpec.describe Forms::BulkUploadSales::Guidance do + include Rails.application.routes.url_helpers + + subject(:bu_guidance) { described_class.new(year:, referrer:) } + + let(:year) { 2024 } + + describe "#back_path" do + context "when referrer is prepare-your-file" do + let(:referrer) { "prepare-your-file" } + + it "returns the prepare your file path" do + expect(bu_guidance.back_path).to eq bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: }) + end + end + + context "when referrer is home" do + let(:referrer) { "home" } + + it "returns the root path" do + expect(bu_guidance.back_path).to eq root_path + end + end + + context "when referrer is guidance" do + let(:referrer) { "guidance" } + + it "returns the main guidance page path" do + expect(bu_guidance.back_path).to eq guidance_path + end + end + + context "when referrer is absent" do + let(:referrer) { nil } + + it "returns the main guidance page path" do + expect(bu_guidance.back_path).to eq guidance_path + end + end + end +end