Skip to content

Commit

Permalink
test: test removing a stop
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald committed Nov 14, 2024
1 parent 985e8fb commit ce8ac60
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 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 @@ -148,6 +148,46 @@ defmodule ArrowWeb.ShuttleLiveTest do
assert html_response(conn, 200) =~ ~r/shuttle updated successfully/i
end

@tag :authenticated_admin
test "can remove a stop", %{conn: conn, shuttle: shuttle} do
direction_0_route = Enum.find(shuttle.routes, fn route -> route.direction_id == :"0" end)
gtfs_stop = insert(:gtfs_stop)

direction_0_route
|> Arrow.Shuttles.Route.changeset(%{
"route_stops" => [
%{
"direction_id" => "0",
"stop_sequence" => "1",
"display_stop_id" => gtfs_stop.id
}
]
})
|> Arrow.Repo.update()

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

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

edit_live
|> element("#shuttle-form")
|> render_change(%{
routes_with_stops: %{"0" => %{"route_stops_drop" => ["0"]}}
})

{:ok, conn} =
edit_live
|> element("#shuttle-form")
|> render_submit()
|> follow_redirect(conn)

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

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

assert Enum.all?(updated_shuttle.routes, fn route -> route.route_stops == [] end)
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 ce8ac60

Please sign in to comment.