From 32dd02c7ea1f76958a4ce0f2540fd88fdb64ebac Mon Sep 17 00:00:00 2001 From: Kat <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:37:35 +0000 Subject: [PATCH] Only display name once in the locations if only Ecode has changed --- app/helpers/locations_helper.rb | 2 +- spec/helpers/locations_helper_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index fc1008926..60b668cea 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -150,7 +150,7 @@ private def formatted_local_authority_timeline(location) sorted_linked_authorities = location.linked_local_authorities.sort_by(&:start_date) - return sorted_linked_authorities.first["name"] if sorted_linked_authorities.count == 1 + return sorted_linked_authorities.first["name"] if sorted_linked_authorities.count == 1 || sorted_linked_authorities.map(&:name).uniq.count == 1 sorted_linked_authorities.map { |linked_local_authority| formatted_start_date = linked_local_authority.start_date.year == 2021 ? "until" : "#{linked_local_authority.start_date&.to_formatted_s(:govuk_date)} -" diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index 5b3a77e61..3d9eb90b5 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -368,4 +368,26 @@ RSpec.describe LocationsHelper do end end end + + describe "formatted_local_authority_timeline" do + before do + LocalAuthorityLink.create!(local_authority_id: LocalAuthority.find_by(code: "E07000030").id, linked_local_authority_id: LocalAuthority.find_by(code: "E06000063").id) + LocalAuthorityLink.create!(local_authority_id: LocalAuthority.find_by(code: "E08000016").id, linked_local_authority_id: LocalAuthority.find_by(code: "E08000038").id) + end + context "when the location LA's have changed" do + let(:location) { FactoryBot.create(:location, location_code: "E07000030") } + + it "displays a timeline of LAs" do + expect(formatted_local_authority_timeline(location)).to eq("Eden (until 31 March 2023)\nCumberland (1 April 2023 - present)") + end + end + + context "when the LA name hasn't changed but Ecode has changed" do + let(:location) { FactoryBot.create(:location, location_code: "E08000016") } + + it "only displays the location name once" do + expect(formatted_local_authority_timeline(location)).to eq("Barnsley") + end + end + end end