Skip to content

Commit

Permalink
test: test for shuttle route LiveView
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald committed Nov 4, 2024
1 parent 1e7e197 commit 30c43bd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/arrow_web/live/shuttle_live/shuttle_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<div class="form-group">
<a
target="_blank"
Expand Down
56 changes: 56 additions & 0 deletions test/arrow_web/live/shuttle_live/shuttle_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
defmodule ArrowWeb.ShuttleLiveTest do
use ArrowWeb.ConnCase

import Phoenix.LiveViewTest

@create_attrs %{
disrupted_route_id: "",
routes: %{
"0" => %{
:_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

0 comments on commit 30c43bd

Please sign in to comment.