Browse Source

CLDC-2849 Display correct location code (#2043)

* Display correct location code

* Simplify formatted_local_authority_timeline
pull/2050/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
6d49be2858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/helpers/locations_helper.rb
  2. 4
      spec/features/schemes_spec.rb
  3. 6
      spec/helpers/locations_helper_spec.rb
  4. 1
      spec/views/locations/show.html.erb_spec.rb

12
app/helpers/locations_helper.rb

@ -28,11 +28,11 @@ module LocationsHelper
{ name: "Postcode", value: location.postcode, attribute: "postcode" },
{ name: "Location name", value: location.name, attribute: "name" },
{ name: "Status", value: location.status, attribute: "status" },
{ name: "Local authority", value: formatted_local_authority_timeline(location, "name"), attribute: "local_authority" },
{ name: "Local authority", value: formatted_local_authority_timeline(location), attribute: "local_authority" },
{ name: "Number of units", value: location.units, attribute: "units" },
{ name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit" },
{ name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" },
{ name: "Location code", value: formatted_local_authority_timeline(location, "code"), attribute: "location_code" },
{ name: "Location code", value: location.id, attribute: "id" },
{ name: "Availability", value: location_availability(location), attribute: "availability" },
]
end
@ -41,7 +41,7 @@ module LocationsHelper
[
{ name: "Postcode", value: location.postcode, attribute: "postcode" },
{ name: "Location name", value: location.name, attribute: "name" },
{ name: "Local authority", value: formatted_local_authority_timeline(location, "name"), attribute: "local_authority" },
{ name: "Local authority", value: formatted_local_authority_timeline(location), attribute: "local_authority" },
{ name: "Number of units", value: location.units, attribute: "units" },
{ name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit" },
{ name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" },
@ -121,14 +121,14 @@ private
[inner.deactivation_date, inner.reactivation_date].all? { |date| date.between?(outer.deactivation_date, outer.reactivation_date) }
end
def formatted_local_authority_timeline(location, field)
def formatted_local_authority_timeline(location)
sorted_linked_authorities = location.linked_local_authorities.sort_by(&:start_date)
return sorted_linked_authorities.first[field] if sorted_linked_authorities.count == 1
return sorted_linked_authorities.first["name"] if sorted_linked_authorities.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)} -"
formatted_end_date = linked_local_authority.end_date&.to_formatted_s(:govuk_date) || "present"
"#{linked_local_authority[field]} (#{formatted_start_date} #{formatted_end_date})"
"#{linked_local_authority['name']} (#{formatted_start_date} #{formatted_end_date})"
}.join("\n")
end
end

4
spec/features/schemes_spec.rb

@ -817,7 +817,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content(deactivated_location.units)
expect(page).to have_content(deactivated_location.type_of_unit)
expect(page).to have_content(deactivated_location.mobility_type)
expect(page).to have_content(deactivated_location.location_code)
expect(page).to have_content(deactivated_location.id)
expect(page).to have_content("Active from 4 April 2022 to 3 June 2022 Deactivated on 4 June 2022")
expect(page).to have_content("Deactivated")
end
@ -856,7 +856,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content(location.units)
expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.mobility_type)
expect(page).to have_content(location.location_code)
expect(page).to have_content(location.id)
expect(page).to have_content("Active from 4 April 2022")
expect(page).to have_content("Active")
end

6
spec/helpers/locations_helper_spec.rb

@ -146,7 +146,7 @@ RSpec.describe LocationsHelper do
{ attribute: "units", name: "Number of units", value: location.units },
{ attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit },
{ attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type },
{ attribute: "location_code", name: "Location code", value: location.location_code },
{ attribute: "id", name: "Location code", value: location.id },
{ attribute: "availability", name: "Availability", value: "Active from 1 April 2022" },
]
@ -168,7 +168,7 @@ RSpec.describe LocationsHelper do
{ attribute: "units", name: "Number of units", value: location.units },
{ attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit },
{ attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type },
{ attribute: "location_code", name: "Location code", value: "E07000030 (until 31 March 2023)\nE06000063 (1 April 2023 - present)" },
{ attribute: "id", name: "Location code", value: location.id },
{ attribute: "availability", name: "Availability", value: "Active from 1 April 2022" },
]
@ -191,7 +191,7 @@ RSpec.describe LocationsHelper do
{ attribute: "units", name: "Number of units", value: location.units },
{ attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit },
{ attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type },
{ attribute: "location_code", name: "Location code", value: "" },
{ attribute: "id", name: "Location code", value: location.id },
{ attribute: "availability", name: "Availability", value: "Active from 1 April 2022" },
]

1
spec/views/locations/show.html.erb_spec.rb

@ -29,6 +29,7 @@ RSpec.describe "locations/show.html.erb" do
let(:location) do
instance_double(
Location,
id: 5,
name: "some location",
postcode: "EC1N 2TD",
linked_local_authorities: [],

Loading…
Cancel
Save