diff --git a/app/flows/check_travel_during_coronavirus_flow/outcomes/_country.erb b/app/flows/check_travel_during_coronavirus_flow/outcomes/_country.erb index 550d0684966..b75cdb94592 100644 --- a/app/flows/check_travel_during_coronavirus_flow/outcomes/_country.erb +++ b/app/flows/check_travel_during_coronavirus_flow/outcomes/_country.erb @@ -5,6 +5,10 @@ margin_bottom: 4, } %> +<% if country.next_covid_status.present? %> + <%= render partial: "country/status_change", locals: { country: country } %> +<% end %> + <% if calculator.countries_with_content_headers_converted.include?(country.slug) %>

You should read the following sections of the <%= country.title %> entry requirements guidance on:

diff --git a/app/flows/check_travel_during_coronavirus_flow/outcomes/country/_status_change.erb b/app/flows/check_travel_during_coronavirus_flow/outcomes/country/_status_change.erb new file mode 100644 index 00000000000..7530de982a0 --- /dev/null +++ b/app/flows/check_travel_during_coronavirus_flow/outcomes/country/_status_change.erb @@ -0,0 +1,14 @@ +<% + next_status_date = country.next_covid_status_applies_at.to_s(:govuk_date) + next_status_time = country.next_covid_status_applies_at.to_s(:govuk_time) +%> + +<% if country.next_covid_status == "red" %> + <%= render "govuk_publishing_components/components/warning_text", { + text: "#{country.title} will move to the red list for travel to England at #{next_status_time} on #{next_status_date}. Until then you should follow the rules below for returning to England." + } %> +<% else %> + <%= render "govuk_publishing_components/components/warning_text", { + text: "#{country.title} will be removed from the red list for travel to England at #{next_status_time} on #{next_status_date}. Until then you should follow the rules below for returning to England." + } %> +<% end %> diff --git a/app/models/world_location.rb b/app/models/world_location.rb index 845517f703b..f060e8569bf 100644 --- a/app/models/world_location.rb +++ b/app/models/world_location.rb @@ -66,7 +66,51 @@ def self.travel_rules @travel_rules ||= YAML.load_file(Rails.root.join("config/smart_answers/check_travel_during_coronavirus_data.yml")) end + def initialize(location) + @title = location.fetch("title", "") + @details = location.fetch("details", {}) + @slug = @details.fetch("slug", "") + end + + alias_method :name, :title + def covid_status + current_covid_status_data&.dig("covid_status") + end + + def next_covid_status + next_covid_status_data&.dig("covid_status") + end + + def next_covid_status_applies_at + Time.zone.parse(next_covid_status_data["covid_status_applies_at"]) + rescue NoMethodError, TypeError + nil + end + + def current_covid_status_data + current_statuses = covid_status_data_for_location&.select do |status| + start_date = Time.zone.parse(status["covid_status_applies_at"]) + start_date.past? + end + + return if current_statuses.blank? + + current_statuses.max_by { |status| status["covid_status_applies_at"] } + end + + def next_covid_status_data + future_statuses = covid_status_data_for_location&.select do |status| + start_date = Time.zone.parse(status["covid_status_applies_at"]) + start_date.future? + end + + return if future_statuses.blank? + + future_statuses.min_by { |status| status["covid_status_applies_at"] } + end + + def covid_status_data_for_location # Once the world location api returns the covid status, we should be able # to replace this line with: # location.fetch("england_coronavirus_travel", "") @@ -74,17 +118,9 @@ def covid_status return if rules.blank? - rules["england_coronavirus_travel"]["covid_status"] + rules["england_coronavirus_travel"] end - def initialize(location) - @title = location.fetch("title", "") - @details = location.fetch("details", {}) - @slug = @details.fetch("slug", "") - end - - alias_method :name, :title - def ==(other) other.is_a?(self.class) && other.slug == @slug end diff --git a/config/initializers/time_formats.rb b/config/initializers/time_formats.rb index d2452eea894..176c69b2d7c 100644 --- a/config/initializers/time_formats.rb +++ b/config/initializers/time_formats.rb @@ -13,6 +13,7 @@ shared_formats = { govuk_date: "%-d %B %Y", # '4 December 2009' govuk_date_with_day: "%A, %d %B %Y", # 'Friday, 4 December 2009' + govuk_time: "%l:%M%P", # '2:30am' } Time::DATE_FORMATS.merge! shared_formats diff --git a/config/smart_answers/check_travel_during_coronavirus_data.yml b/config/smart_answers/check_travel_during_coronavirus_data.yml index e7560ff11a8..5de9dc81176 100644 --- a/config/smart_answers/check_travel_during_coronavirus_data.yml +++ b/config/smart_answers/check_travel_during_coronavirus_data.yml @@ -4,15 +4,15 @@ results: details: slug: italy england_coronavirus_travel: - covid_status: green - next_covid_status: - next_covid_status_applies_at: - status_out_of_date: false + - covid_status: not_red + covid_status_applies_at: "2021-12-20T:02:00.000+00:00" + - covid_status: red + covid_status_applies_at: "2022-02-20T:02:30.000+00:00" - title: South Africa details: slug: south-africa england_coronavirus_travel: - covid_status: red - next_covid_status: - next_covid_status_applies_at: - status_out_of_date: false + - covid_status: red + covid_status_applies_at: "2021-12-20T:02:00.000+00:00" + - covid_status: not_red + covid_status_applies_at: "2022-02-20T:16:00.000+00:00" diff --git a/test/flows/check_travel_during_coronavirus_test.rb b/test/flows/check_travel_during_coronavirus_flow_test.rb similarity index 80% rename from test/flows/check_travel_during_coronavirus_test.rb rename to test/flows/check_travel_during_coronavirus_flow_test.rb index 84413cade93..aa480af5298 100644 --- a/test/flows/check_travel_during_coronavirus_test.rb +++ b/test/flows/check_travel_during_coronavirus_flow_test.rb @@ -1,7 +1,7 @@ require "test_helper" require "support/flow_test_helper" -class CheckTravelDuringCoronavirusTest < ActiveSupport::TestCase +class CheckTravelDuringCoronavirusFlowTest < ActiveSupport::TestCase include FlowTestHelper setup do @@ -218,6 +218,89 @@ class CheckTravelDuringCoronavirusTest < ActiveSupport::TestCase assert_rendered_outcome text: "You are travelling through" end + context "content for countries changing covid status" do + should "render 'move to the red list' content for countries moving to the red list" do + travel_to("2022-01-01") do + WorldLocation.stubs(:travel_rules).returns({ + "results" => [ + { + "title" => "Poland", + "details" => { + "slug" => "poland", + }, + "england_coronavirus_travel" => [ + { + "covid_status" => "not_red", + "covid_status_applies_at" => "2021-12-20T:02:00.000+00:00", + }, + { + "covid_status" => "red", + "covid_status_applies_at" => "2022-02-20T:02:00.000+00:00", + }, + ], + }, + ], + }) + assert_rendered_outcome text: "Poland will move to the red list for travel to England" + end + end + + should "render 'removed from the red list' content for countries moving from the red list" do + travel_to("2022-01-01") do + WorldLocation.stubs(:travel_rules).returns({ + "results" => [ + { + "title" => "Poland", + "details" => { + "slug" => "poland", + }, + "england_coronavirus_travel" => [ + { + "covid_status" => "red", + "covid_status_applies_at" => "2021-12-20T:02:00.000+00:00", + }, + { + "covid_status" => "not_red", + "covid_status_applies_at" => "2022-02-20T:02:00.000+00:00", + }, + ], + }, + ], + }) + + add_responses going_to_countries_within_10_days: "no" + assert_rendered_outcome text: "Poland will be removed from the red list for travel to England" + end + end + + should "not render changing status content if most recent status is in the past" do + travel_to("2022-03-01") do + WorldLocation.stubs(:travel_rules).returns({ + "results" => [ + { + "title" => "Poland", + "details" => { + "slug" => "poland", + }, + "england_coronavirus_travel" => [ + { + "covid_status" => "red", + "covid_status_applies_at" => "2021-12-20T:02:00.000+00:00", + }, + { + "covid_status" => "not_red", + "covid_status_applies_at" => "2022-02-20T:02:00.000+00:00", + }, + ], + }, + ], + }) + + assert_no_match "Poland will be removed from the red list for travel to England", @test_flow.outcome_text + end + end + end + context "country specific content that has had the headers converted" do setup do SmartAnswer::Calculators::CheckTravelDuringCoronavirusCalculator.any_instance.stubs(:countries_with_content_headers_converted).returns(%w[spain italy]) diff --git a/test/unit/world_location_test.rb b/test/unit/world_location_test.rb index 7805b4b26d6..e437828a83e 100644 --- a/test/unit/world_location_test.rb +++ b/test/unit/world_location_test.rb @@ -275,7 +275,7 @@ class WorldLocationTest < ActiveSupport::TestCase context "england_coronavirus_travel" do setup do - stub_worldwide_api_has_location("italy") + @future_status_date = "2022-02-20T:02:00.000+00:00" WorldLocation.stubs(:travel_rules).returns({ "results" => [ { @@ -283,17 +283,58 @@ class WorldLocationTest < ActiveSupport::TestCase "details" => { "slug" => "italy", }, - "england_coronavirus_travel" => { - "covid_status" => "red", - }, + "england_coronavirus_travel" => [ + { + "covid_status" => "red", + "covid_status_applies_at" => "2021-12-20T:02:00.000+00:00", + }, + { + "covid_status" => "not_red", + "covid_status_applies_at" => @future_status_date, + }, + ], }, ], }) - @location = WorldLocation.find("italy") + travel_to("2022-01-01") end - should "find the covid status for a location" do - assert_equal "red", @location.covid_status + context "covid statuses exist" do + setup do + stub_worldwide_api_has_location("italy") + @location = WorldLocation.find("italy") + end + + should "find the current covid status for a location" do + assert_equal "red", @location.covid_status + end + + should "find the next covid status for a location" do + assert_equal "not_red", @location.next_covid_status + end + + should "find the next covid status applies at date for a location" do + assert_equal Time.zone.parse(@future_status_date), @location.next_covid_status_applies_at + end + end + + context "covid statuses do not exist" do + setup do + stub_worldwide_api_has_location("spain") + @location = WorldLocation.find("spain") + end + + should "return covid status of nil if covid statuses unknown for location" do + assert_nil @location.covid_status + end + + should "return a next covid status of nil if covid statuses unknown for location" do + assert_nil @location.next_covid_status + end + + should "return a next covid status date of nil if covid statuses unknown for location" do + assert_nil @location.next_covid_status_applies_at + end end end end