-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Show "Depart at" buttons and show the correct itinerary on click #2238
Changes from 13 commits
72dd393
63fa14e
3d0f7dd
a8b79da
a0a6823
3d194d4
f144a64
7103053
9dedde5
98ae545
fbd6177
eb6bfc2
52f867f
b2e48a7
11537cc
669039f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,9 +3,39 @@ defmodule DotcomWeb.Live.TripPlannerTest do | |||||
|
||||||
import Mox | ||||||
import Phoenix.LiveViewTest | ||||||
import Test.Support.Factories.TripPlanner.TripPlanner, only: [limit_route_types: 1] | ||||||
|
||||||
alias OpenTripPlannerClient.Test.Support.Factory, as: OtpFactory | ||||||
|
||||||
setup :verify_on_exit! | ||||||
|
||||||
defp stub_otp_results(itineraries) do | ||||||
expect(OpenTripPlannerClient.Mock, :plan, fn _ -> | ||||||
{:ok, %OpenTripPlannerClient.Plan{itineraries: itineraries}} | ||||||
end) | ||||||
end | ||||||
|
||||||
defp stub_populated_otp_results() do | ||||||
# Uhhh the OTP factory will generate with any route_type value but our | ||||||
# parsing will break with unexpected route types | ||||||
itineraries = | ||||||
OtpFactory.build_list(3, :itinerary) | ||||||
|> Enum.map(&limit_route_types/1) | ||||||
|
||||||
stub_otp_results(itineraries) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we already do this in a factory?
If not, we should probably fix the factory rather than add that code here (since it applies to all code that uses the OtpFactory and not just this test). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we do this in a factory (I didn't add this - I just moved it), and I do think we should. I was thinking that fixing that could be a follow-up PR, so that the depart-at buttons can still go-live. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine as long as we do it later. I know the factory does this, but it also parses it. Might be worth trying to use the factory directly:
|
||||||
end | ||||||
|
||||||
defp update_trip_details(itinerary, trip_id: trip_id, start_time: start_time) do | ||||||
updated_transit_leg = | ||||||
itinerary.legs | ||||||
|> Enum.at(1) | ||||||
|> update_in([:trip, :gtfs_id], fn _ -> "ma_mbta_us:#{trip_id}" end) | ||||||
|
||||||
itinerary | ||||||
|> Map.update!(:legs, &List.replace_at(&1, 1, updated_transit_leg)) | ||||||
|> Map.put(:start, DateTime.new!(Date.utc_today(), start_time, "America/New_York")) | ||||||
end | ||||||
|
||||||
test "Preview version behind basic auth", %{conn: conn} do | ||||||
conn = get(conn, ~p"/preview/trip-planner") | ||||||
|
||||||
|
@@ -96,9 +126,7 @@ defmodule DotcomWeb.Live.TripPlannerTest do | |||||
} | ||||||
} | ||||||
|
||||||
expect(OpenTripPlannerClient.Mock, :plan, fn _ -> | ||||||
{:ok, %OpenTripPlannerClient.Plan{itineraries: []}} | ||||||
end) | ||||||
stub_otp_results([]) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're only using this in one place, I would just write this as an expectation in this test. That would allow you to remove one of the two functions above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
expect(OpenTripPlannerClient.Mock, :plan, fn _ ->
{:ok, %OpenTripPlannerClient.Plan{itineraries: itineraries}}
end) |
||||||
|
||||||
{:ok, view, _html} = live(conn, ~p"/preview/trip-planner?#{params}") | ||||||
|
||||||
|
@@ -115,16 +143,6 @@ defmodule DotcomWeb.Live.TripPlannerTest do | |||||
Test.Support.Factories.Stops.Stop.build(:stop) | ||||||
end) | ||||||
|
||||||
# Uhhh the OTP factory will generate with any route_type value but our | ||||||
# parsing will break with unexpected route types | ||||||
itineraries = | ||||||
OpenTripPlannerClient.Test.Support.Factory.build_list(3, :itinerary) | ||||||
|> Enum.map(&Test.Support.Factories.TripPlanner.TripPlanner.limit_route_types/1) | ||||||
|
||||||
expect(OpenTripPlannerClient.Mock, :plan, fn _ -> | ||||||
{:ok, %OpenTripPlannerClient.Plan{itineraries: itineraries}} | ||||||
end) | ||||||
|
||||||
%{ | ||||||
conn: | ||||||
put_req_header( | ||||||
|
@@ -144,12 +162,16 @@ defmodule DotcomWeb.Live.TripPlannerTest do | |||||
end | ||||||
|
||||||
test "starts out with no 'View All Options' button", %{conn: conn, params: params} do | ||||||
stub_populated_otp_results() | ||||||
|
||||||
{:ok, view, _html} = live(conn, ~p"/preview/trip-planner?#{params}") | ||||||
|
||||||
refute render_async(view) =~ "View All Options" | ||||||
end | ||||||
|
||||||
test "clicking 'Details' button opens details view", %{conn: conn, params: params} do | ||||||
stub_populated_otp_results() | ||||||
|
||||||
{:ok, view, _html} = live(conn, ~p"/preview/trip-planner?#{params}") | ||||||
|
||||||
render_async(view) | ||||||
|
@@ -162,6 +184,8 @@ defmodule DotcomWeb.Live.TripPlannerTest do | |||||
conn: conn, | ||||||
params: params | ||||||
} do | ||||||
stub_populated_otp_results() | ||||||
|
||||||
{:ok, view, _html} = live(conn, ~p"/preview/trip-planner?#{params}") | ||||||
|
||||||
render_async(view) | ||||||
|
@@ -171,5 +195,45 @@ defmodule DotcomWeb.Live.TripPlannerTest do | |||||
|
||||||
refute render_async(view) =~ "View All Options" | ||||||
end | ||||||
|
||||||
test "'Depart At' buttons toggle which itinerary to show", %{ | ||||||
conn: conn, | ||||||
params: params | ||||||
} do | ||||||
trip_time_1 = ~T[09:26:00] | ||||||
trip_id_1 = "trip_id_1" | ||||||
|
||||||
trip_time_2 = ~T[10:46:00] | ||||||
trip_time_display_2 = "10:46AM" | ||||||
trip_id_2 = "trip_id_2" | ||||||
|
||||||
base_itinerary = | ||||||
OtpFactory.build(:itinerary) | ||||||
|> limit_route_types() | ||||||
|
||||||
# Right now, the headsign (which is what we actually want to | ||||||
# show) is not available from OTP client, but we're rendering | ||||||
# the trip ID in its place. Once the headsign is available, we | ||||||
# should update these updates and the assertions below to use | ||||||
# the headsign instead of the trip ID. | ||||||
stub_otp_results([ | ||||||
update_trip_details(base_itinerary, trip_id: "trip_id_1", start_time: trip_time_1), | ||||||
update_trip_details(base_itinerary, trip_id: "trip_id_2", start_time: trip_time_2) | ||||||
]) | ||||||
|
||||||
{:ok, view, _html} = live(conn, ~p"/preview/trip-planner?#{params}") | ||||||
|
||||||
render_async(view) | ||||||
|
||||||
view |> element("button", "Details") |> render_click() | ||||||
|
||||||
assert render_async(view) =~ trip_id_1 | ||||||
refute render_async(view) =~ trip_id_2 | ||||||
|
||||||
view |> element("button", trip_time_display_2) |> render_click() | ||||||
|
||||||
assert render_async(view) =~ trip_id_2 | ||||||
refute render_async(view) =~ trip_id_1 | ||||||
end | ||||||
end | ||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per this comment, both of these bits of state are going to get moved up to the
TripPlanner
level in a follow-up PR.