Skip to content

Commit

Permalink
test: test adding a stop
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald committed Nov 14, 2024
1 parent ce8ac60 commit 3a5e693
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/arrow_web/live/shuttle_live/shuttle_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,38 @@ defmodule ArrowWeb.ShuttleLiveTest do
assert Enum.all?(updated_shuttle.routes, fn route -> route.route_stops == [] end)
end

@tag :authenticated_admin
test "can add a stop", %{conn: conn, shuttle: shuttle} do
gtfs_stop = insert(:gtfs_stop)
stop_id = gtfs_stop.id

{:ok, edit_live, _html} = live(conn, ~p"/shuttles/#{shuttle}/edit")

edit_live
|> element("#shuttle-form > button[value=\"0\"]")
|> render_click()

{:ok, conn} =
edit_live
|> form("#shuttle-form",
shuttle: @update_attrs,
routes_with_stops: %{
"0" => %{route_stops: %{"0" => %{display_stop_id: stop_id}}}
}
)
|> render_submit()
|> follow_redirect(conn)

assert html_response(conn, 200) =~ ~r/shuttle updated successfully/i

updated_shuttle = Arrow.Shuttles.get_shuttle!(shuttle.id)

direction_0_route =
Enum.find(updated_shuttle.routes, fn route -> route.direction_id == :"0" end)

assert [%{gtfs_stop_id: ^stop_id}] = direction_0_route.route_stops
end

@tag :authenticated_admin
test "renders errors when data is invalid", %{conn: conn, shuttle: shuttle} do
{:ok, new_live, _html} = live(conn, ~p"/shuttles/#{shuttle}/edit")
Expand Down

0 comments on commit 3a5e693

Please sign in to comment.