Skip to content

Commit

Permalink
add routes to test signs (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
panentheos authored Jun 11, 2024
1 parent 12153df commit 09661b8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
3 changes: 2 additions & 1 deletion lib/signs/utilities/source_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ defmodule Signs.Utilities.SourceConfig do
@enforce_keys [
:stop_id,
:direction_id,
:routes,
:platform,
:terminal?,
:announce_arriving?,
:announce_boarding?
]
defstruct @enforce_keys ++
[:routes, :headway_stop_id, multi_berth?: false]
[:headway_stop_id, multi_berth?: false]

@type source :: %__MODULE__{
stop_id: String.t(),
Expand Down
82 changes: 43 additions & 39 deletions test/signs/realtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Signs.RealtimeTest do
@src %Signs.Utilities.SourceConfig{
stop_id: "1",
direction_id: 0,
routes: ["Red"],
platform: nil,
terminal?: false,
announce_arriving?: true,
Expand All @@ -17,6 +18,7 @@ defmodule Signs.RealtimeTest do
@src_2 %Signs.Utilities.SourceConfig{
stop_id: "2",
direction_id: 0,
routes: ["Red"],
platform: nil,
terminal?: false,
announce_arriving?: true,
Expand Down Expand Up @@ -58,25 +60,21 @@ defmodule Signs.RealtimeTest do
%{sources: [@src], headway_group: "group", headway_destination: :northbound},
%{sources: [@src_2], headway_group: "group", headway_destination: :southbound}
},
current_content_top: "Trains",
current_content_top: "Red line trains",
current_content_bottom: "Every 11 to 13 min"
}

@mezzanine_sign_with_routes %{
@mezzanine_sign
@multi_route_mezzanine_sign %{
@sign
| source_config: {
%{
sources: [%{@src | routes: ["Orange"]}],
headway_group: "group",
headway_destination: :northbound
},
%{
sources: [%{@src_2 | routes: ["Orange"]}],
headway_group: "group",
headway_destination: :southbound
}
%{sources: [@src_2], headway_group: "group", headway_destination: :southbound}
},
current_content_top: "Orange line trains",
current_content_top: "Trains",
current_content_bottom: "Every 11 to 13 min"
}

Expand Down Expand Up @@ -104,7 +102,7 @@ defmodule Signs.RealtimeTest do
}
}

@no_service_audio {:canned, {"107", ["861", "21000", "864", "21000", "863"], :audio}}
@no_service_audio {:canned, {"107", ["861", "21000", "3005", "21000", "863"], :audio}}

setup :verify_on_exit!

Expand Down Expand Up @@ -244,36 +242,47 @@ defmodule Signs.RealtimeTest do

test "when sign is at a station closed by shuttles and there are no predictions, it says so" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_closed_station end)
expect_messages({"No train service", "Use shuttle bus"})
expect_messages({"No Red Line", "Use shuttle bus"})

expect_audios([{:canned, {"199", ["864"], :audio}}], [
{"There is no train service at this station. Use shuttle.", nil}
expect_audios([{:canned, {"199", ["3005"], :audio}}], [
{"There is no Red Line service at this station. Use shuttle.", nil}
])

Signs.Realtime.handle_info(:run_loop, @sign)
end

test "when sign is at a station closed and there are no predictions, but shuttles do not run at this station" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_closed_station end)
expect_messages({"No train service", ""})
expect_audios([@no_service_audio], [{"There is no train service at this station.", nil}])
expect_messages({"No Red Line", ""})
expect_audios([@no_service_audio], [{"There is no Red Line service at this station.", nil}])
Signs.Realtime.handle_info(:run_loop, %{@sign | uses_shuttles: false})
end

test "when sign is at a station closed due to suspension and there are no predictions, it says so" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :suspension_closed_station end)
expect_messages({"No train service", ""})
expect_audios([@no_service_audio], [{"There is no train service at this station.", nil}])
expect_messages({"No Red Line", ""})
expect_audios([@no_service_audio], [{"There is no Red Line service at this station.", nil}])
Signs.Realtime.handle_info(:run_loop, @sign)
end

test "when sign is at a closed station and there are no predictions, it says so" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :station_closure end)
expect_messages({"No train service", ""})
expect_audios([@no_service_audio], [{"There is no train service at this station.", nil}])
expect_messages({"No Red Line", ""})
expect_audios([@no_service_audio], [{"There is no Red Line service at this station.", nil}])
assert {_, %{announced_alert: true}} = Signs.Realtime.handle_info(:run_loop, @sign)
end

test "multi-route mezzanine sign with alert" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :station_closure end)
expect_messages({"No train service", ""})

expect_audios([{:canned, {"107", ["861", "21000", "864", "21000", "863"], :audio}}], [
{"There is no train service at this station.", nil}
])

Signs.Realtime.handle_info(:run_loop, @multi_route_mezzanine_sign)
end

test "predictions take precedence over alerts" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :suspension_closed_station end)

Expand Down Expand Up @@ -341,8 +350,8 @@ defmodule Signs.RealtimeTest do
end)

expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :station_closure end)
expect_messages({"No train service", ""})
expect_audios([@no_service_audio], [{"There is no train service at this station.", nil}])
expect_messages({"No Red Line", ""})
expect_audios([@no_service_audio], [{"There is no Red Line service at this station.", nil}])
Signs.Realtime.handle_info(:run_loop, @sign)
end

Expand All @@ -363,7 +372,7 @@ defmodule Signs.RealtimeTest do
%{@headway_config | range_high: 14}
end)

expect_messages({"Trains", "Every 11 to 14 min"})
expect_messages({"Red line trains", "Every 11 to 14 min"})
Signs.Realtime.handle_info(:run_loop, @mezzanine_sign)
end

Expand Down Expand Up @@ -964,10 +973,10 @@ defmodule Signs.RealtimeTest do

test "reads alerts" do
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_closed_station end)
expect_messages({"No train service", "Use shuttle bus"})
expect_messages({"No Red Line", "Use shuttle bus"})

expect_audios([{:canned, {"199", ["864"], :audio}}], [
{"There is no train service at this station. Use shuttle.", nil}
expect_audios([{:canned, {"199", ["3005"], :audio}}], [
{"There is no Red Line service at this station. Use shuttle.", nil}
])

Signs.Realtime.handle_info(:run_loop, %{@sign | tick_read: 0, announced_alert: true})
Expand Down Expand Up @@ -1358,7 +1367,7 @@ defmodule Signs.RealtimeTest do
%{@headway_config | range_low: 9}
end)

expect_messages({"Trains", "Every 9 to 13 min"})
expect_messages({"Red line trains", "Every 9 to 13 min"})

Signs.Realtime.handle_info(:run_loop, %{
@mezzanine_sign
Expand Down Expand Up @@ -1448,7 +1457,7 @@ defmodule Signs.RealtimeTest do
]
end)

expect_messages({"Trains", "Every 11 to 13 min"})
expect_messages({"Red line trains", "Every 11 to 13 min"})

Signs.Realtime.handle_info(:run_loop, %{
@jfk_mezzanine_sign
Expand Down Expand Up @@ -1625,30 +1634,25 @@ defmodule Signs.RealtimeTest do
Signs.Realtime.handle_info(:run_loop, sign)
end

test "Station is closed" do
sign = %{
@mezzanine_sign
| tick_read: 0
}

test "multi-route mezzanine sign, both sides closed" do
expect_messages({"Station closed", "Service ended for night"})

expect_audios([{:canned, {"105", ["864", "21000", "882"], :audio}}], [
{"This station is closed. Service has ended for the night.", nil}
])

Signs.Realtime.handle_info(:run_loop, sign)
Signs.Realtime.handle_info(:run_loop, %{@multi_route_mezzanine_sign | tick_read: 0})
end

test "Station with routes is closed" do
test "single-route mezzanine sign, both sides closed" do
sign = %{
@mezzanine_sign_with_routes
@mezzanine_sign
| tick_read: 0
}

expect_messages({"No Orange Line", "Service ended for night"})
expect_messages({"No Red Line", "Service ended for night"})

expect_audios([{:canned, {"105", ["3006", "21000", "882"], :audio}}], [
expect_audios([{:canned, {"105", ["3005", "21000", "882"], :audio}}], [
{"This station is closed. Service has ended for the night.", nil}
])

Expand All @@ -1657,7 +1661,7 @@ defmodule Signs.RealtimeTest do

test "No service goes on bottom line when top line fits in 18 chars or less" do
sign = %{
@mezzanine_sign_with_routes
@mezzanine_sign
| tick_read: 0,
announced_stalls: [{"a", 8}]
}
Expand Down

0 comments on commit 09661b8

Please sign in to comment.