diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 2a02ebc94..b64f8f1bf 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -32,8 +32,17 @@ module LocationsHelper { name: "Common type of unit", value: location.type_of_unit }, { name: "Mobility type", value: location.mobility_type }, { name: "Code", value: location.location_code }, - { name: "Availability", value: "Available from #{location.available_from.to_formatted_s(:govuk_date)}" }, + { name: "Availability", value: location_availability(location) }, { name: "Status", value: location.status }, ] end + + def location_availability(location) + availability = "Active from #{location.available_from.to_formatted_s(:govuk_date)}" + location.location_deactivations.each do |deactivation| + availability << " to #{(deactivation.deactivation_date - 1.day).to_formatted_s(:govuk_date)}\nDeactivated on #{deactivation.deactivation_date.to_formatted_s(:govuk_date)}" + availability << "\nActive from #{deactivation.reactivation_date.to_formatted_s(:govuk_date)}" if deactivation.reactivation_date.present? + end + availability + end end diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index a41b202ad..9f87ec566 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -73,7 +73,7 @@ <% row.cell(text: simple_format("#{location.type_of_unit}")) %> <% row.cell(text: location.mobility_type) %> <% row.cell(text: simple_format(location_cell_location_admin_district(location, get_location_change_link_href_location_admin_district(@scheme, location)), wrapper_tag: "div")) %> - <% row.cell(text: location.startdate&.to_formatted_s(:govuk_date)) %> + <% row.cell(text: location_availability(location)) %> <% end %> <% end %> <% end %> diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 1500a728c..67660b8ad 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -766,7 +766,7 @@ RSpec.describe "Schemes scheme Features" do 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("Available from 4 April 2022") + expect(page).to have_content("Active from 4 April 2022") expect(page).to have_content("Active") end diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index 2adfab35f..a85ed782d 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -59,18 +59,35 @@ RSpec.describe LocationsHelper do { name: "Common type of unit", value: location.type_of_unit }, { name: "Mobility type", value: location.mobility_type }, { name: "Code", value: location.location_code }, - { name: "Availability", value: "Available from 8 August 2022" }, + { name: "Availability", value: "Active from 8 August 2022" }, { name: "Status", value: :active }, ] expect(display_location_attributes(location)).to eq(attributes) end - it "displays created_at as availability date if startdate is not present" do - location.update!(startdate: nil) - availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] + context "when viewing availability" do + context "with are no deactivations" do + it "displays created_at as availability date if startdate is not present" do + location.update!(startdate: nil) + availability_attribute = display_attributes(location).find { |x| x[:name] == "Availability" }[:value] - expect(availability_attribute).to eq("Available from #{location.created_at.to_formatted_s(:govuk_date)}") + expect(availability_attribute).to eq("Active from #{location.created_at.to_formatted_s(:govuk_date)}") + end + end + + context "with previous deactivations" do + before do + location.location_deactivations << FactoryBot.create(:location_deactivation, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1)) + location.location_deactivations << FactoryBot.create(:location_deactivation, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil) + end + + it "displays the timeline of availability" do + availability_attribute = display_attributes(location).find { |x| x[:name] == "Availability" }[:value] + + expect(availability_attribute).to eq("Active from 8 August 2022 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022") + end + end end end end