Browse Source

Update location availability

pull/996/head
Kat 4 years ago
parent
commit
2b6d56971e
  1. 11
      app/helpers/locations_helper.rb
  2. 2
      app/views/schemes/check_answers.html.erb
  3. 2
      spec/features/schemes_spec.rb
  4. 27
      spec/helpers/locations_helper_spec.rb

11
app/helpers/locations_helper.rb

@ -32,8 +32,17 @@ module LocationsHelper
{ name: "Common type of unit", value: location.type_of_unit }, { name: "Common type of unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type }, { name: "Mobility type", value: location.mobility_type },
{ name: "Code", value: location.location_code }, { 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 }, { name: "Status", value: location.status },
] ]
end 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 end

2
app/views/schemes/check_answers.html.erb

@ -73,7 +73,7 @@
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %> <% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %> <% 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: 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 %> <% end %>
<% end %> <% end %>

2
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.type_of_unit)
expect(page).to have_content(location.mobility_type) expect(page).to have_content(location.mobility_type)
expect(page).to have_content(location.location_code) 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") expect(page).to have_content("Active")
end end

27
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: "Common type of unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type }, { name: "Mobility type", value: location.mobility_type },
{ name: "Code", value: location.location_code }, { 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 }, { name: "Status", value: :active },
] ]
expect(display_location_attributes(location)).to eq(attributes) expect(display_location_attributes(location)).to eq(attributes)
end end
it "displays created_at as availability date if startdate is not present" do context "when viewing availability" do
location.update!(startdate: nil) context "with are no deactivations" do
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] 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 end
end end

Loading…
Cancel
Save