Skip to content

Commit 28cf595

Browse files
authored
Merge pull request #5731 from alphagov/automate-changing-statuses
Display upcoming COVID status changes on the results page
2 parents a19f5e9 + cbe06fb commit 28cf595

File tree

7 files changed

+204
-25
lines changed

7 files changed

+204
-25
lines changed

app/flows/check_travel_during_coronavirus_flow/outcomes/_country.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
margin_bottom: 4,
66
} %>
77

8+
<% if country.next_covid_status.present? %>
9+
<%= render partial: "country/status_change", locals: { country: country } %>
10+
<% end %>
11+
812
<% if calculator.countries_with_content_headers_converted.include?(country.slug) %>
913
<p class="govuk-body">You should read the following sections of the <%= country.title %> entry requirements guidance on:</p>
1014

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<%
2+
next_status_date = country.next_covid_status_applies_at.to_s(:govuk_date)
3+
next_status_time = country.next_covid_status_applies_at.to_s(:govuk_time)
4+
%>
5+
6+
<% if country.next_covid_status == "red" %>
7+
<%= render "govuk_publishing_components/components/warning_text", {
8+
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."
9+
} %>
10+
<% else %>
11+
<%= render "govuk_publishing_components/components/warning_text", {
12+
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."
13+
} %>
14+
<% end %>

app/models/world_location.rb

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,61 @@ def self.travel_rules
6666
@travel_rules ||= YAML.load_file(Rails.root.join("config/smart_answers/check_travel_during_coronavirus_data.yml"))
6767
end
6868

69+
def initialize(location)
70+
@title = location.fetch("title", "")
71+
@details = location.fetch("details", {})
72+
@slug = @details.fetch("slug", "")
73+
end
74+
75+
alias_method :name, :title
76+
6977
def covid_status
78+
current_covid_status_data&.dig("covid_status")
79+
end
80+
81+
def next_covid_status
82+
next_covid_status_data&.dig("covid_status")
83+
end
84+
85+
def next_covid_status_applies_at
86+
Time.zone.parse(next_covid_status_data["covid_status_applies_at"])
87+
rescue NoMethodError, TypeError
88+
nil
89+
end
90+
91+
def current_covid_status_data
92+
current_statuses = covid_status_data_for_location&.select do |status|
93+
start_date = Time.zone.parse(status["covid_status_applies_at"])
94+
start_date.past?
95+
end
96+
97+
return if current_statuses.blank?
98+
99+
current_statuses.max_by { |status| status["covid_status_applies_at"] }
100+
end
101+
102+
def next_covid_status_data
103+
future_statuses = covid_status_data_for_location&.select do |status|
104+
start_date = Time.zone.parse(status["covid_status_applies_at"])
105+
start_date.future?
106+
end
107+
108+
return if future_statuses.blank?
109+
110+
future_statuses.min_by { |status| status["covid_status_applies_at"] }
111+
end
112+
113+
def covid_status_data_for_location
70114
# Once the world location api returns the covid status, we should be able
71115
# to replace this line with:
72116
# location.fetch("england_coronavirus_travel", "")
73117
rules = self.class.travel_rules["results"].select { |country| country["details"]["slug"] == slug }.first
74118

75119
return if rules.blank?
76120

77-
rules["england_coronavirus_travel"]["covid_status"]
121+
rules["england_coronavirus_travel"]
78122
end
79123

80-
def initialize(location)
81-
@title = location.fetch("title", "")
82-
@details = location.fetch("details", {})
83-
@slug = @details.fetch("slug", "")
84-
end
85-
86-
alias_method :name, :title
87-
88124
def ==(other)
89125
other.is_a?(self.class) && other.slug == @slug
90126
end

config/initializers/time_formats.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
shared_formats = {
1414
govuk_date: "%-d %B %Y", # '4 December 2009'
1515
govuk_date_with_day: "%A, %d %B %Y", # 'Friday, 4 December 2009'
16+
govuk_time: "%l:%M%P", # '2:30am'
1617
}
1718

1819
Time::DATE_FORMATS.merge! shared_formats

config/smart_answers/check_travel_during_coronavirus_data.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ results:
44
details:
55
slug: italy
66
england_coronavirus_travel:
7-
covid_status: green
8-
next_covid_status:
9-
next_covid_status_applies_at:
10-
status_out_of_date: false
7+
- covid_status: not_red
8+
covid_status_applies_at: "2021-12-20T:02:00.000+00:00"
9+
- covid_status: red
10+
covid_status_applies_at: "2022-02-20T:02:30.000+00:00"
1111
- title: South Africa
1212
details:
1313
slug: south-africa
1414
england_coronavirus_travel:
15-
covid_status: red
16-
next_covid_status:
17-
next_covid_status_applies_at:
18-
status_out_of_date: false
15+
- covid_status: red
16+
covid_status_applies_at: "2021-12-20T:02:00.000+00:00"
17+
- covid_status: not_red
18+
covid_status_applies_at: "2022-02-20T:16:00.000+00:00"

test/flows/check_travel_during_coronavirus_test.rb renamed to test/flows/check_travel_during_coronavirus_flow_test.rb

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "test_helper"
22
require "support/flow_test_helper"
33

4-
class CheckTravelDuringCoronavirusTest < ActiveSupport::TestCase
4+
class CheckTravelDuringCoronavirusFlowTest < ActiveSupport::TestCase
55
include FlowTestHelper
66

77
setup do
@@ -218,6 +218,89 @@ class CheckTravelDuringCoronavirusTest < ActiveSupport::TestCase
218218
assert_rendered_outcome text: "You are travelling through"
219219
end
220220

221+
context "content for countries changing covid status" do
222+
should "render 'move to the red list' content for countries moving to the red list" do
223+
travel_to("2022-01-01") do
224+
WorldLocation.stubs(:travel_rules).returns({
225+
"results" => [
226+
{
227+
"title" => "Poland",
228+
"details" => {
229+
"slug" => "poland",
230+
},
231+
"england_coronavirus_travel" => [
232+
{
233+
"covid_status" => "not_red",
234+
"covid_status_applies_at" => "2021-12-20T:02:00.000+00:00",
235+
},
236+
{
237+
"covid_status" => "red",
238+
"covid_status_applies_at" => "2022-02-20T:02:00.000+00:00",
239+
},
240+
],
241+
},
242+
],
243+
})
244+
assert_rendered_outcome text: "Poland will move to the red list for travel to England"
245+
end
246+
end
247+
248+
should "render 'removed from the red list' content for countries moving from the red list" do
249+
travel_to("2022-01-01") do
250+
WorldLocation.stubs(:travel_rules).returns({
251+
"results" => [
252+
{
253+
"title" => "Poland",
254+
"details" => {
255+
"slug" => "poland",
256+
},
257+
"england_coronavirus_travel" => [
258+
{
259+
"covid_status" => "red",
260+
"covid_status_applies_at" => "2021-12-20T:02:00.000+00:00",
261+
},
262+
{
263+
"covid_status" => "not_red",
264+
"covid_status_applies_at" => "2022-02-20T:02:00.000+00:00",
265+
},
266+
],
267+
},
268+
],
269+
})
270+
271+
add_responses going_to_countries_within_10_days: "no"
272+
assert_rendered_outcome text: "Poland will be removed from the red list for travel to England"
273+
end
274+
end
275+
276+
should "not render changing status content if most recent status is in the past" do
277+
travel_to("2022-03-01") do
278+
WorldLocation.stubs(:travel_rules).returns({
279+
"results" => [
280+
{
281+
"title" => "Poland",
282+
"details" => {
283+
"slug" => "poland",
284+
},
285+
"england_coronavirus_travel" => [
286+
{
287+
"covid_status" => "red",
288+
"covid_status_applies_at" => "2021-12-20T:02:00.000+00:00",
289+
},
290+
{
291+
"covid_status" => "not_red",
292+
"covid_status_applies_at" => "2022-02-20T:02:00.000+00:00",
293+
},
294+
],
295+
},
296+
],
297+
})
298+
299+
assert_no_match "Poland will be removed from the red list for travel to England", @test_flow.outcome_text
300+
end
301+
end
302+
end
303+
221304
context "country specific content that has had the headers converted" do
222305
setup do
223306
SmartAnswer::Calculators::CheckTravelDuringCoronavirusCalculator.any_instance.stubs(:countries_with_content_headers_converted).returns(%w[spain italy])

test/unit/world_location_test.rb

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,66 @@ class WorldLocationTest < ActiveSupport::TestCase
275275

276276
context "england_coronavirus_travel" do
277277
setup do
278-
stub_worldwide_api_has_location("italy")
278+
@future_status_date = "2022-02-20T:02:00.000+00:00"
279279
WorldLocation.stubs(:travel_rules).returns({
280280
"results" => [
281281
{
282282
"title" => "Italy",
283283
"details" => {
284284
"slug" => "italy",
285285
},
286-
"england_coronavirus_travel" => {
287-
"covid_status" => "red",
288-
},
286+
"england_coronavirus_travel" => [
287+
{
288+
"covid_status" => "red",
289+
"covid_status_applies_at" => "2021-12-20T:02:00.000+00:00",
290+
},
291+
{
292+
"covid_status" => "not_red",
293+
"covid_status_applies_at" => @future_status_date,
294+
},
295+
],
289296
},
290297
],
291298
})
292-
@location = WorldLocation.find("italy")
299+
travel_to("2022-01-01")
293300
end
294301

295-
should "find the covid status for a location" do
296-
assert_equal "red", @location.covid_status
302+
context "covid statuses exist" do
303+
setup do
304+
stub_worldwide_api_has_location("italy")
305+
@location = WorldLocation.find("italy")
306+
end
307+
308+
should "find the current covid status for a location" do
309+
assert_equal "red", @location.covid_status
310+
end
311+
312+
should "find the next covid status for a location" do
313+
assert_equal "not_red", @location.next_covid_status
314+
end
315+
316+
should "find the next covid status applies at date for a location" do
317+
assert_equal Time.zone.parse(@future_status_date), @location.next_covid_status_applies_at
318+
end
319+
end
320+
321+
context "covid statuses do not exist" do
322+
setup do
323+
stub_worldwide_api_has_location("spain")
324+
@location = WorldLocation.find("spain")
325+
end
326+
327+
should "return covid status of nil if covid statuses unknown for location" do
328+
assert_nil @location.covid_status
329+
end
330+
331+
should "return a next covid status of nil if covid statuses unknown for location" do
332+
assert_nil @location.next_covid_status
333+
end
334+
335+
should "return a next covid status date of nil if covid statuses unknown for location" do
336+
assert_nil @location.next_covid_status_applies_at
337+
end
297338
end
298339
end
299340
end

0 commit comments

Comments
 (0)