-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial widgets for new DUP logic
Rather than being entirely placeholders, the `new_departures` DUP variant now generates header and evergreen content widgets that should work identically to the base variant. The "departures" area is stubbed to always render a "no data" message.
- Loading branch information
1 parent
e920468
commit f0a1591
Showing
8 changed files
with
158 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Screens.V2.CandidateGenerator.DupNew.Departures do | ||
@moduledoc false | ||
|
||
alias Screens.V2.WidgetInstance.Departures, as: DeparturesWidget | ||
alias Screens.V2.WidgetInstance.{DeparturesNoData, OvernightDepartures} | ||
alias ScreensConfig.Screen | ||
|
||
@type widget :: DeparturesNoData.t() | DeparturesWidget.t() | OvernightDepartures.t() | ||
|
||
@spec instances(Screen.t(), DateTime.t()) :: [widget()] | ||
def instances(config, _now) do | ||
~w[ | ||
main_content_zero | ||
main_content_one | ||
main_content_two | ||
main_content_reduced_zero | ||
main_content_reduced_one | ||
main_content_reduced_two | ||
]a | ||
|> Enum.map(&%DeparturesNoData{screen: config, slot_name: &1}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Screens.V2.CandidateGenerator.DupNew.Header do | ||
@moduledoc false | ||
|
||
alias Screens.V2.WidgetInstance.NormalHeader | ||
alias ScreensConfig.Screen | ||
alias ScreensConfig.V2.Dup | ||
alias ScreensConfig.V2.Header.{CurrentStopId, CurrentStopName} | ||
|
||
@stop Application.compile_env( | ||
:screens, | ||
[Screens.V2.CandidateGenerator.DupNew, :stop_module], | ||
Screens.Stops.Stop | ||
) | ||
|
||
@spec instances(Screen.t(), DateTime.t()) :: [NormalHeader.t()] | ||
def instances(%Screen{app_params: %Dup{header: header_config}} = config, now) do | ||
# Generate one header for each of the 3 rotations. | ||
%NormalHeader{screen: config, icon: :logo, text: stop_name(header_config), time: now} | ||
|> List.duplicate(3) | ||
end | ||
|
||
defp stop_name(%CurrentStopName{stop_name: name}), do: name | ||
defp stop_name(%CurrentStopId{stop_id: stop_id}), do: @stop.fetch_stop_name(stop_id) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
defmodule Screens.V2.CandidateGenerator.DupNewTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ScreensConfig.Screen | ||
alias ScreensConfig.V2.{Alerts, Departures, EvergreenContentItem, Header, Schedule} | ||
alias ScreensConfig.V2.Dup, as: DupConfig | ||
alias Screens.Stops.MockStop | ||
alias Screens.Util.Assets | ||
alias Screens.V2.CandidateGenerator.DupNew | ||
alias Screens.V2.WidgetInstance.{DeparturesNoData, EvergreenContent, NormalHeader} | ||
|
||
import Mox | ||
setup :verify_on_exit! | ||
|
||
describe "candidate_instances/2" do | ||
@config %Screen{ | ||
app_id: :dup_v2, | ||
app_params: %DupConfig{ | ||
alerts: %Alerts{stop_id: "place-abcde"}, | ||
header: %Header.CurrentStopName{stop_name: "Test Stop"}, | ||
primary_departures: %Departures{sections: []}, | ||
secondary_departures: %Departures{sections: []} | ||
}, | ||
vendor: :outfront, | ||
device_id: "TEST", | ||
name: "TEST" | ||
} | ||
@now ~U[2024-01-15 11:45:30Z] | ||
|
||
test "returns expected header instances" do | ||
expected_header = %NormalHeader{screen: @config, icon: :logo, text: "Test Stop", time: @now} | ||
|
||
instances = DupNew.candidate_instances(@config, @now) | ||
|
||
assert Enum.filter(instances, &is_struct(&1, NormalHeader)) == | ||
List.duplicate(expected_header, 3) | ||
end | ||
|
||
test "returns header with stop name determined from stop ID" do | ||
config = put_in(@config.app_params.header, %Header.CurrentStopId{stop_id: "test_id"}) | ||
expect(MockStop, :fetch_stop_name, fn "test_id" -> "Test Name" end) | ||
|
||
instances = DupNew.candidate_instances(config, @now) | ||
|
||
assert %NormalHeader{text: "Test Name"} = Enum.find(instances, &is_struct(&1, NormalHeader)) | ||
end | ||
|
||
test "returns evergreen content when scheduled" do | ||
schedule = %Schedule{start_dt: ~U[2024-01-01 00:00:00Z], end_dt: ~U[2024-02-01 00:00:00Z]} | ||
|
||
item = %EvergreenContentItem{ | ||
asset_path: "test.png", | ||
priority: [1], | ||
schedule: [schedule], | ||
slot_names: ["bottom_pane_zero"] | ||
} | ||
|
||
config = put_in(@config.app_params.evergreen_content, [item]) | ||
now_active = ~U[2024-01-10 00:00:00Z] | ||
now_inactive = ~U[2024-02-02 00:00:00Z] | ||
|
||
expected_instance = %EvergreenContent{ | ||
screen: config, | ||
asset_url: Assets.s3_asset_url("test.png"), | ||
now: now_active, | ||
priority: [1], | ||
schedule: [schedule], | ||
slot_names: [:bottom_pane_zero] | ||
} | ||
|
||
assert expected_instance in DupNew.candidate_instances(config, now_active) | ||
assert expected_instance not in DupNew.candidate_instances(config, now_inactive) | ||
end | ||
|
||
test "stub: always returns no-data state for departures" do | ||
expected_instance = %DeparturesNoData{screen: @config, slot_name: :main_content_zero} | ||
assert expected_instance in DupNew.candidate_instances(@config, @now) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Mox.defmock(Screens.Config.MockCache, for: Screens.Config.Cache) | ||
Mox.defmock(Screens.Stops.MockStop, for: Screens.Stops.Stop) | ||
Mox.defmock(Screens.V2.ScreenData.MockParameters, for: Screens.V2.ScreenData.Parameters) |