From f60d12c7673c1b78115d955704d9f62148e3b58a Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Thu, 16 May 2024 08:58:16 +0100 Subject: [PATCH] various minor changes following tech review --- app/frontend/styles/_data_box.scss | 2 +- app/presenters/homepage_presenter.rb | 5 +- spec/features/form/tasklist_page_spec.rb | 2 +- spec/presenters/homepage_presenter_spec.rb | 2 +- spec/requests/start_controller_spec.rb | 87 ++++--------------- .../lettings/year2023/row_parser_spec.rb | 2 +- .../lettings/year2024/row_parser_spec.rb | 2 +- 7 files changed, 26 insertions(+), 76 deletions(-) diff --git a/app/frontend/styles/_data_box.scss b/app/frontend/styles/_data_box.scss index 2706817c3..95c509b04 100644 --- a/app/frontend/styles/_data_box.scss +++ b/app/frontend/styles/_data_box.scss @@ -5,7 +5,7 @@ } .app-data-box-group { - @include govuk-responsive-margin(4, "top") + @include govuk-responsive-margin(4, "top"); } @media (min-width: 54.0625em) { diff --git a/app/presenters/homepage_presenter.rb b/app/presenters/homepage_presenter.rb index 9fe388308..7110af073 100644 --- a/app/presenters/homepage_presenter.rb +++ b/app/presenters/homepage_presenter.rb @@ -1,5 +1,6 @@ class HomepagePresenter include Rails.application.routes.url_helpers + include CollectionTimeHelper attr_reader :current_year_in_progress_lettings_data, :current_year_completed_lettings_data, :current_year_in_progress_sales_data, :current_year_completed_sales_data, :last_year_in_progress_lettings_data, :last_year_completed_lettings_data, :last_year_in_progress_sales_data, :last_year_completed_sales_data, :incomplete_schemes_data @@ -7,7 +8,7 @@ class HomepagePresenter @user = user @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 = current_collection_start_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 display_sales? @@ -60,8 +61,6 @@ class HomepagePresenter private def subheading_from_year(year) - return "AAAAH" if year.nil? - "#{year} to #{year + 1} Logs" end diff --git a/spec/features/form/tasklist_page_spec.rb b/spec/features/form/tasklist_page_spec.rb index a532478c1..6c87d074e 100644 --- a/spec/features/form/tasklist_page_spec.rb +++ b/spec/features/form/tasklist_page_spec.rb @@ -67,7 +67,7 @@ RSpec.describe "Task List" do expect(page).to have_content("This log has not been started.") end - context "when testing completed subsection count" do + describe "completed subsection count" do let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json") } before do diff --git a/spec/presenters/homepage_presenter_spec.rb b/spec/presenters/homepage_presenter_spec.rb index 2746cbeae..bcb3e2fc4 100644 --- a/spec/presenters/homepage_presenter_spec.rb +++ b/spec/presenters/homepage_presenter_spec.rb @@ -148,7 +148,7 @@ RSpec.describe HomepagePresenter do end end - context "when testing the data collected and exposed by the presenter" do + describe "the data collected and exposed by the presenter" do context "with lettings logs" do let(:type) { :lettings_log } diff --git a/spec/requests/start_controller_spec.rb b/spec/requests/start_controller_spec.rb index 7cbf73a9a..128325184 100644 --- a/spec/requests/start_controller_spec.rb +++ b/spec/requests/start_controller_spec.rb @@ -32,7 +32,7 @@ RSpec.describe StartController, type: :request do expect(page).to have_content("Welcome back") end - context "when testing the data displayed at the top of the home page" do + describe "the data displayed at the top of the home page" do let(:current_year) { FormHandler.instance.current_collection_start_year } let(:in_crossover_period) { false } @@ -139,7 +139,7 @@ RSpec.describe StartController, type: :request do end end - context "when testing the links in the data boxes" do + describe "the links in the data boxes" do let(:user) { create(:user, :data_coordinator) } let(:in_crossover_period) { true } @@ -148,76 +148,27 @@ RSpec.describe StartController, type: :request do get root_path end - it "shows the correct links for in progress lettings" do - type = "lettings" - status = "in_progress" - databoxes = all_databoxes(type, status) - - expect(databoxes.count).to be 2 - - links = databoxes.map { |databox| link_from_databox databox } - - expect(links.map(&:path)).to all eq lettings_logs_path - - params = links.map { |link| CGI.parse(link.query) } - - expect(params.map { |prms| prms["status[]"] }).to all eq [status] - expect(params.first["years[]"]).to eq [(current_year - 1).to_s] - expect(params.second["years[]"]).to eq [current_year.to_s] - end - - it "shows the correct links for completed lettings" do - type = "lettings" - status = "completed" - databoxes = all_databoxes(type, status) - - expect(databoxes.count).to be 2 - - links = databoxes.map { |databox| link_from_databox databox } - - expect(links.map(&:path)).to all eq lettings_logs_path - - params = links.map { |link| CGI.parse(link.query) } + [ + { type: "lettings", status: "in_progress" }, + { type: "lettings", status: "completed" }, + { type: "sales", status: "in_progress" }, + { type: "sales", status: "completed" }, + ].each do |test_case| + it "shows the correct links for #{test_case[:status]} #{test_case[:type]}" do + databoxes = all_databoxes(test_case[:type], test_case[:status]) - expect(params.map { |prms| prms["status[]"] }).to all eq [status] - expect(params.first["years[]"]).to eq [(current_year - 1).to_s] - expect(params.second["years[]"]).to eq [current_year.to_s] - end - - it "shows the correct links for in progress sales" do - type = "sales" - status = "in_progress" - databoxes = all_databoxes(type, status) - - expect(databoxes.count).to be 2 + expect(databoxes.count).to be 2 - links = databoxes.map { |databox| link_from_databox databox } + links = databoxes.map { |databox| link_from_databox databox } - expect(links.map(&:path)).to all eq sales_logs_path + expect(links.map(&:path)).to all eq send("#{test_case[:type]}_logs_path") - params = links.map { |link| CGI.parse(link.query) } + params = links.map { |link| CGI.parse(link.query) } - expect(params.map { |prms| prms["status[]"] }).to all eq [status] - expect(params.first["years[]"]).to eq [(current_year - 1).to_s] - expect(params.second["years[]"]).to eq [current_year.to_s] - end - - it "shows the correct links for completed sales" do - type = "sales" - status = "completed" - databoxes = all_databoxes(type, status) - - expect(databoxes.count).to be 2 - - links = databoxes.map { |databox| link_from_databox databox } - - expect(links.map(&:path)).to all eq sales_logs_path - - params = links.map { |link| CGI.parse(link.query) } - - expect(params.map { |prms| prms["status[]"] }).to all eq [status] - expect(params.first["years[]"]).to eq [(current_year - 1).to_s] - expect(params.second["years[]"]).to eq [current_year.to_s] + expect(params.map { |prms| prms["status[]"] }).to all eq [test_case[:status]] + expect(params.first["years[]"]).to eq [(current_year - 1).to_s] + expect(params.second["years[]"]).to eq [current_year.to_s] + end end it "shows the correct links for incomplete schemes" do @@ -237,7 +188,7 @@ RSpec.describe StartController, type: :request do end end - context "when testing the counts displayed" do + describe "the counts displayed" do let(:in_crossover_period) { true } let(:org_1) { create(:organisation) } let(:org_2) { create(:organisation) } diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index ca17041ff..0c394b9c0 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -107,7 +107,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do end end - context "when testing valid/invalid attributes" do + describe "valid/invalid attributes" do let(:valid_attributes) do { bulk_upload:, diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index 712e7a817..2c4d475ee 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -125,7 +125,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end - context "when testing valid/invalid attributes" do + describe "valid/invalid attributes" do let(:valid_attributes) do { bulk_upload:,