upgrade to phoenix 1.7

This commit is contained in:
2023-04-14 23:34:11 -04:00
parent 1796fb822f
commit 1037f37be2
138 changed files with 2304 additions and 2252 deletions

View File

@ -0,0 +1,14 @@
defmodule CanneryWeb.ErrorHTMLTest do
use CanneryWeb.ConnCase, async: true
# Bring render_to_string/4 for testing custom views
import Phoenix.Template
alias CanneryWeb.ErrorHTML
test "renders 404.html" do
assert render_to_string(ErrorHTML, "404", "html", []) =~ "Not found"
end
test "renders 500.html" do
assert render_to_string(ErrorHTML, "500", "html", []) =~ "Internal server error"
end
end

View File

@ -0,0 +1,12 @@
defmodule CanneryWeb.ErrorJSONTest do
use CanneryWeb.ConnCase, async: true
alias CanneryWeb.ErrorJSON
test "renders 404" do
assert ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not found"}}
end
test "renders 500" do
assert ErrorJSON.render("500.json", %{}) == %{errors: %{detail: "Internal server error"}}
end
end

View File

@ -40,7 +40,7 @@ defmodule CanneryWeb.ExportControllerTest do
shot_record: shot_record,
tag: tag
} do
conn = get(conn, Routes.export_path(conn, :export, :json))
conn = get(conn, ~p"/export/json")
ideal_pack = %{
"type_id" => pack.type_id,

View File

@ -8,7 +8,7 @@ defmodule CanneryWeb.HomeControllerTest do
@moduletag :home_controller_test
test "GET /", %{conn: conn} do
conn = get(conn, "/")
conn = get(conn, ~p"/")
assert html_response(conn, 200) =~ "Welcome to Cannery"
end
end

View File

@ -24,7 +24,7 @@ defmodule CanneryWeb.UserAuthTest do
conn = UserAuth.log_in_user(conn, current_user)
assert token = get_session(conn, :user_token)
assert get_session(conn, :live_socket_id) == "users_sessions:#{Base.url_encode64(token)}"
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
assert Accounts.get_user_by_session_token(token)
end
@ -65,7 +65,7 @@ defmodule CanneryWeb.UserAuthTest do
refute get_session(conn, :user_token)
refute conn.cookies[@remember_me_cookie]
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
refute Accounts.get_user_by_session_token(user_token)
end
@ -87,7 +87,7 @@ defmodule CanneryWeb.UserAuthTest do
conn = conn |> fetch_cookies() |> UserAuth.log_out_user()
refute get_session(conn, :user_token)
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
end
end
@ -130,7 +130,7 @@ defmodule CanneryWeb.UserAuthTest do
|> UserAuth.redirect_if_user_is_authenticated([])
assert conn.halted
assert redirected_to(conn) == "/"
assert redirected_to(conn) == ~p"/"
end
test "does not redirect if user is not authenticated", %{conn: conn} do
@ -144,9 +144,9 @@ defmodule CanneryWeb.UserAuthTest do
test "redirects if user is not authenticated", %{conn: conn} do
conn = conn |> fetch_flash() |> UserAuth.require_authenticated_user([])
assert conn.halted
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
assert redirected_to(conn) == ~p"/users/log_in"
assert get_flash(conn, :error) ==
assert conn.assigns.flash["error"] ==
"You must confirm your account and log in to access this page."
end

View File

@ -14,7 +14,7 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
describe "GET /users/confirm" do
test "renders the confirmation page", %{conn: conn} do
conn = get(conn, Routes.user_confirmation_path(conn, :new))
conn = get(conn, ~p"/users/confirm")
response = html_response(conn, 200)
assert response =~ "Resend confirmation instructions"
end
@ -23,12 +23,10 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
describe "POST /users/confirm" do
@tag :capture_log
test "sends a new confirmation token", %{conn: conn, user: user} do
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{user: %{email: user.email}})
conn = post(conn, ~p"/users/confirm", %{user: %{email: user.email}})
assert redirected_to(conn) == ~p"/"
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
assert conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "confirm"
@ -37,24 +35,18 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
test "does not send confirmation token if User is confirmed", %{conn: conn, user: user} do
Repo.update!(Accounts.User.confirm_changeset(user))
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{user: %{email: user.email}})
conn = post(conn, ~p"/users/confirm", %{user: %{email: user.email}})
assert redirected_to(conn) == ~p"/"
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
assert conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
end
test "does not send confirmation token if email is invalid", %{conn: conn} do
conn =
post(conn, Routes.user_confirmation_path(conn, :create), %{
user: %{email: "unknown@example.com"}
})
conn = post(conn, ~p"/users/confirm", %{user: %{email: "unknown@example.com"}})
assert redirected_to(conn) == ~p"/"
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
assert conn.assigns.flash["info"] =~
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
assert Repo.all(Accounts.UserToken) == []
@ -68,33 +60,33 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
Accounts.deliver_user_confirmation_instructions(user, url)
end)
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~ "#{user.email} confirmed successfully"
conn = get(conn, ~p"/users/confirm/#{token}")
assert redirected_to(conn) == ~p"/"
assert conn.assigns.flash["info"] =~ "#{user.email} confirmed successfully"
assert Accounts.get_user!(user.id).confirmed_at
refute get_session(conn, :user_token)
assert Repo.all(Accounts.UserToken) == []
# When not logged in
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
assert redirected_to(conn) == "/"
conn = get(conn, ~p"/users/confirm/#{token}")
assert redirected_to(conn) == ~p"/"
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
assert conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
# When logged in
conn =
build_conn()
|> log_in_user(user)
|> get(Routes.user_confirmation_path(conn, :confirm, token))
|> get(~p"/users/confirm/#{token}")
assert redirected_to(conn) == "/"
refute get_flash(conn, :error)
assert redirected_to(conn) == ~p"/"
refute conn.assigns.flash["error"]
end
test "does not confirm email with invalid token", %{conn: conn, user: user} do
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, "oops"))
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
conn = get(conn, ~p"/users/confirm/oops")
assert redirected_to(conn) == ~p"/"
assert conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
refute Accounts.get_user!(user.id).confirmed_at
end
end

View File

@ -9,15 +9,15 @@ defmodule CanneryWeb.UserRegistrationControllerTest do
describe "GET /users/register" do
test "renders registration page", %{conn: conn} do
conn = get(conn, Routes.user_registration_path(conn, :new))
conn = get(conn, ~p"/users/register")
response = html_response(conn, 200)
assert response =~ "Register"
assert response =~ "Log in"
end
test "redirects if already logged in", %{conn: conn} do
conn = conn |> log_in_user(user_fixture()) |> get(Routes.user_registration_path(conn, :new))
assert redirected_to(conn) == "/"
conn = conn |> log_in_user(user_fixture()) |> get(~p"/users/register")
assert redirected_to(conn) == ~p"/"
end
end
@ -25,20 +25,16 @@ defmodule CanneryWeb.UserRegistrationControllerTest do
@tag :capture_log
test "creates account and logs the user in", %{conn: conn} do
email = unique_user_email()
conn =
post(conn, Routes.user_registration_path(conn, :create), %{
user: valid_user_attributes(email: email)
})
conn = post(conn, ~p"/users/register", %{user: valid_user_attributes(email: email)})
assert get_session(conn, :phoenix_flash) == %{
"info" => "Please check your email to verify your account"
}
assert redirected_to(conn) =~ "/"
assert redirected_to(conn) =~ ~p"/"
# Now do a logged in request and assert on the menu
conn = get(conn, "/")
conn = get(conn, ~p"/")
response = html_response(conn, 200)
# user's email is recorded as admin
assert response =~ email
@ -46,9 +42,7 @@ defmodule CanneryWeb.UserRegistrationControllerTest do
test "render errors for invalid data", %{conn: conn} do
conn =
post(conn, Routes.user_registration_path(conn, :create), %{
user: %{email: "with spaces", password: "too short"}
})
post(conn, ~p"/users/register", %{user: %{email: "with spaces", password: "too short"}})
response = html_response(conn, 200)
assert response =~ "Register"

View File

@ -14,7 +14,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
describe "GET /users/reset_password" do
test "renders the reset password page", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :new))
conn = get(conn, ~p"/users/reset_password")
response = html_response(conn, 200)
assert response =~ "Forgot your password?"
end
@ -23,26 +23,20 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
describe "POST /users/reset_password" do
@tag :capture_log
test "sends a new reset password token", %{conn: conn, user: user} do
conn =
post(conn, Routes.user_reset_password_path(conn, :create), %{user: %{email: user.email}})
conn = post(conn, ~p"/users/reset_password", %{user: %{email: user.email}})
assert redirected_to(conn) == ~p"/"
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
assert conn.assigns.flash["info"] =~
"If your email is in our system, you will receive instructions to reset your password shortly."
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "reset_password"
end
test "does not send reset password token if email is invalid", %{conn: conn} do
conn =
post(conn, Routes.user_reset_password_path(conn, :create), %{
user: %{email: "unknown@example.com"}
})
conn = post(conn, ~p"/users/reset_password", %{user: %{email: "unknown@example.com"}})
assert redirected_to(conn) == ~p"/"
assert redirected_to(conn) == "/"
assert get_flash(conn, :info) =~
assert conn.assigns.flash["info"] =~
"If your email is in our system, you will receive instructions to reset your password shortly."
assert Repo.all(Accounts.UserToken) == []
@ -60,14 +54,14 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
end
test "renders reset password", %{conn: conn, token: token} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
conn = get(conn, ~p"/users/reset_password/#{token}")
assert html_response(conn, 200) =~ "Reset password"
end
test "does not render reset password with invalid token", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops"))
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
conn = get(conn, ~p"/users/reset_password/oops")
assert redirected_to(conn) == ~p"/"
assert conn.assigns.flash["error"] =~ "Reset password link is invalid or it has expired"
end
end
@ -83,22 +77,22 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
test "resets password once", %{conn: conn, user: user, token: token} do
conn =
put(conn, Routes.user_reset_password_path(conn, :update, token), %{
put(conn, ~p"/users/reset_password/#{token}", %{
user: %{
password: "new valid password",
password_confirmation: "new valid password"
}
})
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
assert redirected_to(conn) == ~p"/users/log_in"
refute get_session(conn, :user_token)
assert get_flash(conn, :info) =~ "Password reset successfully"
assert conn.assigns.flash["info"] =~ "Password reset successfully"
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
end
test "does not reset password on invalid data", %{conn: conn, token: token} do
conn =
put(conn, Routes.user_reset_password_path(conn, :update, token), %{
put(conn, ~p"/users/reset_password/#{token}", %{
user: %{
password: "too short",
password_confirmation: "does not match"
@ -112,9 +106,9 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
end
test "does not reset password with invalid token", %{conn: conn} do
conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops"))
assert redirected_to(conn) == "/"
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
conn = put(conn, ~p"/users/reset_password/oops")
assert redirected_to(conn) == ~p"/"
assert conn.assigns.flash["error"] =~ "Reset password link is invalid or it has expired"
end
end
end

View File

@ -13,29 +13,29 @@ defmodule CanneryWeb.UserSessionControllerTest do
describe "GET /users/log_in" do
test "renders log in page", %{conn: conn} do
conn = get(conn, Routes.user_session_path(conn, :new))
conn = get(conn, ~p"/users/log_in")
response = html_response(conn, 200)
assert response =~ "Log in"
end
test "redirects if already logged in", %{conn: conn, current_user: current_user} do
conn = conn |> log_in_user(current_user) |> get(Routes.user_session_path(conn, :new))
assert redirected_to(conn) == "/"
conn = conn |> log_in_user(current_user) |> get(~p"/users/log_in")
assert redirected_to(conn) == ~p"/"
end
end
describe "POST /users/log_in" do
test "logs the user in", %{conn: conn, current_user: current_user} do
conn =
post(conn, Routes.user_session_path(conn, :create), %{
post(conn, ~p"/users/log_in", %{
user: %{email: current_user.email, password: valid_user_password()}
})
assert get_session(conn, :user_token)
assert redirected_to(conn) =~ "/"
assert redirected_to(conn) =~ ~p"/"
# Now do a logged in request and assert on the menu
conn = get(conn, "/")
conn = get(conn, ~p"/")
response = html_response(conn, 200)
assert response =~ current_user.email
assert response =~ "Are you sure you want to log out?"
@ -43,7 +43,7 @@ defmodule CanneryWeb.UserSessionControllerTest do
test "logs the user in with remember me", %{conn: conn, current_user: current_user} do
conn =
post(conn, Routes.user_session_path(conn, :create), %{
post(conn, ~p"/users/log_in", %{
user: %{
email: current_user.email,
password: valid_user_password(),
@ -52,14 +52,14 @@ defmodule CanneryWeb.UserSessionControllerTest do
})
assert conn.resp_cookies["_cannery_web_user_remember_me"]
assert redirected_to(conn) =~ "/"
assert redirected_to(conn) =~ ~p"/"
end
test "logs the user in with return to", %{conn: conn, current_user: current_user} do
conn =
conn
|> init_test_session(user_return_to: "/foo/bar")
|> post(Routes.user_session_path(conn, :create), %{
|> post(~p"/users/log_in", %{
user: %{
email: current_user.email,
password: valid_user_password()
@ -71,11 +71,7 @@ defmodule CanneryWeb.UserSessionControllerTest do
test "emits error message with invalid credentials",
%{conn: conn, current_user: current_user} do
conn =
post(conn, Routes.user_session_path(conn, :create), %{
user: %{email: current_user.email, password: "bad"}
})
conn = post(conn, ~p"/users/log_in", %{user: %{email: current_user.email, password: "bad"}})
response = html_response(conn, 200)
assert response =~ "Log in"
assert response =~ "Invalid email or password"
@ -84,17 +80,17 @@ defmodule CanneryWeb.UserSessionControllerTest do
describe "DELETE /users/log_out" do
test "logs the user out", %{conn: conn, current_user: current_user} do
conn = conn |> log_in_user(current_user) |> delete(Routes.user_session_path(conn, :delete))
assert redirected_to(conn) == "/"
conn = conn |> log_in_user(current_user) |> delete(~p"/users/log_out")
assert redirected_to(conn) == ~p"/"
refute get_session(conn, :user_token)
assert get_flash(conn, :info) =~ "Logged out successfully"
assert conn.assigns.flash["info"] =~ "Logged out successfully"
end
test "succeeds even if the user is not logged in", %{conn: conn} do
conn = delete(conn, Routes.user_session_path(conn, :delete))
assert redirected_to(conn) == "/"
conn = delete(conn, ~p"/users/log_out")
assert redirected_to(conn) == ~p"/"
refute get_session(conn, :user_token)
assert get_flash(conn, :info) =~ "Logged out successfully"
assert conn.assigns.flash["info"] =~ "Logged out successfully"
end
end
end

View File

@ -12,15 +12,15 @@ defmodule CanneryWeb.UserSettingsControllerTest do
describe "GET /users/settings" do
test "renders settings page", %{conn: conn} do
conn = get(conn, Routes.user_settings_path(conn, :edit))
conn = get(conn, ~p"/users/settings")
response = html_response(conn, 200)
assert response =~ "Settings"
end
test "redirects if user is not logged in" do
conn = build_conn()
conn = get(conn, Routes.user_settings_path(conn, :edit))
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
conn = get(conn, ~p"/users/settings")
assert redirected_to(conn) == ~p"/users/log_in"
end
end
@ -28,7 +28,7 @@ defmodule CanneryWeb.UserSettingsControllerTest do
test "updates the user password and resets tokens",
%{conn: conn, current_user: current_user} do
new_password_conn =
put(conn, Routes.user_settings_path(conn, :update), %{
put(conn, ~p"/users/settings", %{
action: "update_password",
current_password: valid_user_password(),
user: %{
@ -37,15 +37,15 @@ defmodule CanneryWeb.UserSettingsControllerTest do
}
})
assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit)
assert redirected_to(new_password_conn) == ~p"/users/settings"
assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token)
assert get_flash(new_password_conn, :info) =~ "Password updated successfully"
assert new_password_conn.assigns.flash["info"] =~ "Password updated successfully"
assert Accounts.get_user_by_email_and_password(current_user.email, "new valid password")
end
test "does not update password on invalid data", %{conn: conn} do
old_password_conn =
put(conn, Routes.user_settings_path(conn, :update), %{
put(conn, ~p"/users/settings", %{
action: "update_password",
current_password: "invalid",
user: %{
@ -67,15 +67,15 @@ defmodule CanneryWeb.UserSettingsControllerTest do
@tag :capture_log
test "updates the user email", %{conn: conn, current_user: current_user} do
conn =
put(conn, Routes.user_settings_path(conn, :update), %{
put(conn, ~p"/users/settings", %{
action: "update_email",
current_password: valid_user_password(),
user: %{email: unique_user_email()}
})
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert redirected_to(conn) == ~p"/users/settings"
assert get_flash(conn, :info) =~
assert conn.assigns.flash["info"] =~
"A link to confirm your email change has been sent to the new address."
assert Accounts.get_user_by_email(current_user.email)
@ -83,7 +83,7 @@ defmodule CanneryWeb.UserSettingsControllerTest do
test "does not update email on invalid data", %{conn: conn} do
conn =
put(conn, Routes.user_settings_path(conn, :update), %{
put(conn, ~p"/users/settings", %{
action: "update_email",
current_password: "invalid",
user: %{email: "with spaces"}
@ -114,28 +114,28 @@ defmodule CanneryWeb.UserSettingsControllerTest do
test "updates the user email once",
%{conn: conn, current_user: current_user, token: token, email: email} do
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(conn, :info) =~ "Email changed successfully"
conn = get(conn, ~p"/users/settings/confirm_email/#{token}")
assert redirected_to(conn) == ~p"/users/settings"
assert conn.assigns.flash["info"] =~ "Email changed successfully"
refute Accounts.get_user_by_email(current_user.email)
assert Accounts.get_user_by_email(email)
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired"
conn = get(conn, ~p"/users/settings/confirm_email/#{token}")
assert redirected_to(conn) == ~p"/users/settings"
assert conn.assigns.flash["error"] =~ "Email change link is invalid or it has expired"
end
test "does not update email with invalid token", %{conn: conn, current_user: current_user} do
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, "oops"))
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired"
conn = get(conn, ~p"/users/settings/confirm_email/oops")
assert redirected_to(conn) == ~p"/users/settings"
assert conn.assigns.flash["error"] =~ "Email change link is invalid or it has expired"
assert Accounts.get_user_by_email(current_user.email)
end
test "redirects if user is not logged in", %{token: token} do
conn = build_conn()
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
conn = get(conn, ~p"/users/settings/confirm_email/#{token}")
assert redirected_to(conn) == ~p"/users/log_in"
end
end
end

View File

@ -51,14 +51,13 @@ defmodule CanneryWeb.ContainerLiveTest do
setup [:register_and_log_in_user, :create_container]
test "lists all containers", %{conn: conn, container: container} do
{:ok, _index_live, html} = live(conn, Routes.container_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/containers")
assert html =~ "Containers"
assert html =~ container.location
end
test "lists all containers in table mode", %{conn: conn, container: container} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/containers")
html =
index_live
@ -70,7 +69,7 @@ defmodule CanneryWeb.ContainerLiveTest do
end
test "can search for containers", %{conn: conn, container: container} do
{:ok, index_live, html} = live(conn, Routes.container_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/containers")
assert html =~ container.location
@ -78,26 +77,26 @@ defmodule CanneryWeb.ContainerLiveTest do
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: container.location}) =~ container.location
assert_patch(index_live, Routes.container_index_path(conn, :search, container.location))
assert_patch(index_live, ~p"/containers/search/#{container.location}")
refute index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: "something_else"}) =~ container.location
assert_patch(index_live, Routes.container_index_path(conn, :search, "something_else"))
assert_patch(index_live, ~p"/containers/search/something_else")
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: ""}) =~ container.location
assert_patch(index_live, Routes.container_index_path(conn, :index))
assert_patch(index_live, ~p"/containers")
end
test "saves new container", %{conn: conn, container: container} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/containers")
assert index_live |> element("a", "New Container") |> render_click() =~ "New Container"
assert_patch(index_live, Routes.container_index_path(conn, :new))
assert_patch(index_live, ~p"/containers/new")
assert index_live
|> form("#container-form")
@ -107,7 +106,7 @@ defmodule CanneryWeb.ContainerLiveTest do
index_live
|> form("#container-form")
|> render_submit(container: @create_attrs)
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
|> follow_redirect(conn, ~p"/containers")
assert html =~ "#{container.name} created successfully"
assert html =~ "some location"
@ -118,12 +117,12 @@ defmodule CanneryWeb.ContainerLiveTest do
current_user: current_user,
container: container
} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/containers")
assert index_live |> element(~s/a[aria-label="Edit #{container.name}"]/) |> render_click() =~
"Edit #{container.name}"
assert_patch(index_live, Routes.container_index_path(conn, :edit, container))
assert_patch(index_live, ~p"/containers/edit/#{container}")
assert index_live
|> form("#container-form")
@ -133,7 +132,7 @@ defmodule CanneryWeb.ContainerLiveTest do
index_live
|> form("#container-form")
|> render_submit(container: @update_attrs)
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
|> follow_redirect(conn, ~p"/containers")
container = container.id |> Containers.get_container!(current_user)
assert html =~ "#{container.name} updated successfully"
@ -145,13 +144,13 @@ defmodule CanneryWeb.ContainerLiveTest do
current_user: current_user,
container: container
} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/containers")
html = index_live |> element(~s/a[aria-label="Clone #{container.name}"]/) |> render_click()
assert html =~ "New Container"
assert html =~ "some location"
assert_patch(index_live, Routes.container_index_path(conn, :clone, container))
assert_patch(index_live, ~p"/containers/clone/#{container}")
assert index_live
|> form("#container-form")
@ -161,7 +160,7 @@ defmodule CanneryWeb.ContainerLiveTest do
index_live
|> form("#container-form")
|> render_submit(container: @create_attrs)
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
|> follow_redirect(conn, ~p"/containers")
container = container.id |> Containers.get_container!(current_user)
assert html =~ "#{container.name} created successfully"
@ -173,12 +172,12 @@ defmodule CanneryWeb.ContainerLiveTest do
current_user: current_user,
container: container
} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/containers")
assert index_live |> element(~s/a[aria-label="Clone #{container.name}"]/) |> render_click() =~
"New Container"
assert_patch(index_live, Routes.container_index_path(conn, :clone, container))
assert_patch(index_live, ~p"/containers/clone/#{container}")
assert index_live
|> form("#container-form")
@ -190,7 +189,7 @@ defmodule CanneryWeb.ContainerLiveTest do
|> render_submit(
container: Map.merge(@create_attrs, %{location: "some updated location"})
)
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
|> follow_redirect(conn, ~p"/containers")
container = container.id |> Containers.get_container!(current_user)
assert html =~ "#{container.name} created successfully"
@ -198,7 +197,7 @@ defmodule CanneryWeb.ContainerLiveTest do
end
test "deletes container in listing", %{conn: conn, container: container} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/containers")
assert index_live |> element(~s/a[aria-label="Delete #{container.name}"]/) |> render_click()
refute has_element?(index_live, "#container-#{container.id}")
end
@ -211,7 +210,7 @@ defmodule CanneryWeb.ContainerLiveTest do
conn: conn,
container: %{name: name, location: location} = container
} do
{:ok, _show_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
{:ok, _show_live, html} = live(conn, ~p"/container/#{container}")
assert html =~ name
assert html =~ location
end
@ -221,12 +220,12 @@ defmodule CanneryWeb.ContainerLiveTest do
current_user: current_user,
container: container
} do
{:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container))
{:ok, show_live, _html} = live(conn, ~p"/container/#{container}")
assert show_live |> element(~s/a[aria-label="Edit #{container.name}"]/) |> render_click() =~
"Edit #{container.name}"
assert_patch(show_live, Routes.container_show_path(conn, :edit, container))
assert_patch(show_live, ~p"/container/edit/#{container}")
assert show_live
|> form("#container-form")
@ -236,7 +235,7 @@ defmodule CanneryWeb.ContainerLiveTest do
show_live
|> form("#container-form")
|> render_submit(container: @update_attrs)
|> follow_redirect(conn, Routes.container_show_path(conn, :show, container))
|> follow_redirect(conn, ~p"/container/#{container}")
container = container.id |> Containers.get_container!(current_user)
assert html =~ "#{container.name} updated successfully"
@ -252,7 +251,7 @@ defmodule CanneryWeb.ContainerLiveTest do
pistol_type = type_fixture(%{class: :pistol}, current_user)
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
{:ok, index_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
{:ok, index_live, html} = live(conn, ~p"/container/#{container}")
assert html =~ "All"
@ -303,7 +302,7 @@ defmodule CanneryWeb.ContainerLiveTest do
test "displays pack",
%{conn: conn, type: %{name: type_name}, container: container} do
{:ok, _show_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
{:ok, _show_live, html} = live(conn, ~p"/container/#{container}")
assert html =~ type_name
assert html =~ "\n20\n"
@ -311,7 +310,7 @@ defmodule CanneryWeb.ContainerLiveTest do
test "displays pack in table",
%{conn: conn, type: %{name: type_name}, container: container} do
{:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container))
{:ok, show_live, _html} = live(conn, ~p"/container/#{container}")
html =
show_live

View File

@ -9,13 +9,13 @@ defmodule CanneryWeb.HomeLiveTest do
@moduletag :home_live_test
test "disconnected and connected render", %{conn: conn} do
{:ok, home_live, disconnected_html} = live(conn, "/")
{:ok, home_live, disconnected_html} = live(conn, ~p"/")
assert disconnected_html =~ "Welcome to Cannery"
assert render(home_live) =~ "Welcome to Cannery"
end
test "displays version number", %{conn: conn} do
{:ok, home_live, disconnected_html} = live(conn, "/")
{:ok, home_live, disconnected_html} = live(conn, ~p"/")
assert disconnected_html =~ Mix.Project.config()[:version]
assert render(home_live) =~ Mix.Project.config()[:version]
end

View File

@ -21,17 +21,17 @@ defmodule CanneryWeb.InviteLiveTest do
end
test "lists all invites", %{conn: conn, invite: invite} do
{:ok, _index_live, html} = live(conn, Routes.invite_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/invites")
assert html =~ "Invites"
assert html =~ invite.name
end
test "saves new invite", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/invites")
assert index_live |> element("a", "Create Invite") |> render_click() =~ "New Invite"
assert_patch(index_live, Routes.invite_index_path(conn, :new))
assert_patch(index_live, ~p"/invites/new")
assert index_live
|> form("#invite-form")
@ -41,19 +41,19 @@ defmodule CanneryWeb.InviteLiveTest do
index_live
|> form("#invite-form")
|> render_submit(invite: @create_attrs)
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|> follow_redirect(conn, ~p"/invites")
assert html =~ "some name created successfully"
end
test "updates invite in listing", %{conn: conn, invite: invite} do
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/invites")
assert index_live
|> element(~s/a[aria-label="Edit invite for #{invite.name}"]/)
|> render_click() =~ "Edit Invite"
assert_patch(index_live, Routes.invite_index_path(conn, :edit, invite))
assert_patch(index_live, ~p"/invites/#{invite}/edit")
assert index_live
|> form("#invite-form")
@ -63,13 +63,13 @@ defmodule CanneryWeb.InviteLiveTest do
index_live
|> form("#invite-form")
|> render_submit(invite: @update_attrs)
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|> follow_redirect(conn, ~p"/invites")
assert html =~ "some updated name updated successfully"
end
test "deletes invite in listing", %{conn: conn, invite: invite} do
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/invites")
assert index_live
|> element(~s/a[aria-label="Delete invite for #{invite.name}"]/)

View File

@ -56,7 +56,7 @@ defmodule CanneryWeb.PackLiveTest do
setup [:register_and_log_in_user, :create_pack]
test "lists all packs", %{conn: conn, pack: pack} do
{:ok, _index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/ammo")
pack = pack |> Repo.preload(:type)
assert html =~ "Ammo"
assert html =~ pack.type.name
@ -71,7 +71,7 @@ defmodule CanneryWeb.PackLiveTest do
pistol_type = type_fixture(%{class: :pistol}, current_user)
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
{:ok, index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/ammo")
assert html =~ "All"
@ -117,7 +117,7 @@ defmodule CanneryWeb.PackLiveTest do
end
test "can search for packs", %{conn: conn, pack: pack} do
{:ok, index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/ammo")
pack = pack |> Repo.preload(:type)
@ -128,30 +128,27 @@ defmodule CanneryWeb.PackLiveTest do
|> render_change(search: %{search_term: pack.type.name}) =~
pack.type.name
assert_patch(
index_live,
Routes.pack_index_path(conn, :search, pack.type.name)
)
assert_patch(index_live, ~p"/ammo/search/#{pack.type.name}")
refute index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: "something_else"}) =~
pack.type.name
assert_patch(index_live, Routes.pack_index_path(conn, :search, "something_else"))
assert_patch(index_live, ~p"/ammo/search/something_else")
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: ""}) =~ pack.type.name
assert_patch(index_live, Routes.pack_index_path(conn, :index))
assert_patch(index_live, ~p"/ammo")
end
test "saves a single new pack", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
assert_patch(index_live, Routes.pack_index_path(conn, :new))
assert_patch(index_live, ~p"/ammo/new")
assert index_live
|> form("#pack-form")
@ -161,7 +158,7 @@ defmodule CanneryWeb.PackLiveTest do
index_live
|> form("#pack-form")
|> render_submit(pack: @create_attrs)
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|> follow_redirect(conn, ~p"/ammo")
assert html =~ "Ammo added successfully"
assert html =~ "\n42\n"
@ -169,10 +166,10 @@ defmodule CanneryWeb.PackLiveTest do
test "saves multiple new packs", %{conn: conn, current_user: current_user} do
multiplier = 25
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
assert_patch(index_live, Routes.pack_index_path(conn, :new))
assert_patch(index_live, ~p"/ammo/new")
assert index_live
|> form("#pack-form")
@ -182,17 +179,17 @@ defmodule CanneryWeb.PackLiveTest do
index_live
|> form("#pack-form")
|> render_submit(pack: @create_attrs |> Map.put(:multiplier, multiplier))
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|> follow_redirect(conn, ~p"/ammo")
assert html =~ "Ammo added successfully"
assert Ammo.list_packs(nil, :all, current_user) |> Enum.count() == multiplier + 1
end
test "does not save invalid number of new packs", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
assert_patch(index_live, Routes.pack_index_path(conn, :new))
assert_patch(index_live, ~p"/ammo/new")
assert index_live
|> form("#pack-form")
@ -210,13 +207,13 @@ defmodule CanneryWeb.PackLiveTest do
end
test "updates pack in listing", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live
|> element(~s/a[aria-label="Edit pack of #{pack.count} bullets"]/)
|> render_click() =~ "Edit ammo"
assert_patch(index_live, Routes.pack_index_path(conn, :edit, pack))
assert_patch(index_live, ~p"/ammo/edit/#{pack}")
assert index_live
|> form("#pack-form")
@ -226,14 +223,14 @@ defmodule CanneryWeb.PackLiveTest do
index_live
|> form("#pack-form")
|> render_submit(pack: @update_attrs)
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|> follow_redirect(conn, ~p"/ammo")
assert html =~ "Ammo updated successfully"
assert html =~ "\n43\n"
end
test "clones pack in listing", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
html =
index_live
@ -243,13 +240,13 @@ defmodule CanneryWeb.PackLiveTest do
assert html =~ "Add Ammo"
assert html =~ "$#{display_currency(120.5)}"
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
assert_patch(index_live, ~p"/ammo/clone/#{pack}")
{:ok, _index_live, html} =
index_live
|> form("#pack-form")
|> render_submit()
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|> follow_redirect(conn, ~p"/ammo")
assert html =~ "Ammo added successfully"
assert html =~ "\n42\n"
@ -257,7 +254,7 @@ defmodule CanneryWeb.PackLiveTest do
end
test "checks validity when cloning", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
html =
index_live
@ -267,7 +264,7 @@ defmodule CanneryWeb.PackLiveTest do
assert html =~ "Add Ammo"
assert html =~ "$#{display_currency(120.5)}"
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
assert_patch(index_live, ~p"/ammo/clone/#{pack}")
assert index_live
|> form("#pack-form")
@ -275,7 +272,7 @@ defmodule CanneryWeb.PackLiveTest do
end
test "clones pack in listing with updates", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
html =
index_live
@ -284,7 +281,7 @@ defmodule CanneryWeb.PackLiveTest do
assert html =~ "Add Ammo"
assert html =~ "$#{display_currency(120.5)}"
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
assert_patch(index_live, ~p"/ammo/clone/#{pack}")
assert index_live
|> form("#pack-form")
@ -294,7 +291,7 @@ defmodule CanneryWeb.PackLiveTest do
index_live
|> form("#pack-form")
|> render_submit(pack: @create_attrs |> Map.put(:count, 43))
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|> follow_redirect(conn, ~p"/ammo")
assert html =~ "Ammo added successfully"
assert html =~ "\n43\n"
@ -302,7 +299,7 @@ defmodule CanneryWeb.PackLiveTest do
end
test "deletes pack in listing", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live
|> element(~s/a[aria-label="Delete pack of #{pack.count} bullets"]/)
@ -312,10 +309,10 @@ defmodule CanneryWeb.PackLiveTest do
end
test "saves new shot_record", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
assert_patch(index_live, Routes.pack_index_path(conn, :add_shot_record, pack))
assert_patch(index_live, ~p"/ammo/add_shot_record/#{pack}")
assert index_live
|> form("#shot-record-form")
@ -325,7 +322,7 @@ defmodule CanneryWeb.PackLiveTest do
index_live
|> form("#shot-record-form")
|> render_submit(shot_record: @shot_record_create_attrs)
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|> follow_redirect(conn, ~p"/ammo")
assert html =~ "Shots recorded successfully"
end
@ -342,7 +339,7 @@ defmodule CanneryWeb.PackLiveTest do
empty_pack: pack,
current_user: current_user
} do
{:ok, show_live, html} = live(conn, Routes.pack_index_path(conn, :index))
{:ok, show_live, html} = live(conn, ~p"/ammo")
assert html =~ "Show used"
refute html =~ "$#{display_currency(50.00)}"
@ -365,20 +362,20 @@ defmodule CanneryWeb.PackLiveTest do
setup [:register_and_log_in_user, :create_pack]
test "displays pack", %{conn: conn, pack: pack} do
{:ok, _show_live, html} = live(conn, Routes.pack_show_path(conn, :show, pack))
{:ok, _show_live, html} = live(conn, ~p"/ammo/show/#{pack}")
pack = pack |> Repo.preload(:type)
assert html =~ "Show Ammo"
assert html =~ pack.type.name
end
test "updates pack within modal", %{conn: conn, pack: pack} do
{:ok, show_live, _html} = live(conn, Routes.pack_show_path(conn, :show, pack))
{:ok, show_live, _html} = live(conn, ~p"/ammo/show/#{pack}")
assert show_live
|> element(~s/a[aria-label="Edit pack of #{pack.count} bullets"]/)
|> render_click() =~ "Edit Ammo"
assert_patch(show_live, Routes.pack_show_path(conn, :edit, pack))
assert_patch(show_live, ~p"/ammo/show/edit/#{pack}")
assert show_live
|> form("#pack-form")
@ -388,17 +385,17 @@ defmodule CanneryWeb.PackLiveTest do
show_live
|> form("#pack-form")
|> render_submit(pack: @update_attrs)
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|> follow_redirect(conn, ~p"/ammo/show/#{pack}")
assert html =~ "Ammo updated successfully"
assert html =~ "some updated notes"
end
test "saves new shot_record", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_show_path(conn, :show, pack))
{:ok, index_live, _html} = live(conn, ~p"/ammo/show/#{pack}")
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
assert_patch(index_live, Routes.pack_show_path(conn, :add_shot_record, pack))
assert_patch(index_live, ~p"/ammo/show/add_shot_record/#{pack}")
assert index_live
|> form("#shot-record-form")
@ -408,7 +405,7 @@ defmodule CanneryWeb.PackLiveTest do
index_live
|> form("#shot-record-form")
|> render_submit(shot_record: @shot_record_create_attrs)
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|> follow_redirect(conn, ~p"/ammo/show/#{pack}")
assert html =~ "Shots recorded successfully"
end
@ -419,16 +416,13 @@ defmodule CanneryWeb.PackLiveTest do
test "updates shot_record in listing",
%{conn: conn, pack: pack, shot_record: shot_record} do
{:ok, index_live, _html} = live(conn, Routes.pack_show_path(conn, :edit, pack))
{:ok, index_live, _html} = live(conn, ~p"/ammo/show/edit/#{pack}")
assert index_live
|> element(~s/a[aria-label="Edit shot record of #{shot_record.count} shots"]/)
|> render_click() =~ "Edit Shot Record"
assert_patch(
index_live,
Routes.pack_show_path(conn, :edit_shot_record, pack, shot_record)
)
assert_patch(index_live, ~p"/ammo/show/#{pack}/edit/#{shot_record}")
assert index_live
|> form("#shot-record-form")
@ -438,7 +432,7 @@ defmodule CanneryWeb.PackLiveTest do
index_live
|> form("#shot-record-form")
|> render_submit(shot_record: @shot_record_update_attrs)
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|> follow_redirect(conn, ~p"/ammo/show/#{pack}")
assert html =~ "Shot records updated successfully"
assert html =~ "some updated notes"
@ -446,8 +440,7 @@ defmodule CanneryWeb.PackLiveTest do
test "deletes shot_record in listing",
%{conn: conn, pack: pack, shot_record: shot_record} do
{:ok, index_live, _html} =
live(conn, Routes.pack_show_path(conn, :edit_shot_record, pack, shot_record))
{:ok, index_live, _html} = live(conn, ~p"/ammo/show/#{pack}/edit/#{shot_record}")
assert index_live
|> element(~s/a[aria-label="Delete shot record of #{shot_record.count} shots"]/)

View File

@ -34,7 +34,7 @@ defmodule CanneryWeb.RangeLiveTest do
setup [:register_and_log_in_user, :create_shot_record]
test "lists all shot_records", %{conn: conn, shot_record: shot_record} do
{:ok, _index_live, html} = live(conn, Routes.range_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/range")
assert html =~ "Range day"
assert html =~ shot_record.notes
@ -57,7 +57,7 @@ defmodule CanneryWeb.RangeLiveTest do
pistol_shot_record = shot_record_fixture(%{notes: "group_three"}, current_user, pistol_pack)
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/range")
assert html =~ "All"
@ -103,7 +103,7 @@ defmodule CanneryWeb.RangeLiveTest do
end
test "can search for shot_record", %{conn: conn, shot_record: shot_record} do
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/range")
assert html =~ shot_record.notes
@ -111,26 +111,26 @@ defmodule CanneryWeb.RangeLiveTest do
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: shot_record.notes}) =~ shot_record.notes
assert_patch(index_live, Routes.range_index_path(conn, :search, shot_record.notes))
assert_patch(index_live, ~p"/range/search/#{shot_record.notes}")
refute index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: "something_else"}) =~ shot_record.notes
assert_patch(index_live, Routes.range_index_path(conn, :search, "something_else"))
assert_patch(index_live, ~p"/range/search/something_else")
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: ""}) =~ shot_record.notes
assert_patch(index_live, Routes.range_index_path(conn, :index))
assert_patch(index_live, ~p"/range")
end
test "saves new shot_record", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/range")
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
assert_patch(index_live, Routes.range_index_path(conn, :add_shot_record, pack))
assert_patch(index_live, ~p"/range/add_shot_record/#{pack}")
assert index_live
|> form("#shot-record-form")
@ -140,20 +140,20 @@ defmodule CanneryWeb.RangeLiveTest do
index_live
|> form("#shot-record-form")
|> render_submit(shot_record: @create_attrs)
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|> follow_redirect(conn, ~p"/range")
assert html =~ "Shots recorded successfully"
assert html =~ "some notes"
end
test "updates shot_record in listing", %{conn: conn, shot_record: shot_record} do
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/range")
assert index_live
|> element(~s/a[aria-label="Edit shot record of #{shot_record.count} shots"]/)
|> render_click() =~ "Edit Shot Record"
assert_patch(index_live, Routes.range_index_path(conn, :edit, shot_record))
assert_patch(index_live, ~p"/range/edit/#{shot_record}")
assert index_live
|> form("#shot-record-form")
@ -163,14 +163,14 @@ defmodule CanneryWeb.RangeLiveTest do
index_live
|> form("#shot-record-form", shot_record: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|> follow_redirect(conn, ~p"/range")
assert html =~ "Shot records updated successfully"
assert html =~ "some updated notes"
end
test "deletes shot_record in listing", %{conn: conn, shot_record: shot_record} do
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/range")
assert index_live
|> element(~s/a[aria-label="Delete shot record of #{shot_record.count} shots"]/)

View File

@ -33,14 +33,14 @@ defmodule CanneryWeb.TagLiveTest do
setup [:register_and_log_in_user, :create_tag]
test "lists all tags", %{conn: conn, tag: tag} do
{:ok, _index_live, html} = live(conn, Routes.tag_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/tags")
assert html =~ "Tags"
assert html =~ tag.bg_color
end
test "can search for tag", %{conn: conn, tag: tag} do
{:ok, index_live, html} = live(conn, Routes.tag_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/tags")
assert html =~ tag.name
@ -48,26 +48,26 @@ defmodule CanneryWeb.TagLiveTest do
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: tag.name}) =~ tag.name
assert_patch(index_live, Routes.tag_index_path(conn, :search, tag.name))
assert_patch(index_live, ~p"/tags/search/#{tag.name}")
refute index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: "something_else"}) =~ tag.name
assert_patch(index_live, Routes.tag_index_path(conn, :search, "something_else"))
assert_patch(index_live, ~p"/tags/search/something_else")
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: ""}) =~ tag.name
assert_patch(index_live, Routes.tag_index_path(conn, :index))
assert_patch(index_live, ~p"/tags")
end
test "saves new tag", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/tags")
assert index_live |> element("a", "New Tag") |> render_click() =~ "New Tag"
assert_patch(index_live, Routes.tag_index_path(conn, :new))
assert_patch(index_live, ~p"/tags/new")
assert index_live
|> form("#tag-form")
@ -77,19 +77,19 @@ defmodule CanneryWeb.TagLiveTest do
index_live
|> form("#tag-form")
|> render_submit(tag: @create_attrs)
|> follow_redirect(conn, Routes.tag_index_path(conn, :index))
|> follow_redirect(conn, ~p"/tags")
assert html =~ "some name created successfully"
assert html =~ "#100000"
end
test "updates tag in listing", %{conn: conn, tag: tag} do
{:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/tags")
assert index_live |> element(~s/a[aria-label="Edit #{tag.name}"]/) |> render_click() =~
"Edit Tag"
assert_patch(index_live, Routes.tag_index_path(conn, :edit, tag))
assert_patch(index_live, ~p"/tags/edit/#{tag}")
assert index_live
|> form("#tag-form")
@ -99,14 +99,14 @@ defmodule CanneryWeb.TagLiveTest do
index_live
|> form("#tag-form")
|> render_submit(tag: @update_attrs)
|> follow_redirect(conn, Routes.tag_index_path(conn, :index))
|> follow_redirect(conn, ~p"/tags")
assert html =~ "some updated name updated successfully"
assert html =~ "#100001"
end
test "deletes tag in listing", %{conn: conn, tag: tag} do
{:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/tags")
assert index_live |> element(~s/a[aria-label="Delete #{tag.name}"]/) |> render_click()
refute has_element?(index_live, "#tag-#{tag.id}")

View File

@ -64,7 +64,7 @@ defmodule CanneryWeb.TypeLiveTest do
setup [:register_and_log_in_user, :create_type]
test "lists all types", %{conn: conn, type: type} do
{:ok, _index_live, html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, _index_live, html} = live(conn, ~p"/catalog")
assert html =~ "Catalog"
assert html =~ type.bullet_type
end
@ -74,7 +74,7 @@ defmodule CanneryWeb.TypeLiveTest do
shotgun_type = type_fixture(%{class: :shotgun}, current_user)
pistol_type = type_fixture(%{class: :pistol}, current_user)
{:ok, index_live, html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/catalog")
assert html =~ "All"
@ -120,7 +120,7 @@ defmodule CanneryWeb.TypeLiveTest do
end
test "can search for type", %{conn: conn, type: type} do
{:ok, index_live, html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/catalog")
assert html =~ type.bullet_type
@ -129,26 +129,26 @@ defmodule CanneryWeb.TypeLiveTest do
|> render_change(search: %{search_term: type.bullet_type}) =~
type.bullet_type
assert_patch(index_live, Routes.type_index_path(conn, :search, type.bullet_type))
assert_patch(index_live, ~p"/catalog/search/#{type.bullet_type}")
refute index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: "something_else"}) =~ type.bullet_type
assert_patch(index_live, Routes.type_index_path(conn, :search, "something_else"))
assert_patch(index_live, ~p"/catalog/search/something_else")
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: ""}) =~ type.bullet_type
assert_patch(index_live, Routes.type_index_path(conn, :index))
assert_patch(index_live, ~p"/catalog")
end
test "saves new type", %{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/catalog")
assert index_live |> element("a", "New Type") |> render_click() =~ "New Type"
assert_patch(index_live, Routes.type_index_path(conn, :new))
assert_patch(index_live, ~p"/catalog/new")
assert index_live
|> form("#type-form")
@ -158,7 +158,7 @@ defmodule CanneryWeb.TypeLiveTest do
index_live
|> form("#type-form")
|> render_submit(type: @create_attrs)
|> follow_redirect(conn, Routes.type_index_path(conn, :index))
|> follow_redirect(conn, ~p"/catalog")
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} created successfully"
@ -167,12 +167,12 @@ defmodule CanneryWeb.TypeLiveTest do
test "updates type in listing",
%{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/catalog")
assert index_live |> element(~s/a[aria-label="Edit #{type.name}"]/) |> render_click() =~
"Edit #{type.name}"
assert_patch(index_live, Routes.type_index_path(conn, :edit, type))
assert_patch(index_live, ~p"/catalog/edit/#{type}")
assert index_live
|> form("#type-form")
@ -182,7 +182,7 @@ defmodule CanneryWeb.TypeLiveTest do
index_live
|> form("#type-form")
|> render_submit(type: @update_attrs)
|> follow_redirect(conn, Routes.type_index_path(conn, :index))
|> follow_redirect(conn, ~p"/catalog")
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} updated successfully"
@ -191,13 +191,13 @@ defmodule CanneryWeb.TypeLiveTest do
test "clones type in listing",
%{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/catalog")
html = index_live |> element(~s/a[aria-label="Clone #{type.name}"]/) |> render_click()
assert html =~ "New Type"
assert html =~ "some bullet_type"
assert_patch(index_live, Routes.type_index_path(conn, :clone, type))
assert_patch(index_live, ~p"/catalog/clone/#{type}")
assert index_live
|> form("#type-form")
@ -207,7 +207,7 @@ defmodule CanneryWeb.TypeLiveTest do
index_live
|> form("#type-form")
|> render_submit(type: @create_attrs)
|> follow_redirect(conn, Routes.type_index_path(conn, :index))
|> follow_redirect(conn, ~p"/catalog")
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} created successfully"
@ -216,13 +216,13 @@ defmodule CanneryWeb.TypeLiveTest do
test "clones type in listing with updates",
%{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/catalog")
html = index_live |> element(~s/a[aria-label="Clone #{type.name}"]/) |> render_click()
assert html =~ "New Type"
assert html =~ "some bullet_type"
assert_patch(index_live, Routes.type_index_path(conn, :clone, type))
assert_patch(index_live, ~p"/catalog/clone/#{type}")
assert index_live
|> form("#type-form")
@ -234,7 +234,7 @@ defmodule CanneryWeb.TypeLiveTest do
|> render_submit(
type: Map.merge(@create_attrs, %{bullet_type: "some updated bullet_type"})
)
|> follow_redirect(conn, Routes.type_index_path(conn, :index))
|> follow_redirect(conn, ~p"/catalog")
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} created successfully"
@ -242,7 +242,7 @@ defmodule CanneryWeb.TypeLiveTest do
end
test "deletes type in listing", %{conn: conn, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/catalog")
assert index_live |> element(~s/a[aria-label="Delete #{type.name}"]/) |> render_click()
refute has_element?(index_live, "#type-#{type.id}")
end
@ -253,7 +253,7 @@ defmodule CanneryWeb.TypeLiveTest do
test "shows used packs on toggle",
%{conn: conn, pack: pack, current_user: current_user} do
{:ok, index_live, html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, html} = live(conn, ~p"/catalog")
assert html =~ "Show used"
refute html =~ "Used rounds"
@ -277,7 +277,7 @@ defmodule CanneryWeb.TypeLiveTest do
shot_record_fixture(%{count: 5}, current_user, pack)
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, ~p"/catalog")
html =
index_live
@ -296,7 +296,7 @@ defmodule CanneryWeb.TypeLiveTest do
conn: conn,
type: %{name: name, bullet_type: bullet_type} = type
} do
{:ok, _show_live, html} = live(conn, Routes.type_show_path(conn, :show, type))
{:ok, _show_live, html} = live(conn, ~p"/type/#{type}")
assert html =~ name
assert html =~ bullet_type
@ -304,12 +304,12 @@ defmodule CanneryWeb.TypeLiveTest do
test "updates type within modal",
%{conn: conn, current_user: current_user, type: %{name: name} = type} do
{:ok, show_live, _html} = live(conn, Routes.type_show_path(conn, :show, type))
{:ok, show_live, _html} = live(conn, ~p"/type/#{type}")
assert show_live |> element(~s/a[aria-label="Edit #{type.name}"]/) |> render_click() =~
"Edit #{name}"
assert_patch(show_live, Routes.type_show_path(conn, :edit, type))
assert_patch(show_live, ~p"/type/#{type}/edit")
assert show_live
|> form("#type-form")
@ -319,7 +319,7 @@ defmodule CanneryWeb.TypeLiveTest do
show_live
|> form("#type-form")
|> render_submit(type: @update_attrs)
|> follow_redirect(conn, Routes.type_show_path(conn, :show, type))
|> follow_redirect(conn, ~p"/type/#{type}")
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} updated successfully"
@ -335,7 +335,7 @@ defmodule CanneryWeb.TypeLiveTest do
type: %{name: type_name} = type,
container: %{name: container_name}
} do
{:ok, _show_live, html} = live(conn, Routes.type_show_path(conn, :show, type))
{:ok, _show_live, html} = live(conn, ~p"/type/#{type}")
assert html =~ type_name
assert html =~ "\n20\n"
@ -344,7 +344,7 @@ defmodule CanneryWeb.TypeLiveTest do
test "displays pack in table",
%{conn: conn, type: type, container: %{name: container_name}} do
{:ok, show_live, _html} = live(conn, Routes.type_show_path(conn, :show, type))
{:ok, show_live, _html} = live(conn, ~p"/type/#{type}")
html =
show_live
@ -361,7 +361,7 @@ defmodule CanneryWeb.TypeLiveTest do
test "displays empty packs on toggle",
%{conn: conn, type: type, container: %{name: container_name}} do
{:ok, show_live, html} = live(conn, Routes.type_show_path(conn, :show, type))
{:ok, show_live, html} = live(conn, ~p"/type/#{type}")
assert html =~ "Show used"
refute html =~ "\n20\n"
@ -377,7 +377,7 @@ defmodule CanneryWeb.TypeLiveTest do
test "displays empty packs in table on toggle",
%{conn: conn, type: type, container: %{name: container_name}} do
{:ok, show_live, _html} = live(conn, Routes.type_show_path(conn, :show, type))
{:ok, show_live, _html} = live(conn, ~p"/type/#{type}")
html =
show_live

View File

@ -1,19 +0,0 @@
defmodule CanneryWeb.ErrorViewTest do
@moduledoc """
Tests the error view
"""
use CanneryWeb.ConnCase, async: true
# Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View
@moduletag :error_view_test
test "renders 404.html" do
assert render_to_string(CanneryWeb.ErrorView, "404.html", []) =~ "Not found"
end
test "renders 500.html" do
assert render_to_string(CanneryWeb.ErrorView, "500.html", []) =~ "Internal Server Error"
end
end

View File

@ -1,8 +0,0 @@
defmodule CanneryWeb.HomeViewTest do
use CanneryWeb.ConnCase, async: true
# When testing helpers, you may want to import Phoenix.HTML and
# use functions such as safe_to_string() to convert the helper
# result into an HTML string.
# import Phoenix.HTML
end

View File

@ -1,8 +0,0 @@
defmodule CanneryWeb.LayoutViewTest do
use CanneryWeb.ConnCase, async: true
# When testing helpers, you may want to import Phoenix.HTML and
# use functions such as safe_to_string() to convert the helper
# result into an HTML string.
# import Phoenix.HTML
end