Skip to content

Commit

Permalink
Tests, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahpurcell committed Jul 24, 2023
1 parent f0455f9 commit 7aad68b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 44 deletions.
1 change: 1 addition & 0 deletions lib/screens/v2/widget_instance/reconstructed_alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlert do
def audio_serialize(t), do: ReconstructedAlert.serialize(t)
def audio_sort_key(t), do: ReconstructedAlert.audio_sort_key(t)
def audio_valid_candidate?(t), do: ReconstructedAlert.temporarily_override_alert(t)

def audio_view(t),
do:
if(ReconstructedAlert.widget_type(t) === :reconstructed_large_alert,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
is_full_screen: true,
informed_stations_string: "Oak Grove"
informed_stations: ["Oak Grove"]
},
expected_common_data
),
Expand All @@ -187,7 +187,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
informed_entities: [ie(stop: "place-mlmnl")],
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
informed_stations_string: "Malden Center"
informed_stations: ["Malden Center"]
},
expected_common_data
),
Expand All @@ -200,7 +200,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
is_full_screen: false,
informed_stations_string: ""
informed_stations: []
},
expected_common_data
)
Expand Down Expand Up @@ -267,7 +267,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
is_full_screen: true,
informed_stations_string: "Malden Center"
informed_stations: ["Malden Center"]
},
expected_common_data
),
Expand All @@ -280,7 +280,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
is_full_screen: true,
informed_stations_string: ""
informed_stations: []
},
expected_common_data
),
Expand All @@ -292,7 +292,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
informed_entities: [ie(stop: "place-astao")],
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
informed_stations_string: "Assembly"
informed_stations: ["Assembly"]
},
expected_common_data
)
Expand Down Expand Up @@ -349,7 +349,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
is_full_screen: true,
informed_stations_string: ""
informed_stations: []
},
expected_common_data
)
Expand Down Expand Up @@ -429,7 +429,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
screen: config,
location_context: location_context,
now: now,
informed_stations_string: "",
informed_stations: [],
is_terminal_station: true
}

Expand Down Expand Up @@ -508,7 +508,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
informed_entities: [ie(stop: "place-ogmnl", direction_id: 0)],
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
informed_stations_string: ""
informed_stations: []
},
expected_common_data
),
Expand All @@ -520,7 +520,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ReconstructedAlertTest do
informed_entities: [ie(stop: "place-ogmnl")],
active_period: [{~U[2020-12-31T00:00:00Z], ~U[2021-01-02T00:00:00Z]}]
},
informed_stations_string: ""
informed_stations: []
},
expected_common_data
)
Expand Down
86 changes: 52 additions & 34 deletions test/screens/v2/widget_instance/reconstructed_alert_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
}
end

defp put_informed_stations_string(widget, string) do
%{widget | informed_stations_string: string}
defp put_informed_stations(widget, stations) do
%{widget | informed_stations: stations}
end

defp put_app_id(widget, app_id) do
Expand Down Expand Up @@ -167,7 +167,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
widget
|> put_home_stop(PreFare, home_stop)
|> put_stop_sequences(stop_sequences)
|> put_informed_stations_string("Downtown Crossing")
|> put_informed_stations(["Downtown Crossing"])
|> put_routes_at_stop(routes)

%{widget: widget}
Expand Down Expand Up @@ -200,7 +200,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
widget
|> put_home_stop(PreFare, home_stop)
|> put_stop_sequences(stop_sequences)
|> put_informed_stations_string("Malden Center")
|> put_informed_stations(["Malden Center"])
|> put_routes_at_stop(routes)

%{widget: widget}
Expand Down Expand Up @@ -239,7 +239,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
end

defp setup_informed_entities_string(%{widget: widget}) do
%{widget: put_informed_stations_string(widget, "Downtown Crossing")}
%{widget: put_informed_stations(widget, ["Downtown Crossing"])}
end

defp setup_location_context(%{widget: widget}) do
Expand Down Expand Up @@ -497,7 +497,9 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
effect: :shuttle,
remedy: "Use shuttle bus",
updated_at: "Friday, 5:00 am",
routes: [%{color: :orange, text: "ORANGE LINE", type: :text}]
routes: [%{color: :orange, text: "ORANGE LINE", type: :text}],
# Odd range, but not a normal alert situation
endpoints: {"Malden Center", "Malden Center"}
}

assert expected == ReconstructedAlert.serialize(widget)
Expand All @@ -520,7 +522,8 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
effect: :station_closure,
remedy: "Seek alternate route",
updated_at: "Friday, 5:00 am",
routes: [%{color: :orange, text: "ORANGE LINE", type: :text}]
routes: [%{color: :orange, text: "ORANGE LINE", type: :text}],
other_closures: ["Malden Center"]
}

assert expected == ReconstructedAlert.serialize(widget)
Expand Down Expand Up @@ -593,7 +596,8 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
effect: :shuttle,
remedy: "Use shuttle bus",
updated_at: "Friday, 5:00 am",
routes: [%{color: :orange, text: "ORANGE LINE", type: :text}]
routes: [%{color: :orange, text: "ORANGE LINE", type: :text}],
endpoints: {"Oak Grove", "Malden Center"}
}

assert expected == ReconstructedAlert.serialize(widget)
Expand All @@ -618,12 +622,13 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
issue: "No trains to Oak Grove",
location: "No Orange Line trains between Oak Grove and Malden Center",
cause: nil,
routes: ["ol-oak-grove"],
routes: [%{headsign: "Oak Grove", route_id: "Orange", svg_name: "ol-oak-grove"}],
effect: :suspension,
remedy: "Seek alternate route",
updated_at: "Friday, 5:00 am",
region: :boundary,
endpoints: {"Oak Grove", "Malden Center"}
endpoints: {"Oak Grove", "Malden Center"},
is_transfer_station: false
}

assert expected == ReconstructedAlert.serialize(widget)
Expand All @@ -644,12 +649,13 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
issue: "No trains to Oak Grove",
location: "Shuttle buses between Oak Grove and Malden Center",
cause: nil,
routes: ["ol-oak-grove"],
routes: [%{headsign: "Oak Grove", route_id: "Orange", svg_name: "ol-oak-grove"}],
effect: :shuttle,
remedy: "Use shuttle bus",
updated_at: "Friday, 5:00 am",
region: :boundary,
endpoints: {"Oak Grove", "Malden Center"}
endpoints: {"Oak Grove", "Malden Center"},
is_transfer_station: false
}

assert expected == ReconstructedAlert.serialize(widget)
Expand All @@ -670,7 +676,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
expected = %{
issue: "Trains may be delayed up to 20 minutes",
cause: nil,
routes: ["ol"],
routes: [%{route_id: "Orange", svg_name: "ol"}],
effect: :delay,
remedy: "Delays are happening",
updated_at: "Friday, 5:00 am",
Expand All @@ -695,7 +701,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
expected = %{
issue: "Trains may be delayed over 60 minutes",
cause: nil,
routes: ["ol"],
routes: [%{route_id: "Orange", svg_name: "ol"}],
effect: :delay,
remedy: "Delays are happening",
updated_at: "Friday, 5:00 am",
Expand All @@ -720,7 +726,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
expected = %{
issue: "Trains may be delayed up to 20 minutes",
cause: nil,
routes: ["ol-forest-hills"],
routes: [%{headsign: "Forest Hills", route_id: "Orange", svg_name: "ol-forest-hills"}],
effect: :delay,
remedy: "Delays are happening",
updated_at: "Friday, 5:00 am",
Expand All @@ -745,7 +751,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
expected = %{
issue: "Trains may be delayed over 60 minutes",
cause: :construction,
routes: ["ol"],
routes: [%{route_id: "Orange", svg_name: "ol"}],
effect: :delay,
remedy: "Delays are happening",
updated_at: "Friday, 5:00 am",
Expand All @@ -770,7 +776,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
expected = %{
issue: "Trains may be delayed over 60 minutes",
cause: nil,
routes: ["ol"],
routes: [%{route_id: "Orange", svg_name: "ol"}],
effect: :delay,
remedy: "Delays are happening",
updated_at: "Friday, 5:00 am",
Expand All @@ -794,12 +800,13 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
issue: "No trains",
location: nil,
cause: nil,
routes: ["ol-forest-hills"],
routes: [%{headsign: "Forest Hills", route_id: "Orange", svg_name: "ol-forest-hills"}],
effect: :shuttle,
remedy: "Shuttle buses available",
updated_at: "Friday, 5:00 am",
region: :outside,
endpoints: {"Wellington", "Wellington"}
endpoints: {"Wellington", "Wellington"},
is_transfer_station: false
}

assert expected == ReconstructedAlert.serialize(widget)
Expand All @@ -820,12 +827,13 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
issue: "No trains",
location: nil,
cause: nil,
routes: ["ol-forest-hills"],
routes: [%{headsign: "Forest Hills", route_id: "Orange", svg_name: "ol-forest-hills"}],
effect: :suspension,
remedy: "Seek alternate route",
updated_at: "Friday, 5:00 am",
region: :outside,
endpoints: {"Wellington", "Assembly"}
endpoints: {"Wellington", "Assembly"},
is_transfer_station: false
}

assert expected == ReconstructedAlert.serialize(widget)
Expand All @@ -846,10 +854,10 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
|> put_is_full_screen(true)

expected = %{
issue: ["orange"],
unaffected_routes: ["red"],
issue: nil,
unaffected_routes: [%{route_id: "Red", svg_name: "rl"}],
cause: nil,
routes: ["ol"],
routes: [%{route_id: "Orange", svg_name: "ol"}],
effect: :station_closure,
updated_at: "Friday, 5:00 am",
region: :here
Expand All @@ -873,11 +881,12 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
remedy: "Seek alternate route",
cause: nil,
location: "No Orange Line trains at Downtown Crossing",
routes: ["ol"],
routes: [%{route_id: "Orange", svg_name: "ol"}],
effect: :suspension,
updated_at: "Friday, 5:00 am",
region: :here,
endpoints: {"Downtown Crossing", "Downtown Crossing"}
endpoints: {"Downtown Crossing", "Downtown Crossing"},
is_transfer_station: true
}

assert expected == ReconstructedAlert.serialize(widget)
Expand All @@ -898,11 +907,12 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
remedy: "Use shuttle bus",
cause: nil,
location: "Shuttle buses at Downtown Crossing",
routes: ["ol"],
routes: [%{route_id: "Orange", svg_name: "ol"}],
effect: :shuttle,
updated_at: "Friday, 5:00 am",
region: :here,
endpoints: {"Downtown Crossing", "Downtown Crossing"}
endpoints: {"Downtown Crossing", "Downtown Crossing"},
is_transfer_station: true
}

assert expected == ReconstructedAlert.serialize(widget)
Expand Down Expand Up @@ -1220,7 +1230,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
ie(stop: "place-welln", route: "Orange", route_type: 1)
])
|> put_cause(:unknown)
|> put_informed_stations_string("Wellington")
|> put_informed_stations(["Wellington"])

expected = %{
issue: "Trains will bypass Wellington",
Expand Down Expand Up @@ -1270,7 +1280,7 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
ie(stop: "place-welln", route: "Orange", route_type: 1)
])
|> put_cause(:construction)
|> put_informed_stations_string("Wellington")
|> put_informed_stations(["Wellington"])

expected = %{
issue: "Trains will bypass Wellington",
Expand Down Expand Up @@ -1649,12 +1659,13 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
issue: "No trains",
location: nil,
cause: nil,
routes: ["ol-forest-hills"],
routes: [%{headsign: "Forest Hills", route_id: "Orange", svg_name: "ol-forest-hills"}],
effect: :suspension,
remedy: "Seek alternate route",
updated_at: "Friday, 5:14 am",
region: :outside,
endpoints: {"North Station", "Back Bay"}
endpoints: {"North Station", "Back Bay"},
is_transfer_station: false
}

assert expected == ReconstructedAlert.serialize(alert_widget)
Expand Down Expand Up @@ -2033,12 +2044,19 @@ defmodule Screens.V2.WidgetInstance.ReconstructedAlertTest do
issue: "No trains to North Station & North",
location: "Shuttle buses between Union Square and Government Center",
cause: nil,
routes: ["gl-north-station-north"],
routes: [
%{
headsign: "North Station & North",
route_id: "Green",
svg_name: "gl-north-station-north"
}
],
effect: :shuttle,
remedy: "Use shuttle bus",
updated_at: "Friday, 2:24 pm",
region: :boundary,
endpoints: {"Union Square", "Government Center"}
endpoints: {"Union Square", "Government Center"},
is_transfer_station: false
}

assert expected == ReconstructedAlert.serialize(alert_widget)
Expand Down

0 comments on commit 7aad68b

Please sign in to comment.