Skip to content
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

fix: Don't show "No trips found" message when there are other errors #2290

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions lib/dotcom_web/components/trip_planner/results_summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,46 @@ defmodule DotcomWeb.Components.TripPlanner.ResultsSummary do
>
<p class="text-lg font-semibold mb-0">{submission_summary(@changeset.changes)}</p>
<p>{time_summary(@changeset.changes)}</p>
<%= if @results.loading? do %>
<.spinner aria_label="Waiting for results" /> Waiting for results...
<% else %>
<%= if @results.error do %>
<.feedback kind={:error}>{@results.error}</.feedback>
<% end %>
<%= if Enum.count(@results.itinerary_groups) == 0 do %>
<.feedback kind={:warning}>No trips found.</.feedback>
<% else %>
<.feedback kind={:success}>
Found {Enum.count(@results.itinerary_groups)} {Inflex.inflect(
"way",
Enum.count(@results.itinerary_groups)
)} to go.
</.feedback>
<% end %>
<% end %>
<.results_feedback results={@results} />
</section>
"""
end

defp results_feedback(%{results: %{loading?: true}} = assigns) do
~H"""
<.spinner aria_label="Waiting for results" /> Waiting for results...
"""
end

defp results_feedback(%{results: %{error: nil}} = assigns) do
~H"""
<.itinerary_group_feedback itinerary_groups={@results.itinerary_groups} />
"""
end

defp results_feedback(assigns) do
~H"""
<.feedback kind={:error}>{@results.error}</.feedback>
"""
end

defp itinerary_group_feedback(%{itinerary_groups: []} = assigns) do
~H"""
<.feedback kind={:warning}>No trips found.</.feedback>
"""
end

defp itinerary_group_feedback(assigns) do
~H"""
<.feedback kind={:success}>
Found {Enum.count(@itinerary_groups)} {Inflex.inflect(
"way",
Enum.count(@itinerary_groups)
)} to go.
</.feedback>
"""
end

defp submission_summary(%{from: from, to: to, modes: modes}) do
modes_string = modes.changes |> InputForm.Modes.selected_modes() |> String.downcase()

Expand Down
24 changes: 24 additions & 0 deletions test/dotcom_web/live/trip_planner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ defmodule DotcomWeb.Live.TripPlannerTest do
refute render_async(view) =~ trip_headsign_2
end

test "displays 'No trips found.' if given an empty list of itineraries", %{
conn: conn,
params: params
} do
stub_otp_results([])

{:ok, view, _html} = live(conn, ~p"/preview/trip-planner?#{params}")

assert render_async(view) =~ "No trips found."
end

test "displays error message from the Open Trip Planner client", %{conn: conn, params: params} do
error_message = Faker.Lorem.sentence()

Expand All @@ -333,5 +344,18 @@ defmodule DotcomWeb.Live.TripPlannerTest do

assert render_async(view) =~ error_message
end

test "does not display 'No trips found.' if there's another error", %{
conn: conn,
params: params
} do
expect(OpenTripPlannerClient.Mock, :plan, fn _ ->
{:error, [%OpenTripPlannerClient.Error{message: Faker.Lorem.sentence()}]}
end)

{:ok, view, _html} = live(conn, ~p"/preview/trip-planner?#{params}")

refute render_async(view) =~ "No trips found."
end
end
end
Loading