Skip to content

Commit

Permalink
Credo and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Oct 16, 2024
1 parent 1c2d9f7 commit 79cf319
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/screens/v2/widget_instance/elevator_closures.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
defmodule Screens.V2.WidgetInstance.ElevatorClosures do
@moduledoc false

alias Screens.Alerts.Alert
alias ScreensConfig.Screen
alias ScreensConfig.V2.Elevator
alias Screens.Alerts.Alert

defstruct screen: nil,
alerts: nil,
Expand Down
71 changes: 71 additions & 0 deletions test/screens/v2/widget_instance/elevator_closures_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do
use ExUnit.Case, async: true

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

setup do
%{
instance: %ElevatorClosures{
screen: struct(Screen, %{app_params: %Elevator{elevator_id: "111"}}),
time: ~U[2024-10-16T09:00:00Z],
alerts: []
}
}
end

describe "priority/1" do
test "returns 1", %{instance: instance} do
assert [1] == WidgetInstance.priority(instance)
end
end

describe "serialize/1" do
test "returns map with id, alerts, and time", %{instance: instance} do
assert %{
id: "111",
time: DateTime.to_iso8601(~U[2024-10-16T09:00:00Z]),
in_station_alerts: [],
outside_alerts: []
} == WidgetInstance.serialize(instance)
end
end

describe "slot_names/1" do
test "returns main_content", %{instance: instance} do
assert [:main_content] == WidgetInstance.slot_names(instance)
end
end

describe "widget_type/1" do
test "returns elevator_closures", %{instance: instance} do
assert :elevator_closures == WidgetInstance.widget_type(instance)
end
end

describe "audio_serialize/1" do
test "returns empty map", %{instance: instance} do
assert %{} == WidgetInstance.audio_serialize(instance)
end
end

describe "audio_sort_key/1" do
test "returns [0]", %{instance: instance} do
assert [0] == WidgetInstance.audio_sort_key(instance)
end
end

describe "audio_valid_candidate?/1" do
test "returns false", %{instance: instance} do
refute WidgetInstance.audio_valid_candidate?(instance)
end
end

describe "audio_view/1" do
test "returns ElevatorClosuresView", %{instance: instance} do
assert ScreensWeb.V2.Audio.ElevatorClosuresView == WidgetInstance.audio_view(instance)
end
end
end

0 comments on commit 79cf319

Please sign in to comment.