From 30c43bd34e32e200a4dbff0aa4d4259689dc5515 Mon Sep 17 00:00:00 2001 From: Eddie Maldonado Date: Mon, 4 Nov 2024 11:02:58 -0500 Subject: [PATCH] test: test for shuttle route LiveView --- .../live/shuttle_live/shuttle_live.ex | 9 ++- .../live/shuttle_live/shuttle_live_test.exs | 56 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/arrow_web/live/shuttle_live/shuttle_live_test.exs diff --git a/lib/arrow_web/live/shuttle_live/shuttle_live.ex b/lib/arrow_web/live/shuttle_live/shuttle_live.ex index 1c266115..c8bcdf96 100644 --- a/lib/arrow_web/live/shuttle_live/shuttle_live.ex +++ b/lib/arrow_web/live/shuttle_live/shuttle_live.ex @@ -17,7 +17,14 @@ defmodule ArrowWeb.ShuttleViewLive do def shuttle_form(assigns) do ~H""" - <.simple_form :let={f} for={@form} as={:shuttle_route} action={@http_action} phx-submit={@action}> + <.simple_form + :let={f} + for={@form} + as={:shuttle_route} + action={@http_action} + phx-submit={@action} + id="shuttle-form" + >
%{ + :_persistent_id => "0", + destination: "Broadway", + direction_desc: "Southbound", + direction_id: "0", + shape_id: "", + suffix: "", + waypoint: "" + }, + "1" => %{ + :_persistent_id => "1", + destination: "Harvard", + direction_desc: "Northbound", + direction_id: "1", + shape_id: "", + suffix: "", + waypoint: "" + } + }, + shuttle_name: "Blah 2", + status: "draft" + } + + describe "new shuttle" do + @tag :authenticated_admin + test "renders form", %{conn: conn} do + {:ok, _new_live, html} = live(conn, ~p"/shuttles/new") + assert html =~ "create new replacement service shuttle" + end + end + + describe "create shuttle" do + @tag :authenticated_admin + test "redirects to index when data is valid", %{conn: conn} do + {:ok, new_live, _html} = live(conn, ~p"/shuttles/new") + + {:ok, conn} = + new_live + |> form("#shuttle-form", shuttle_route: @create_attrs) + |> render_submit() + |> follow_redirect(conn) + + assert html_response(conn, 200) =~ ~r/shuttle created successfully/i + + assert %{"id" => _id} = conn.params + end + end +end