Skip to content

Commit

Permalink
Test improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Nov 26, 2024
1 parent 1d0be22 commit a2a70bc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
34 changes: 22 additions & 12 deletions test/screens/v2/candidate_generator/elevator/closures_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do
@stop injected(Stop)

describe "elevator_status_instances/1" do
test "Only returns alerts with effect of :elevator_closure" do
setup do
%{
config: %Elevator{
elevator_id: "111",
accessible_path_direction_arrow: :n,
alternate_direction_text: "Test"
}
}
end

test "Only returns alerts with effect of :elevator_closure", %{config: config} do
expect(@facility, :fetch_stop_for_facility, fn "111" -> {:ok, %Stop{id: "place-test"}} end)

expect(@stop, :fetch_parent_station_name_map, fn ->
Expand Down Expand Up @@ -51,7 +61,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do

[
%Screens.V2.WidgetInstance.ElevatorClosures{
id: "111",
elevator_config: ^config,
in_station_closures: [
%{
id: "1",
Expand All @@ -65,11 +75,11 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do
}
] =
ElevatorClosures.elevator_status_instances(
struct(Screen, app_id: :elevator_v2, app_params: %Elevator{elevator_id: "111"})
struct(Screen, app_id: :elevator_v2, app_params: config)
)
end

test "Groups outside closures by station" do
test "Groups outside closures by station", %{config: config} do
expect(@facility, :fetch_stop_for_facility, fn "111" -> {:ok, %Stop{id: "place-test"}} end)

expect(@stop, :fetch_parent_station_name_map, fn ->
Expand Down Expand Up @@ -107,7 +117,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do

[
%Screens.V2.WidgetInstance.ElevatorClosures{
id: "111",
elevator_config: ^config,
in_station_closures: [],
other_stations_with_closures: [
%{
Expand Down Expand Up @@ -135,11 +145,11 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do
}
] =
ElevatorClosures.elevator_status_instances(
struct(Screen, app_id: :elevator_v2, app_params: %Elevator{elevator_id: "111"})
struct(Screen, app_id: :elevator_v2, app_params: config)
)
end

test "Filters alerts with no facilities or more than one facility" do
test "Filters alerts with no facilities or more than one facility", %{config: config} do
expect(@facility, :fetch_stop_for_facility, fn "111" -> {:ok, %Stop{id: "place-test"}} end)

expect(@stop, :fetch_parent_station_name_map, fn ->
Expand Down Expand Up @@ -172,17 +182,17 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do

[
%Screens.V2.WidgetInstance.ElevatorClosures{
id: "111",
elevator_config: ^config,
in_station_closures: [],
other_stations_with_closures: []
}
] =
ElevatorClosures.elevator_status_instances(
struct(Screen, app_id: :elevator_v2, app_params: %Elevator{elevator_id: "111"})
struct(Screen, app_id: :elevator_v2, app_params: config)
)
end

test "Return empty routes on API error" do
test "Return empty routes on API error", %{config: config} do
expect(@facility, :fetch_stop_for_facility, fn "111" -> {:ok, %Stop{id: "place-test"}} end)

expect(@stop, :fetch_parent_station_name_map, fn ->
Expand All @@ -209,7 +219,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do

[
%Screens.V2.WidgetInstance.ElevatorClosures{
id: "111",
elevator_config: ^config,
in_station_closures: [
%{
id: "1",
Expand All @@ -223,7 +233,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do
}
] =
ElevatorClosures.elevator_status_instances(
struct(Screen, app_id: :elevator_v2, app_params: %Elevator{elevator_id: "111"})
struct(Screen, app_id: :elevator_v2, app_params: config)
)
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/screens/v2/candidate_generator/elevator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ defmodule Screens.V2.CandidateGenerator.ElevatorTest do
config = %Screen{
app_id: :elevator_v2,
app_params: %V2.Elevator{
elevator_id: "1"
elevator_id: "1",
alternate_direction_text: "Test",
accessible_path_direction_arrow: :n
},
device_id: "TEST",
name: "TEST",
Expand Down
20 changes: 18 additions & 2 deletions test/screens/v2/widget_instance/elevator_closures_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do

alias Screens.V2.WidgetInstance
alias Screens.V2.WidgetInstance.ElevatorClosures
alias ScreensConfig.V2.Elevator

setup do
%{
instance: %ElevatorClosures{
id: "111",
elevator_config:
struct(Elevator,
elevator_id: "1",
alternate_direction_text: "Test",
accessible_path_direction_arrow: :n
),
in_station_closures: [
%ElevatorClosures.Closure{
description: "Test Alert Description",
Expand Down Expand Up @@ -44,7 +50,17 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do

describe "serialize/1" do
test "returns map with id and closures", %{instance: instance} do
assert Map.from_struct(instance) == WidgetInstance.serialize(instance)
assert %{
in_station_closures: instance.in_station_closures,
other_stations_with_closures: instance.other_stations_with_closures,
accessible_path_direction_arrow:
instance.elevator_config.accessible_path_direction_arrow,
accessible_path_image_here_coordinates:
instance.elevator_config.accessible_path_image_here_coordinates,
accessible_path_image_url: instance.elevator_config.accessible_path_image_url,
alternate_direction_text: instance.elevator_config.alternate_direction_text,
id: instance.elevator_config.elevator_id
} == WidgetInstance.serialize(instance)
end
end

Expand Down

0 comments on commit a2a70bc

Please sign in to comment.