Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule DotcomWeb.Components.SystemStatus.CommuterRailRouteStatus do
<:heading>
<div class="grow">
<.status_label
description={"#{@prefix}#{Alert.human_effect(@impact.alert)}"}
description={"#{@prefix}#{service_effect_description(@impact.alert)}"}
status={@impact.alert.effect}
/>
</div>
Expand All @@ -79,6 +79,9 @@ defmodule DotcomWeb.Components.SystemStatus.CommuterRailRouteStatus do
"""
end

defp service_effect_description(%Alert{effect: :station_closure}), do: ~t"Stop Skipped"
defp service_effect_description(alert), do: Alerts.Alert.human_effect(alert)

defp train_impact_rows(%{impacts: []} = assigns), do: ~H""

defp train_impact_rows(assigns) do
Expand Down
35 changes: 19 additions & 16 deletions lib/dotcom_web/components/system_status/commuter_rail_status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ defmodule DotcomWeb.Components.SystemStatus.CommuterRailStatus do
|> Enum.to_list()
|> case do
[{effect, impact_list}] ->
effect_string = Alerts.Alert.human_effect(%Alerts.Alert{effect: effect})

[
%{icon_atom: effect, label: service_impact_label(impact_list, effect_string)}
%{icon_atom: effect, label: service_impact_label(impact_list, effect)}
]

_ ->
Expand All @@ -181,21 +179,26 @@ defmodule DotcomWeb.Components.SystemStatus.CommuterRailStatus do
end
end

# Constructs a label for a service impact row out of the effect
# string out of the impact list and the provided effect string
defp service_impact_label(impact_list, effect_string)
# Constructs a label for a service impact row out of the impact list
# and the provided effect. If there's a single impact, then it
# either says "1 <effect>" or "HH:MM: <effect>", depending on
# whether the alert is active. If there are multiple impacts, then
# it says "<count> <effects>".
defp service_impact_label([impact], effect),
do: "#{count_or_time(impact.start_time)} #{singular_effect_description(effect)}"

# If there's just one impact, then use `maybe_add_time_prefix` to
# prepend the time or count
defp service_impact_label([impact], effect_string) do
"#{count_or_time(impact.start_time)} #{effect_string}"
end
defp service_impact_label(impact_list, effect),
do: "#{impact_list |> Enum.count()} #{plural_effect_description(effect)}"

# If there's more than one impact, then the label should be the
# count along with a pluralized effect string
defp service_impact_label(impact_list, effect_string) do
"#{impact_list |> Enum.count()} #{effect_string |> Inflex.pluralize()}"
end
defp singular_effect_description(:station_closure), do: ~t"Stop Skipped"

defp singular_effect_description(effect),
do: Alerts.Alert.human_effect(%Alerts.Alert{effect: effect})

defp plural_effect_description(:station_closure), do: ~t"Stops Skipped"

defp plural_effect_description(effect),
do: effect |> singular_effect_description() |> Inflex.pluralize()

# If there is one alert of the effect, and it is active in the future, give the time.
# For all others, just give the count.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,50 @@ defmodule DotcomWeb.SystemStatus.CommuterRailRouteStatusTest do

assert status_row_headers_for_route(route_id) == ["Delays"]
end

test "shows other service alerts" do
# SETUP
route_id = Faker.Color.fancy_name()

alert =
Factories.Alerts.Alert.build(:alert_for_route,
effect: :shuttle,
severity: 3,
route_id: route_id
)

expect(Alerts.Repo.Mock, :by_route_ids, fn _, _ ->
[alert |> Factories.Alerts.Alert.active_now()]
end)

# EXERCISE / VERIFY

assert status_row_headers_for_route(route_id) == [
"Shuttle"
]
end

test "renders station closures as 'Stop Skipped'" do
# SETUP
route_id = Faker.Color.fancy_name()

alert =
Factories.Alerts.Alert.build(:alert_for_route,
effect: :station_closure,
severity: 3,
route_id: route_id
)

expect(Alerts.Repo.Mock, :by_route_ids, fn _, _ ->
[alert |> Factories.Alerts.Alert.active_now()]
end)

# EXERCISE / VERIFY

assert status_row_headers_for_route(route_id) == [
"Stop Skipped"
]
end
end

defp status_row_headers_for_route(route_id) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,46 @@ defmodule DotcomWeb.SystemStatus.CommuterRailStatusTest do
assert html =~ "2 Shuttles"
end

test "renders a single station closure as `Stop Skipped`" do
# SETUP
expect(Alerts.Repo.Mock, :by_route_ids, fn _, _ ->
[
Factories.Alerts.Alert.build(:alert,
effect: :station_closure,
severity: 3
)
]
|> Enum.map(&Factories.Alerts.Alert.active_now/1)
end)

assigns = %{commuter_rail_status: commuter_rail_status()}

# EXERCISE
html = render_component(&alerts_commuter_rail_status/1, assigns)

# VERIFY
assert html =~ "1 Stop Skipped"
end

test "renders multiple station closures as `Stops Skipped`" do
# SETUP
expect(Alerts.Repo.Mock, :by_route_ids, fn _, _ ->
Factories.Alerts.Alert.build_list(2, :alert,
effect: :station_closure,
severity: 3
)
|> Enum.map(&Factories.Alerts.Alert.active_now/1)
end)

assigns = %{commuter_rail_status: commuter_rail_status()}

# EXERCISE
html = render_component(&alerts_commuter_rail_status/1, assigns)

# VERIFY
assert html =~ "2 Stops Skipped"
end

test "shows the active-period start time for a single service impact starting in the future" do
# SETUP
{_, service_day_end} = ServiceDateTime.service_range_day()
Expand Down