From f7ac378a0c1bebebd72cb69667ceefee7c306d18 Mon Sep 17 00:00:00 2001 From: cmaddox5 Date: Tue, 3 Dec 2024 12:42:28 -0500 Subject: [PATCH] Converted elevator components into separate widgets. --- assets/css/elevator_v2.scss | 45 +++++++++- ...view.scss => current_elevator_closed.scss} | 3 +- assets/css/v2/elevator/elevator_closures.scss | 42 ---------- ...ew.scss => outside_elevator_closures.scss} | 2 +- assets/src/apps/v2/elevator.tsx | 6 +- ...d_view.tsx => current_elevator_closed.tsx} | 34 ++++---- .../v2/elevator/elevator_closures.tsx | 80 ------------------ .../components/v2/elevator/models/closure.ts | 7 ++ .../components/v2/elevator/models/station.ts | 9 ++ ...view.tsx => outside_elevator_closures.tsx} | 29 ++++--- .../{closures => }/paging_indicators.tsx | 0 .../candidate_generator/elevator/closures.ex | 42 ++++++---- ...closures.ex => current_elevator_closed.ex} | 40 ++------- .../outside_elevator_closures.ex | 58 +++++++++++++ ...iew.ex => current_elevator_closed_view.ex} | 2 +- .../audio/outside_elevator_closures_view.ex | 7 ++ .../elevator/closures_test.exs | 77 +++++++++++++++-- .../current_elevator_closed_test.exs | 84 +++++++++++++++++++ ...exs => outside_elevator_closures_test.exs} | 27 +++--- 19 files changed, 374 insertions(+), 220 deletions(-) rename assets/css/v2/elevator/{closures/current_elevator_closed_view.scss => current_elevator_closed.scss} (97%) delete mode 100644 assets/css/v2/elevator/elevator_closures.scss rename assets/css/v2/elevator/{closures/outside_closures_view.scss => outside_elevator_closures.scss} (98%) rename assets/src/components/v2/elevator/{closures/current_elevator_closed_view.tsx => current_elevator_closed.tsx} (75%) delete mode 100644 assets/src/components/v2/elevator/elevator_closures.tsx create mode 100644 assets/src/components/v2/elevator/models/closure.ts create mode 100644 assets/src/components/v2/elevator/models/station.ts rename assets/src/components/v2/elevator/{closures/outside_closures_view.tsx => outside_elevator_closures.tsx} (84%) rename assets/src/components/v2/elevator/{closures => }/paging_indicators.tsx (100%) rename lib/screens/v2/widget_instance/{elevator_closures.ex => current_elevator_closed.ex} (58%) create mode 100644 lib/screens/v2/widget_instance/outside_elevator_closures.ex rename lib/screens_web/views/v2/audio/{elevator_closures_view.ex => current_elevator_closed_view.ex} (57%) create mode 100644 lib/screens_web/views/v2/audio/outside_elevator_closures_view.ex create mode 100644 test/screens/v2/widget_instance/current_elevator_closed_test.exs rename test/screens/v2/widget_instance/{elevator_closures_test.exs => outside_elevator_closures_test.exs} (69%) diff --git a/assets/css/elevator_v2.scss b/assets/css/elevator_v2.scss index e6bdfeaf5..06f089c72 100644 --- a/assets/css/elevator_v2.scss +++ b/assets/css/elevator_v2.scss @@ -5,7 +5,6 @@ @import "https://rsms.me/inter/inter.css"; @import "colors"; @import "v2/lcd_common/screen_container"; -@import "v2/elevator/elevator_closures"; @import "v2/elevator/normal"; @import "v2/simulation_common"; @import "v2/lcd_common/simulation"; @@ -42,3 +41,47 @@ body { background-color: $accessibility-blue; } } + +.outside-elevator-closures, +.current-elevator-closed { + position: relative; + display: flex; + flex-direction: column; + height: 100%; + color: $cool-black-15; + background-color: $warm-neutral-90; + + hr.thick { + min-height: 24px; + margin: 0; + background-color: $cool-black-15; + border: none; + } + + hr.thin { + min-height: 2px; + margin: 24px 0; + background-color: $true-grey-45; + border: none; + opacity: 0.5; + } + + .subheading { + font-size: 80px; + font-weight: 700; + line-height: 80px; + } +} + +.paging-indicators { + display: flex; + align-items: center; + margin-right: 66px; + + .paging-indicator:first-child:not(:only-child) { + margin-right: 27px; + } +} + +@import "v2/elevator/current_elevator_closed"; +@import "v2/elevator/outside_elevator_closures"; diff --git a/assets/css/v2/elevator/closures/current_elevator_closed_view.scss b/assets/css/v2/elevator/current_elevator_closed.scss similarity index 97% rename from assets/css/v2/elevator/closures/current_elevator_closed_view.scss rename to assets/css/v2/elevator/current_elevator_closed.scss index f3c3f0f78..acaa23595 100644 --- a/assets/css/v2/elevator/closures/current_elevator_closed_view.scss +++ b/assets/css/v2/elevator/current_elevator_closed.scss @@ -1,4 +1,4 @@ -.current-elevator-closed-view { +.current-elevator-closed { position: relative; height: 100%; @@ -91,6 +91,7 @@ .paging-indicators { position: absolute; right: 0; + bottom: 0; height: 120px; } } diff --git a/assets/css/v2/elevator/elevator_closures.scss b/assets/css/v2/elevator/elevator_closures.scss deleted file mode 100644 index 15fc556d1..000000000 --- a/assets/css/v2/elevator/elevator_closures.scss +++ /dev/null @@ -1,42 +0,0 @@ -.elevator-closures { - position: relative; - display: flex; - flex-direction: column; - height: 100%; - color: $cool-black-15; - background-color: $warm-neutral-90; - - hr.thick { - min-height: 24px; - margin: 0; - background-color: $cool-black-15; - border: none; - } - - hr.thin { - min-height: 2px; - margin: 24px 0; - background-color: $true-grey-45; - border: none; - opacity: 0.5; - } - - .subheading { - font-size: 80px; - font-weight: 700; - line-height: 80px; - } -} - -.paging-indicators { - display: flex; - align-items: center; - margin-right: 66px; - - .paging-indicator:first-child:not(:only-child) { - margin-right: 27px; - } -} - -@import "closures/current_elevator_closed_view"; -@import "closures/outside_closures_view"; diff --git a/assets/css/v2/elevator/closures/outside_closures_view.scss b/assets/css/v2/elevator/outside_elevator_closures.scss similarity index 98% rename from assets/css/v2/elevator/closures/outside_closures_view.scss rename to assets/css/v2/elevator/outside_elevator_closures.scss index 16de69558..077f6ce2a 100644 --- a/assets/css/v2/elevator/closures/outside_closures_view.scss +++ b/assets/css/v2/elevator/outside_elevator_closures.scss @@ -1,4 +1,4 @@ -.outside-closures-view { +.outside-elevator-closures { display: flex; flex: 1; flex-direction: column; diff --git a/assets/src/apps/v2/elevator.tsx b/assets/src/apps/v2/elevator.tsx index cea5a1e47..b43342a35 100644 --- a/assets/src/apps/v2/elevator.tsx +++ b/assets/src/apps/v2/elevator.tsx @@ -14,14 +14,16 @@ import EvergreenContent from "Components/v2/evergreen_content"; import ScreenPage from "Components/v2/screen_page"; import { MappingContext } from "Components/v2/widget"; import MultiScreenPage from "Components/v2/multi_screen_page"; -import ElevatorClosures from "Components/v2/elevator/elevator_closures"; +import OutsideElevatorClosures from "Components/v2/elevator/outside_elevator_closures"; +import CurrentElevatorClosed from "Components/v2/elevator/current_elevator_closed"; import SimulationScreenPage from "Components/v2/simulation_screen_page"; import Footer from "Components/v2/elevator/footer"; import NormalHeader from "Components/v2/normal_header"; const TYPE_TO_COMPONENT = { normal: NormalScreen, - elevator_closures: ElevatorClosures, + outside_elevator_closures: OutsideElevatorClosures, + current_elevator_closed: CurrentElevatorClosed, evergreen_content: EvergreenContent, footer: Footer, normal_header: NormalHeader, diff --git a/assets/src/components/v2/elevator/closures/current_elevator_closed_view.tsx b/assets/src/components/v2/elevator/current_elevator_closed.tsx similarity index 75% rename from assets/src/components/v2/elevator/closures/current_elevator_closed_view.tsx rename to assets/src/components/v2/elevator/current_elevator_closed.tsx index 2adf6c9d4..4350ee8a2 100644 --- a/assets/src/components/v2/elevator/closures/current_elevator_closed_view.tsx +++ b/assets/src/components/v2/elevator/current_elevator_closed.tsx @@ -1,9 +1,11 @@ -import React from "react"; +import React, { ComponentType } from "react"; import cx from "classnames"; import Arrow, { Direction } from "Components/v2/arrow"; -import { WrappedComponentProps } from "Components/v2/persistent_wrapper"; -import PagingIndicators from "Components/v2/elevator/closures/paging_indicators"; -import { type ElevatorClosure } from "Components/v2/elevator/elevator_closures"; +import makePersistent, { + WrappedComponentProps, +} from "Components/v2/persistent_wrapper"; +import PagingIndicators from "Components/v2/elevator/paging_indicators"; +import { type Closure } from "Components/v2/elevator/models/closure"; import useClientPaging from "Hooks/v2/use_client_paging"; import useTextResizer from "Hooks/v2/use_text_resizer"; import CurrentLocationMarker from "Images/svgr_bundled/current-location-marker.svg"; @@ -27,18 +29,18 @@ const PulsatingDot = ({ x, y }: Coordinates) => { }; interface CurrentElevatorClosedViewProps extends WrappedComponentProps { - closure: ElevatorClosure; - alternateDirectionText: string; - accessiblePathDirectionArrow: Direction; - accessiblePathImageUrl: string | null; - accessiblePathImageHereCoordinates: Coordinates; + closure: Closure; + alternate_direction_text: string; + accessible_path_direction_arrow: Direction; + accessible_path_image_url: string | null; + accessible_path_image_here_coordinates: Coordinates; } const CurrentElevatorClosedView = ({ - alternateDirectionText, - accessiblePathDirectionArrow, - accessiblePathImageUrl, - accessiblePathImageHereCoordinates, + alternate_direction_text: alternateDirectionText, + accessible_path_direction_arrow: accessiblePathDirectionArrow, + accessible_path_image_url: accessiblePathImageUrl, + accessible_path_image_here_coordinates: accessiblePathImageHereCoordinates, onFinish, lastUpdate, }: CurrentElevatorClosedViewProps) => { @@ -51,7 +53,7 @@ const CurrentElevatorClosedView = ({ }); return ( -
+
@@ -91,4 +93,6 @@ const CurrentElevatorClosedView = ({ ); }; -export default CurrentElevatorClosedView; +export default makePersistent( + CurrentElevatorClosedView as ComponentType, +); diff --git a/assets/src/components/v2/elevator/elevator_closures.tsx b/assets/src/components/v2/elevator/elevator_closures.tsx deleted file mode 100644 index 3f414a7fa..000000000 --- a/assets/src/components/v2/elevator/elevator_closures.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import React, { ComponentType } from "react"; -import _ from "lodash"; -import makePersistent, { - WrappedComponentProps, -} from "Components/v2/persistent_wrapper"; -import { type Pill } from "Components/v2/departures/route_pill"; -import { Direction } from "Components/v2/arrow"; -import OutsideClosuresView from "Components/v2/elevator/closures/outside_closures_view"; -import CurrentElevatorClosedView, { - type Coordinates, -} from "Components/v2/elevator/closures/current_elevator_closed_view"; - -export type StationWithClosures = { - id: string; - name: string; - route_icons: Pill[]; - closures: ElevatorClosure[]; -}; - -export type ElevatorClosure = { - id: string; - elevator_name: string; - elevator_id: string; - description: string; - header_text: string; -}; - -interface Props extends WrappedComponentProps { - id: string; - in_station_closures: ElevatorClosure[]; - other_stations_with_closures: StationWithClosures[]; - alternate_direction_text: string; - accessible_path_direction_arrow: Direction; - accessible_path_image_url: string | null; - accessible_path_image_here_coordinates: Coordinates; -} - -const ElevatorClosures: React.ComponentType = ({ - id, - other_stations_with_closures: otherStationsWithClosures, - in_station_closures: inStationClosures, - alternate_direction_text: alternateDirectionText, - accessible_path_direction_arrow: accessiblePathDirectionArrow, - accessible_path_image_url: accessiblePathImageUrl, - accessible_path_image_here_coordinates: accessiblePathImageHereCoordinates, - lastUpdate, - onFinish, -}: Props) => { - const currentElevatorClosure = inStationClosures.find( - (c) => c.elevator_id === id, - ); - - return ( -
- {currentElevatorClosure ? ( - - ) : ( - - )} -
- ); -}; - -export default makePersistent( - ElevatorClosures as ComponentType, -); diff --git a/assets/src/components/v2/elevator/models/closure.ts b/assets/src/components/v2/elevator/models/closure.ts new file mode 100644 index 000000000..44158fac6 --- /dev/null +++ b/assets/src/components/v2/elevator/models/closure.ts @@ -0,0 +1,7 @@ +export type Closure = { + id: string; + elevator_name: string; + elevator_id: string; + description: string; + header_text: string; +}; diff --git a/assets/src/components/v2/elevator/models/station.ts b/assets/src/components/v2/elevator/models/station.ts new file mode 100644 index 000000000..259cc1b3f --- /dev/null +++ b/assets/src/components/v2/elevator/models/station.ts @@ -0,0 +1,9 @@ +import { type Pill } from "Components/v2/departures/route_pill"; +import { type Closure } from "Components/v2/elevator/models/closure"; + +export type StationWithClosures = { + id: string; + name: string; + route_icons: Pill[]; + closures: Closure[]; +}; diff --git a/assets/src/components/v2/elevator/closures/outside_closures_view.tsx b/assets/src/components/v2/elevator/outside_elevator_closures.tsx similarity index 84% rename from assets/src/components/v2/elevator/closures/outside_closures_view.tsx rename to assets/src/components/v2/elevator/outside_elevator_closures.tsx index e5ab35210..a392a934f 100644 --- a/assets/src/components/v2/elevator/closures/outside_closures_view.tsx +++ b/assets/src/components/v2/elevator/outside_elevator_closures.tsx @@ -1,10 +1,13 @@ -import React, { useLayoutEffect, useRef, useState } from "react"; +import React, { ComponentType, useLayoutEffect, useRef, useState } from "react"; import cx from "classnames"; import _ from "lodash"; -import { type StationWithClosures } from "Components/v2/elevator/elevator_closures"; import RoutePill, { routePillKey } from "Components/v2/departures/route_pill"; -import { WrappedComponentProps } from "Components/v2/persistent_wrapper"; -import PagingIndicators from "Components/v2/elevator/closures/paging_indicators"; +import makePersistent, { + WrappedComponentProps, +} from "Components/v2/persistent_wrapper"; +import PagingIndicators from "Components/v2/elevator/paging_indicators"; +import { type StationWithClosures } from "Components/v2/elevator/models/station"; +import { type Closure } from "Components/v2/elevator/models/closure"; import useClientPaging from "Hooks/v2/use_client_paging"; import NormalService from "Images/svgr_bundled/normal-service.svg"; import AccessibilityAlert from "Images/svgr_bundled/accessibility-alert.svg"; @@ -137,15 +140,19 @@ const OutsideClosureList = ({ ); }; -interface OutsideClosuresViewProps extends OutsideClosureListProps {} +interface Props extends WrappedComponentProps { + id: string; + in_station_closures: Closure[]; + other_stations_with_closures: StationWithClosures[]; +} -const OutsideClosuresView = ({ - stations, +const OutsideElevatorClosures = ({ + other_stations_with_closures: stations, lastUpdate, onFinish, -}: OutsideClosuresViewProps) => { +}: Props) => { return ( -
+
, +); diff --git a/assets/src/components/v2/elevator/closures/paging_indicators.tsx b/assets/src/components/v2/elevator/paging_indicators.tsx similarity index 100% rename from assets/src/components/v2/elevator/closures/paging_indicators.tsx rename to assets/src/components/v2/elevator/paging_indicators.tsx diff --git a/lib/screens/v2/candidate_generator/elevator/closures.ex b/lib/screens/v2/candidate_generator/elevator/closures.ex index c57e4cccb..2b0bc9c19 100644 --- a/lib/screens/v2/candidate_generator/elevator/closures.ex +++ b/lib/screens/v2/candidate_generator/elevator/closures.ex @@ -6,7 +6,16 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do alias Screens.Alerts.{Alert, InformedEntity} alias Screens.Routes.Route alias Screens.Stops.Stop - alias Screens.V2.WidgetInstance.{ElevatorClosures, Footer, NormalHeader} + + alias Screens.V2.WidgetInstance + + alias Screens.V2.WidgetInstance.{ + CurrentElevatorClosed, + Footer, + NormalHeader, + OutsideElevatorClosures + } + alias Screens.V2.WidgetInstance.Serializer.RoutePill alias ScreensConfig.Screen alias ScreensConfig.V2.Elevator @@ -19,7 +28,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do @stop injected(Stop) @spec elevator_status_instances(Screen.t(), NormalHeader.t(), Footer.t()) :: - list(ElevatorClosures.t()) + list(WidgetInstance.t()) def elevator_status_instances( %Screen{app_params: %Elevator{elevator_id: elevator_id} = config}, header_instance, @@ -37,20 +46,23 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do in_station_closures = Enum.map(in_station_alerts, &alert_to_elevator_closure/1) - header_footer_variant = - if(Enum.any?(in_station_closures, &(&1.elevator_id == elevator_id)), - do: :closed, - else: nil - ) + current_elevator_closure = Enum.find(in_station_closures, &(&1.elevator_id == elevator_id)) + + {elevator_widget_instance, header_footer_variant} = + if is_nil(current_elevator_closure) do + {%OutsideElevatorClosures{ + in_station_closures: in_station_closures, + other_stations_with_closures: + format_outside_closures(outside_alerts, parent_station_map, routes_map), + app_params: config + }, nil} + else + {%CurrentElevatorClosed{closure: current_elevator_closure, app_params: config}, :closed} + end [ %NormalHeader{header_instance | variant: header_footer_variant}, - %ElevatorClosures{ - in_station_closures: in_station_closures, - other_stations_with_closures: - format_outside_closures(outside_alerts, parent_station_map, routes_map), - app_params: config - }, + elevator_widget_instance, %Footer{footer_instance | variant: header_footer_variant} ] else @@ -122,7 +134,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do }) do facility = Enum.find_value(entities, fn %{facility: facility} -> facility end) - %ElevatorClosures.Closure{ + %CurrentElevatorClosed.Closure{ id: id, elevator_name: facility.name, elevator_id: facility.id, @@ -142,7 +154,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do |> Map.fetch!(parent_station_id) |> Enum.map(&RoutePill.serialize_icon/1) - %ElevatorClosures.Station{ + %OutsideElevatorClosures.Station{ id: parent_station_id, name: Map.fetch!(station_id_to_name, parent_station_id), route_icons: route_pills, diff --git a/lib/screens/v2/widget_instance/elevator_closures.ex b/lib/screens/v2/widget_instance/current_elevator_closed.ex similarity index 58% rename from lib/screens/v2/widget_instance/elevator_closures.ex rename to lib/screens/v2/widget_instance/current_elevator_closed.ex index 9f81a0262..2a5905527 100644 --- a/lib/screens/v2/widget_instance/elevator_closures.ex +++ b/lib/screens/v2/widget_instance/current_elevator_closed.ex @@ -1,36 +1,16 @@ -defmodule Screens.V2.WidgetInstance.ElevatorClosures do +defmodule Screens.V2.WidgetInstance.CurrentElevatorClosed do @moduledoc false - alias Screens.Stops.Stop alias Screens.Util.Assets alias ScreensConfig.V2.Elevator - defstruct ~w[app_params in_station_closures other_stations_with_closures]a + defstruct ~w[app_params closure]a @type t :: %__MODULE__{ app_params: Elevator.t(), - in_station_closures: list(__MODULE__.Closure.t()), - other_stations_with_closures: list(__MODULE__.Station.t()) + closure: __MODULE__.Closure.t() } - defmodule Station do - @moduledoc false - - alias Screens.Routes.Route - alias Screens.V2.WidgetInstance.ElevatorClosures.Closure - - @derive Jason.Encoder - - defstruct ~w[id name route_icons closures]a - - @type t :: %__MODULE__{ - id: Stop.id(), - name: String.t(), - route_icons: list(Route.icon()), - closures: list(Closure.t()) - } - end - defmodule Closure do @moduledoc false @@ -55,13 +35,11 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosures do accessible_path_image_url: accessible_path_image_url, accessible_path_image_here_coordinates: accessible_path_image_here_coordinates }, - in_station_closures: in_station_closures, - other_stations_with_closures: other_stations_with_closures + closure: closure }), do: %{ id: id, - in_station_closures: in_station_closures, - other_stations_with_closures: other_stations_with_closures, + closure: closure, alternate_direction_text: alternate_direction_text, accessible_path_direction_arrow: accessible_path_direction_arrow, accessible_path_image_url: @@ -73,16 +51,16 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosures do } defimpl Screens.V2.WidgetInstance do - alias Screens.V2.WidgetInstance.ElevatorClosures + alias Screens.V2.WidgetInstance.CurrentElevatorClosed def priority(_instance), do: [1] - def serialize(instance), do: ElevatorClosures.serialize(instance) + def serialize(instance), do: CurrentElevatorClosed.serialize(instance) def slot_names(_instance), do: [:main_content] - def widget_type(_instance), do: :elevator_closures + def widget_type(_instance), do: :current_elevator_closed def valid_candidate?(_instance), do: true def audio_serialize(_instance), do: %{} def audio_sort_key(_instance), do: [0] def audio_valid_candidate?(_instance), do: false - def audio_view(_instance), do: ScreensWeb.V2.Audio.ElevatorClosuresView + def audio_view(_instance), do: ScreensWeb.V2.Audio.CurrentElevatorClosedView end end diff --git a/lib/screens/v2/widget_instance/outside_elevator_closures.ex b/lib/screens/v2/widget_instance/outside_elevator_closures.ex new file mode 100644 index 000000000..e3d4d14b6 --- /dev/null +++ b/lib/screens/v2/widget_instance/outside_elevator_closures.ex @@ -0,0 +1,58 @@ +defmodule Screens.V2.WidgetInstance.OutsideElevatorClosures do + @moduledoc false + + alias Screens.Stops.Stop + alias Screens.V2.WidgetInstance.CurrentElevatorClosed.Closure + alias ScreensConfig.V2.Elevator + + defstruct ~w[app_params in_station_closures other_stations_with_closures]a + + @type t :: %__MODULE__{ + app_params: Elevator.t(), + in_station_closures: list(Closure.t()), + other_stations_with_closures: list(__MODULE__.Station.t()) + } + + defmodule Station do + @moduledoc false + + alias Screens.Routes.Route + alias Screens.V2.WidgetInstance.CurrentElevatorClosed.Closure + + @derive Jason.Encoder + + defstruct ~w[id name route_icons closures]a + + @type t :: %__MODULE__{ + id: Stop.id(), + name: String.t(), + route_icons: list(Route.icon()), + closures: list(Closure.t()) + } + end + + def serialize(%__MODULE__{ + app_params: %Elevator{elevator_id: id}, + in_station_closures: in_station_closures, + other_stations_with_closures: other_stations_with_closures + }), + do: %{ + id: id, + in_station_closures: in_station_closures, + other_stations_with_closures: other_stations_with_closures + } + + defimpl Screens.V2.WidgetInstance do + alias Screens.V2.WidgetInstance.OutsideElevatorClosures + + def priority(_instance), do: [1] + def serialize(instance), do: OutsideElevatorClosures.serialize(instance) + def slot_names(_instance), do: [:main_content] + def widget_type(_instance), do: :outside_elevator_closures + def valid_candidate?(_instance), do: true + def audio_serialize(_instance), do: %{} + def audio_sort_key(_instance), do: [0] + def audio_valid_candidate?(_instance), do: false + def audio_view(_instance), do: ScreensWeb.V2.Audio.OutsideElevatorClosuresView + end +end diff --git a/lib/screens_web/views/v2/audio/elevator_closures_view.ex b/lib/screens_web/views/v2/audio/current_elevator_closed_view.ex similarity index 57% rename from lib/screens_web/views/v2/audio/elevator_closures_view.ex rename to lib/screens_web/views/v2/audio/current_elevator_closed_view.ex index 7bd732227..8060c80da 100644 --- a/lib/screens_web/views/v2/audio/elevator_closures_view.ex +++ b/lib/screens_web/views/v2/audio/current_elevator_closed_view.ex @@ -1,4 +1,4 @@ -defmodule ScreensWeb.V2.Audio.ElevatorClosuresView do +defmodule ScreensWeb.V2.Audio.CurrentElevatorClosedView do use ScreensWeb, :view def render("_widget.ssml", _) do diff --git a/lib/screens_web/views/v2/audio/outside_elevator_closures_view.ex b/lib/screens_web/views/v2/audio/outside_elevator_closures_view.ex new file mode 100644 index 000000000..bfee0f336 --- /dev/null +++ b/lib/screens_web/views/v2/audio/outside_elevator_closures_view.ex @@ -0,0 +1,7 @@ +defmodule ScreensWeb.V2.Audio.OutsideElevatorClosuresView do + use ScreensWeb, :view + + def render("_widget.ssml", _) do + ~E"" + end +end diff --git a/test/screens/v2/candidate_generator/elevator/closures_test.exs b/test/screens/v2/candidate_generator/elevator/closures_test.exs index 28360d7a6..71760653d 100644 --- a/test/screens/v2/candidate_generator/elevator/closures_test.exs +++ b/test/screens/v2/candidate_generator/elevator/closures_test.exs @@ -1,11 +1,19 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do use ExUnit.Case, async: true + alias Screens.V2.WidgetInstance.CurrentElevatorClosed.Closure alias Screens.Alerts.Alert alias Screens.Routes.Route alias Screens.Stops.Stop alias Screens.V2.CandidateGenerator.Elevator.Closures, as: ElevatorClosures - alias Screens.V2.WidgetInstance.{Footer, NormalHeader} + + alias Screens.V2.WidgetInstance.{ + CurrentElevatorClosed, + Footer, + NormalHeader, + OutsideElevatorClosures + } + alias ScreensConfig.Screen alias ScreensConfig.V2.Elevator @@ -75,7 +83,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do [ ^header_instance, - %Screens.V2.WidgetInstance.ElevatorClosures{ + %OutsideElevatorClosures{ app_params: ^config, in_station_closures: [ %{ @@ -139,7 +147,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do [ ^header_instance, - %Screens.V2.WidgetInstance.ElevatorClosures{ + %OutsideElevatorClosures{ app_params: ^config, in_station_closures: [], other_stations_with_closures: [ @@ -212,7 +220,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do [ ^header_instance, - %Screens.V2.WidgetInstance.ElevatorClosures{ + %OutsideElevatorClosures{ app_params: ^config, in_station_closures: [], other_stations_with_closures: [] @@ -226,6 +234,65 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do ) end + test "Returns CurrentElevatorClosed if configured elevator is closed", %{ + config: config, + header_instance: header_instance, + footer_instance: footer_instance + } do + expect(@facility, :fetch_stop_for_facility, fn "111" -> {:ok, %Stop{id: "place-test"}} end) + + expect(@stop, :fetch_parent_station_name_map, fn -> + {:ok, %{"place-test" => "Place Test"}} + end) + + expect(@route, :fetch, fn %{stop_id: "place-test"} -> + {:ok, [%Route{id: "Red", type: :subway}]} + end) + + expect(@alert, :fetch_elevator_alerts_with_facilities, fn -> + alerts = [ + struct(Alert, + id: "1", + effect: :elevator_closure, + informed_entities: [ + %{stop: "place-test", facility: %{name: "Test", id: "111"}} + ] + ), + struct(Alert, + effect: :detour, + informed_entities: [ + %{stop: "place-test", facility: %{name: "Test 2", id: "facility-test2"}} + ] + ) + ] + + {:ok, alerts} + end) + + closed_header_instance = %{header_instance | variant: :closed} + closed_footer_instance = %{footer_instance | variant: :closed} + + [ + ^closed_header_instance, + %CurrentElevatorClosed{ + app_params: ^config, + closure: %Closure{ + id: "1", + elevator_name: "Test", + elevator_id: "111", + description: nil, + header_text: nil + } + }, + ^closed_footer_instance + ] = + ElevatorClosures.elevator_status_instances( + struct(Screen, app_id: :elevator_v2, app_params: config), + header_instance, + footer_instance + ) + end + test "Return empty routes on API error", %{ config: config, header_instance: header_instance, @@ -257,7 +324,7 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do [ ^header_instance, - %Screens.V2.WidgetInstance.ElevatorClosures{ + %OutsideElevatorClosures{ app_params: ^config, in_station_closures: [ %{ diff --git a/test/screens/v2/widget_instance/current_elevator_closed_test.exs b/test/screens/v2/widget_instance/current_elevator_closed_test.exs new file mode 100644 index 000000000..324e691c9 --- /dev/null +++ b/test/screens/v2/widget_instance/current_elevator_closed_test.exs @@ -0,0 +1,84 @@ +defmodule Screens.V2.WidgetInstance.CurrentElevatorClosedTest do + use ExUnit.Case, async: true + + alias Screens.V2.WidgetInstance + alias Screens.V2.WidgetInstance.CurrentElevatorClosed + alias ScreensConfig.V2.Elevator + + setup do + %{ + instance: %CurrentElevatorClosed{ + app_params: + struct(Elevator, + elevator_id: "111", + alternate_direction_text: "Test", + accessible_path_direction_arrow: :n + ), + closure: %CurrentElevatorClosed.Closure{ + description: "Test Alert Description", + elevator_name: "Test Elevator", + elevator_id: "111", + id: "1", + header_text: "Test Alert Header" + } + } + } + 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, closure, and alternate direction info", %{instance: instance} do + assert %{ + closure: instance.closure, + accessible_path_direction_arrow: + instance.app_params.accessible_path_direction_arrow, + accessible_path_image_here_coordinates: + instance.app_params.accessible_path_image_here_coordinates, + accessible_path_image_url: instance.app_params.accessible_path_image_url, + alternate_direction_text: instance.app_params.alternate_direction_text, + id: instance.app_params.elevator_id + } == 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 current_elevator_closed", %{instance: instance} do + assert :current_elevator_closed == 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 CurrentElevatorClosedView", %{instance: instance} do + assert ScreensWeb.V2.Audio.CurrentElevatorClosedView == WidgetInstance.audio_view(instance) + end + end +end diff --git a/test/screens/v2/widget_instance/elevator_closures_test.exs b/test/screens/v2/widget_instance/outside_elevator_closures_test.exs similarity index 69% rename from test/screens/v2/widget_instance/elevator_closures_test.exs rename to test/screens/v2/widget_instance/outside_elevator_closures_test.exs index 3564088e3..9f5504ea9 100644 --- a/test/screens/v2/widget_instance/elevator_closures_test.exs +++ b/test/screens/v2/widget_instance/outside_elevator_closures_test.exs @@ -1,13 +1,13 @@ -defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do +defmodule Screens.V2.WidgetInstance.OutsideElevatorClosuresTest do use ExUnit.Case, async: true alias Screens.V2.WidgetInstance - alias Screens.V2.WidgetInstance.ElevatorClosures + alias Screens.V2.WidgetInstance.{CurrentElevatorClosed, OutsideElevatorClosures} alias ScreensConfig.V2.Elevator setup do %{ - instance: %ElevatorClosures{ + instance: %OutsideElevatorClosures{ app_params: struct(Elevator, elevator_id: "1", @@ -15,7 +15,7 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do accessible_path_direction_arrow: :n ), in_station_closures: [ - %ElevatorClosures.Closure{ + %CurrentElevatorClosed.Closure{ description: "Test Alert Description", elevator_name: "Test Elevator", elevator_id: "111", @@ -24,11 +24,11 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do } ], other_stations_with_closures: [ - %ElevatorClosures.Station{ + %OutsideElevatorClosures.Station{ name: "Forest Hills", route_icons: ["Orange"], closures: [ - %ElevatorClosures.Closure{ + %CurrentElevatorClosed.Closure{ description: "FH Alert Description", elevator_name: "FH Elevator", elevator_id: "222", @@ -53,12 +53,6 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do assert %{ in_station_closures: instance.in_station_closures, other_stations_with_closures: instance.other_stations_with_closures, - accessible_path_direction_arrow: - instance.app_params.accessible_path_direction_arrow, - accessible_path_image_here_coordinates: - instance.app_params.accessible_path_image_here_coordinates, - accessible_path_image_url: instance.app_params.accessible_path_image_url, - alternate_direction_text: instance.app_params.alternate_direction_text, id: instance.app_params.elevator_id } == WidgetInstance.serialize(instance) end @@ -71,8 +65,8 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do end describe "widget_type/1" do - test "returns elevator_closures", %{instance: instance} do - assert :elevator_closures == WidgetInstance.widget_type(instance) + test "returns outside_elevator_closures", %{instance: instance} do + assert :outside_elevator_closures == WidgetInstance.widget_type(instance) end end @@ -95,8 +89,9 @@ defmodule Screens.V2.WidgetInstance.ElevatorClosuresTest do end describe "audio_view/1" do - test "returns ElevatorClosuresView", %{instance: instance} do - assert ScreensWeb.V2.Audio.ElevatorClosuresView == WidgetInstance.audio_view(instance) + test "returns OutsideElevatorClosuresView", %{instance: instance} do + assert ScreensWeb.V2.Audio.OutsideElevatorClosuresView == + WidgetInstance.audio_view(instance) end end end