use atom keys in tests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -4,7 +4,6 @@ defmodule CanneryWeb.UserAuthTest do
|
||||
"""
|
||||
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Accounts
|
||||
alias CanneryWeb.UserAuth
|
||||
|
||||
@ -148,7 +147,7 @@ defmodule CanneryWeb.UserAuthTest do
|
||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||
|
||||
assert get_flash(conn, :error) ==
|
||||
dgettext("errors", "You must confirm your account and log in to access this page.")
|
||||
"You must confirm your account and log in to access this page."
|
||||
end
|
||||
|
||||
test "stores the path to redirect to on GET", %{conn: conn} do
|
||||
|
@ -4,7 +4,6 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
|
||||
"""
|
||||
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.{Accounts, Repo}
|
||||
|
||||
@moduletag :user_confirmation_controller_test
|
||||
@ -17,7 +16,7 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
|
||||
test "renders the confirmation page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_confirmation_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ dgettext("actions", "Resend confirmation instructions")
|
||||
assert response =~ "Resend confirmation instructions"
|
||||
end
|
||||
end
|
||||
|
||||
@ -25,18 +24,12 @@ defmodule CanneryWeb.UserConfirmationControllerTest 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}
|
||||
})
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{user: %{email: user.email}})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system and it has not been confirmed yet, " <>
|
||||
"you will receive an email with instructions shortly."
|
||||
)
|
||||
"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"
|
||||
end
|
||||
@ -45,34 +38,24 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
|
||||
Repo.update!(Accounts.User.confirm_changeset(user))
|
||||
|
||||
conn =
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||
"user" => %{"email" => user.email}
|
||||
})
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{user: %{email: user.email}})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system and it has not been confirmed yet, " <>
|
||||
"you will receive an email with instructions shortly."
|
||||
)
|
||||
"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"}
|
||||
user: %{email: "unknown@example.com"}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system and it has not been confirmed yet, " <>
|
||||
"you will receive an email with instructions shortly."
|
||||
)
|
||||
"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) == []
|
||||
end
|
||||
@ -87,10 +70,7 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
|
||||
|
||||
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext("prompts", "%{email} confirmed successfully", email: user.email)
|
||||
|
||||
assert get_flash(conn, :info) =~ "#{user.email} confirmed successfully"
|
||||
assert Accounts.get_user!(user.id).confirmed_at
|
||||
refute get_session(conn, :user_token)
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
@ -99,8 +79,7 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
|
||||
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "User confirmation link is invalid or it has expired")
|
||||
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
|
||||
|
||||
# When logged in
|
||||
conn =
|
||||
@ -115,10 +94,7 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
|
||||
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) =~
|
||||
dgettext("errors", "User confirmation link is invalid or it has expired")
|
||||
|
||||
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
|
||||
refute Accounts.get_user!(user.id).confirmed_at
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,6 @@ defmodule CanneryWeb.UserRegistrationControllerTest do
|
||||
"""
|
||||
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
import CanneryWeb.Gettext
|
||||
|
||||
@moduletag :user_registration_controller_test
|
||||
|
||||
@ -12,8 +11,8 @@ defmodule CanneryWeb.UserRegistrationControllerTest do
|
||||
test "renders registration page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_registration_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ dgettext("actions", "Register")
|
||||
assert response =~ dgettext("actions", "Log in")
|
||||
assert response =~ "Register"
|
||||
assert response =~ "Log in"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn} do
|
||||
@ -29,11 +28,11 @@ defmodule CanneryWeb.UserRegistrationControllerTest do
|
||||
|
||||
conn =
|
||||
post(conn, Routes.user_registration_path(conn, :create), %{
|
||||
"user" => valid_user_attributes(email: email)
|
||||
user: valid_user_attributes(email: email)
|
||||
})
|
||||
|
||||
assert get_session(conn, :phoenix_flash) == %{
|
||||
"info" => dgettext("prompts", "Please check your email to verify your account")
|
||||
"info" => "Please check your email to verify your account"
|
||||
}
|
||||
|
||||
assert redirected_to(conn) =~ "/"
|
||||
@ -48,11 +47,11 @@ 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"}
|
||||
user: %{email: "with spaces", password: "too short"}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ gettext("Register")
|
||||
assert response =~ "Register"
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "should be at least 12 character"
|
||||
end
|
||||
|
@ -4,7 +4,6 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
||||
"""
|
||||
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.{Accounts, Repo}
|
||||
|
||||
@moduletag :user_reset_password_controller_test
|
||||
@ -17,7 +16,7 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
||||
test "renders the reset password page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_reset_password_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ dgettext("actions", "Forgot your password?")
|
||||
assert response =~ "Forgot your password?"
|
||||
end
|
||||
end
|
||||
|
||||
@ -25,17 +24,12 @@ defmodule CanneryWeb.UserResetPasswordControllerTest 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}
|
||||
})
|
||||
post(conn, Routes.user_reset_password_path(conn, :create), %{user: %{email: user.email}})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system, you will receive instructions to reset your password shortly."
|
||||
)
|
||||
"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
|
||||
@ -43,16 +37,13 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
||||
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"}
|
||||
user: %{email: "unknown@example.com"}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system, you will receive instructions to reset your password shortly."
|
||||
)
|
||||
"If your email is in our system, you will receive instructions to reset your password shortly."
|
||||
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
end
|
||||
@ -70,15 +61,13 @@ defmodule CanneryWeb.UserResetPasswordControllerTest do
|
||||
|
||||
test "renders reset password", %{conn: conn, token: token} do
|
||||
conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
|
||||
assert html_response(conn, 200) =~ dgettext("actions", "Reset password")
|
||||
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) =~
|
||||
dgettext("errors", "Reset password link is invalid or it has expired")
|
||||
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
|
||||
end
|
||||
end
|
||||
|
||||
@ -95,39 +84,37 @@ 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), %{
|
||||
"user" => %{
|
||||
"password" => "new valid password",
|
||||
"password_confirmation" => "new valid password"
|
||||
user: %{
|
||||
password: "new valid password",
|
||||
password_confirmation: "new valid password"
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ dgettext("prompts", "Password reset successfully")
|
||||
assert get_flash(conn, :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), %{
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
user: %{
|
||||
password: "too short",
|
||||
password_confirmation: "does not match"
|
||||
}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ gettext("Reset password")
|
||||
assert response =~ dgettext("errors", "should be at least 12 character(s)")
|
||||
assert response =~ dgettext("errors", "does not match password")
|
||||
assert response =~ "Reset password"
|
||||
assert response =~ "should be at least 12 character(s)"
|
||||
assert response =~ "does not match password"
|
||||
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) =~
|
||||
dgettext("errors", "Reset password link is invalid or it has expired")
|
||||
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,6 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
"""
|
||||
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
import CanneryWeb.Gettext
|
||||
|
||||
@moduletag :user_session_controller_test
|
||||
|
||||
@ -16,7 +15,7 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
test "renders log in page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_session_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ dgettext("actions", "Log in")
|
||||
assert response =~ "Log in"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn, current_user: current_user} do
|
||||
@ -29,7 +28,7 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
test "logs the user in", %{conn: conn, current_user: current_user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{"email" => current_user.email, "password" => valid_user_password()}
|
||||
user: %{email: current_user.email, password: valid_user_password()}
|
||||
})
|
||||
|
||||
assert get_session(conn, :user_token)
|
||||
@ -39,16 +38,16 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
conn = get(conn, "/")
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ current_user.email
|
||||
assert response =~ dgettext("prompts", "Are you sure you want to log out?")
|
||||
assert response =~ "Are you sure you want to log out?"
|
||||
end
|
||||
|
||||
test "logs the user in with remember me", %{conn: conn, current_user: current_user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{
|
||||
"email" => current_user.email,
|
||||
"password" => valid_user_password(),
|
||||
"remember_me" => "true"
|
||||
user: %{
|
||||
email: current_user.email,
|
||||
password: valid_user_password(),
|
||||
remember_me: "true"
|
||||
}
|
||||
})
|
||||
|
||||
@ -61,9 +60,9 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
conn
|
||||
|> init_test_session(user_return_to: "/foo/bar")
|
||||
|> post(Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{
|
||||
"email" => current_user.email,
|
||||
"password" => valid_user_password()
|
||||
user: %{
|
||||
email: current_user.email,
|
||||
password: valid_user_password()
|
||||
}
|
||||
})
|
||||
|
||||
@ -74,12 +73,12 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
%{conn: conn, current_user: current_user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{"email" => current_user.email, "password" => "bad"}
|
||||
user: %{email: current_user.email, password: "bad"}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ dgettext("actions", "Log in")
|
||||
assert response =~ dgettext("errors", "Invalid email or password")
|
||||
assert response =~ "Log in"
|
||||
assert response =~ "Invalid email or password"
|
||||
end
|
||||
end
|
||||
|
||||
@ -88,14 +87,14 @@ defmodule CanneryWeb.UserSessionControllerTest do
|
||||
conn = conn |> log_in_user(current_user) |> delete(Routes.user_session_path(conn, :delete))
|
||||
assert redirected_to(conn) == "/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ gettext("Logged out successfully")
|
||||
assert get_flash(conn, :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) == "/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ gettext("Logged out successfully")
|
||||
assert get_flash(conn, :info) =~ "Logged out successfully"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,6 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
"""
|
||||
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Accounts
|
||||
|
||||
@moduletag :user_settings_controller_test
|
||||
@ -15,7 +14,7 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
test "renders settings page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :edit))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ gettext("Settings")
|
||||
assert response =~ "Settings"
|
||||
end
|
||||
|
||||
test "redirects if user is not logged in" do
|
||||
@ -30,40 +29,36 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
%{conn: conn, current_user: current_user} do
|
||||
new_password_conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_password",
|
||||
"current_password" => valid_user_password(),
|
||||
"user" => %{
|
||||
"password" => "new valid password",
|
||||
"password_confirmation" => "new valid password"
|
||||
action: "update_password",
|
||||
current_password: valid_user_password(),
|
||||
user: %{
|
||||
password: "new valid password",
|
||||
password_confirmation: "new valid password"
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token)
|
||||
|
||||
assert get_flash(new_password_conn, :info) =~
|
||||
dgettext("actions", "Password updated successfully")
|
||||
|
||||
assert get_flash(new_password_conn, :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), %{
|
||||
"action" => "update_password",
|
||||
"current_password" => "invalid",
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
action: "update_password",
|
||||
current_password: "invalid",
|
||||
user: %{
|
||||
password: "too short",
|
||||
password_confirmation: "does not match"
|
||||
}
|
||||
})
|
||||
|
||||
response = html_response(old_password_conn, 200)
|
||||
assert response =~ gettext("Settings")
|
||||
assert response =~ dgettext("errors", "should be at least 12 character(s)")
|
||||
assert response =~ dgettext("errors", "does not match password")
|
||||
assert response =~ dgettext("errors", "is not valid")
|
||||
|
||||
assert response =~ "Settings"
|
||||
assert response =~ "should be at least 12 character(s)"
|
||||
assert response =~ "does not match password"
|
||||
assert response =~ "is not valid"
|
||||
assert get_session(old_password_conn, :user_token) == get_session(conn, :user_token)
|
||||
end
|
||||
end
|
||||
@ -73,18 +68,15 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
test "updates the user email", %{conn: conn, current_user: current_user} do
|
||||
conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_email",
|
||||
"current_password" => valid_user_password(),
|
||||
"user" => %{"email" => unique_user_email()}
|
||||
action: "update_email",
|
||||
current_password: valid_user_password(),
|
||||
user: %{email: unique_user_email()}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"A link to confirm your email change has been sent to the new address."
|
||||
)
|
||||
"A link to confirm your email change has been sent to the new address."
|
||||
|
||||
assert Accounts.get_user_by_email(current_user.email)
|
||||
end
|
||||
@ -92,15 +84,15 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
test "does not update email on invalid data", %{conn: conn} do
|
||||
conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_email",
|
||||
"current_password" => "invalid",
|
||||
"user" => %{"email" => "with spaces"}
|
||||
action: "update_email",
|
||||
current_password: "invalid",
|
||||
user: %{email: "with spaces"}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ gettext("Settings")
|
||||
assert response =~ dgettext("errors", "must have the @ sign and no spaces")
|
||||
assert response =~ dgettext("errors", "is not valid")
|
||||
assert response =~ "Settings"
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "is not valid"
|
||||
end
|
||||
end
|
||||
|
||||
@ -124,24 +116,19 @@ defmodule CanneryWeb.UserSettingsControllerTest do
|
||||
%{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) =~ dgettext("prompts", "Email changed successfully")
|
||||
assert get_flash(conn, :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) =~
|
||||
dgettext("errors", "Email change link is invalid or it has expired")
|
||||
assert get_flash(conn, :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) =~
|
||||
dgettext("errors", "Email change link is invalid or it has expired")
|
||||
|
||||
assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired"
|
||||
assert Accounts.get_user_by_email(current_user.email)
|
||||
end
|
||||
|
||||
|
@ -5,43 +5,40 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|
||||
use CanneryWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.{Ammo, Repo}
|
||||
|
||||
@moduletag :ammo_group_live_test
|
||||
@shot_group_create_attrs %{"ammo_left" => 5, "notes" => "some notes"}
|
||||
@shot_group_update_attrs %{
|
||||
"count" => 5,
|
||||
"date" => ~N[2022-02-13 03:17:00],
|
||||
"notes" => "some updated notes"
|
||||
}
|
||||
@create_attrs %{"count" => 42, "notes" => "some notes", "price_paid" => 120.5}
|
||||
@update_attrs %{"count" => 43, "notes" => "some updated notes", "price_paid" => 456.7}
|
||||
@create_attrs %{count: 42, notes: "some notes", price_paid: 120.5}
|
||||
@update_attrs %{count: 43, notes: "some updated notes", price_paid: 456.7}
|
||||
@invalid_attrs %{count: nil, notes: nil, price_paid: nil}
|
||||
@ammo_group_create_limit 10_000
|
||||
@shot_group_create_attrs %{ammo_left: 5, notes: "some notes"}
|
||||
@shot_group_update_attrs %{
|
||||
count: 5,
|
||||
date: ~N[2022-02-13 03:17:00],
|
||||
notes: "some updated notes"
|
||||
}
|
||||
@shot_group_invalid_attrs %{ammo_left: nil, count: nil, notes: nil}
|
||||
@empty_attrs %{
|
||||
"price_paid" => 50,
|
||||
"count" => 20
|
||||
price_paid: 50,
|
||||
count: 20
|
||||
}
|
||||
@shot_group_attrs %{
|
||||
"price_paid" => 50,
|
||||
"count" => 20
|
||||
price_paid: 50,
|
||||
count: 20
|
||||
}
|
||||
|
||||
# @invalid_attrs %{count: -1, notes: nil, price_paid: nil}
|
||||
|
||||
defp create_ammo_group(%{current_user: current_user}) do
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
container = container_fixture(current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(@create_attrs, ammo_type, container, current_user)
|
||||
|
||||
%{ammo_type: ammo_type, ammo_group: ammo_group, container: container}
|
||||
[ammo_type: ammo_type, ammo_group: ammo_group, container: container]
|
||||
end
|
||||
|
||||
defp create_shot_group(%{current_user: current_user, ammo_group: ammo_group}) do
|
||||
shot_group = shot_group_fixture(@shot_group_update_attrs, current_user, ammo_group)
|
||||
ammo_group = ammo_group |> Repo.reload!()
|
||||
|
||||
%{ammo_group: ammo_group, shot_group: shot_group}
|
||||
[ammo_group: ammo_group, shot_group: shot_group]
|
||||
end
|
||||
|
||||
defp create_empty_ammo_group(%{
|
||||
@ -52,7 +49,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
{1, [ammo_group]} = ammo_group_fixture(@empty_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, ammo_group)
|
||||
ammo_group = ammo_group |> Repo.reload!()
|
||||
%{empty_ammo_group: ammo_group, shot_group: shot_group}
|
||||
[empty_ammo_group: ammo_group, shot_group: shot_group]
|
||||
end
|
||||
|
||||
describe "Index of ammo group" do
|
||||
@ -60,19 +57,18 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|
||||
test "lists all ammo_groups", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
ammo_group = ammo_group |> Repo.preload(:ammo_type)
|
||||
assert html =~ gettext("Ammo")
|
||||
assert html =~ "Ammo"
|
||||
assert html =~ ammo_group.ammo_type.name
|
||||
end
|
||||
|
||||
test "can sort by type",
|
||||
%{conn: conn, container: container, current_user: current_user} do
|
||||
rifle_type = ammo_type_fixture(%{"type" => "rifle"}, current_user)
|
||||
rifle_type = ammo_type_fixture(%{type: "rifle"}, current_user)
|
||||
{1, [rifle_ammo_group]} = ammo_group_fixture(rifle_type, container, current_user)
|
||||
shotgun_type = ammo_type_fixture(%{"type" => "shotgun"}, current_user)
|
||||
shotgun_type = ammo_type_fixture(%{type: "shotgun"}, current_user)
|
||||
{1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_type, container, current_user)
|
||||
pistol_type = ammo_type_fixture(%{"type" => "pistol"}, current_user)
|
||||
pistol_type = ammo_type_fixture(%{type: "pistol"}, current_user)
|
||||
{1, [pistol_ammo_group]} = ammo_group_fixture(pistol_type, container, current_user)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
@ -128,10 +124,9 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
assert html =~ ammo_group.ammo_type.name
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/,
|
||||
search: %{search_term: ammo_group.ammo_type.name}
|
||||
)
|
||||
|> render_change() =~ ammo_group.ammo_type.name
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ammo_group.ammo_type.name}) =~
|
||||
ammo_group.ammo_type.name
|
||||
|
||||
assert_patch(
|
||||
index_live,
|
||||
@ -139,14 +134,15 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
)
|
||||
|
||||
refute index_live
|
||||
|> form(~s/form[phx-change="search"]/, search: %{search_term: "something_else"})
|
||||
|> render_change() =~ ammo_group.ammo_type.name
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: "something_else"}) =~
|
||||
ammo_group.ammo_type.name
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :search, "something_else"))
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/, search: %{search_term: ""})
|
||||
|> render_change() =~ ammo_group.ammo_type.name
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ""}) =~ ammo_group.ammo_type.name
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :index))
|
||||
end
|
||||
@ -154,85 +150,65 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
test "saves a single new ammo_group", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "Add Ammo")) |> render_click() =~
|
||||
dgettext("actions", "Add Ammo")
|
||||
|
||||
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :new))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form", ammo_group: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("prompts", "Ammo added successfully")
|
||||
assert html =~ "Ammo added successfully"
|
||||
assert html =~ "\n42\n"
|
||||
end
|
||||
|
||||
test "saves multiple new ammo_groups", %{conn: conn, current_user: current_user} do
|
||||
multiplier = 25
|
||||
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "Add Ammo")) |> render_click() =~
|
||||
dgettext("actions", "Add Ammo")
|
||||
|
||||
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :new))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form",
|
||||
ammo_group: @create_attrs |> Map.put("multiplier", to_string(multiplier))
|
||||
)
|
||||
|> render_submit()
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @create_attrs |> Map.put(:multiplier, multiplier))
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("prompts", "Ammo added successfully")
|
||||
assert html =~ "Ammo added successfully"
|
||||
assert Ammo.list_ammo_groups(nil, :all, current_user) |> Enum.count() == multiplier + 1
|
||||
end
|
||||
|
||||
test "does not save invalid number of new ammo_groups", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "Add Ammo")) |> render_click() =~
|
||||
dgettext("actions", "Add Ammo")
|
||||
|
||||
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :new))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form", ammo_group: @create_attrs |> Map.put("multiplier", "0"))
|
||||
|> render_submit() =~
|
||||
dgettext(
|
||||
"errors",
|
||||
"Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}",
|
||||
multiplier: 0,
|
||||
max: @ammo_group_create_limit
|
||||
)
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @create_attrs |> Map.put(:multiplier, "0")) =~
|
||||
"Invalid number of copies, must be between 1 and #{@ammo_group_create_limit}. Was 0"
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form",
|
||||
ammo_group:
|
||||
@create_attrs |> Map.put("multiplier", to_string(@ammo_group_create_limit + 1))
|
||||
)
|
||||
|> render_submit() =~
|
||||
dgettext(
|
||||
"errors",
|
||||
"Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}",
|
||||
multiplier: @ammo_group_create_limit + 1,
|
||||
max: @ammo_group_create_limit
|
||||
)
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(
|
||||
ammo_group: @create_attrs |> Map.put(:multiplier, @ammo_group_create_limit + 1)
|
||||
) =~
|
||||
"Invalid number of copies, must be between 1 and #{@ammo_group_create_limit}. Was #{@ammo_group_create_limit + 1}"
|
||||
end
|
||||
|
||||
test "updates ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do
|
||||
@ -240,22 +216,21 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> render_click() =~
|
||||
gettext("Edit ammo")
|
||||
|> render_click() =~ "Edit ammo"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :edit, ammo_group))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form", ammo_group: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("prompts", "Ammo updated successfully")
|
||||
assert html =~ "Ammo updated successfully"
|
||||
assert html =~ "\n43\n"
|
||||
end
|
||||
|
||||
@ -267,24 +242,38 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ dgettext("actions", "Add Ammo")
|
||||
assert html =~ gettext("$%{amount}", amount: display_currency(120.5))
|
||||
assert html =~ "Add Ammo"
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :clone, ammo_group))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
|
||||
{:ok, _view, html} =
|
||||
{:ok, _index_live, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("prompts", "Ammo added successfully")
|
||||
assert html =~ "Ammo added successfully"
|
||||
assert html =~ "\n42\n"
|
||||
assert html =~ gettext("$%{amount}", amount: display_currency(120.5))
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
end
|
||||
|
||||
test "checks validity when cloning", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "Add Ammo"
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :clone, ammo_group))
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
end
|
||||
|
||||
test "clones ammo_group in listing with updates", %{conn: conn, ammo_group: ammo_group} do
|
||||
@ -295,24 +284,23 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ dgettext("actions", "Add Ammo")
|
||||
assert html =~ gettext("$%{amount}", amount: display_currency(120.5))
|
||||
|
||||
assert html =~ "Add Ammo"
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :clone, ammo_group))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form", ammo_group: Map.merge(@create_attrs, %{"count" => 43}))
|
||||
|> render_submit()
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @create_attrs |> Map.put(:count, 43))
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("prompts", "Ammo added successfully")
|
||||
assert html =~ "Ammo added successfully"
|
||||
assert html =~ "\n43\n"
|
||||
assert html =~ gettext("$%{amount}", amount: display_currency(120.5))
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
end
|
||||
|
||||
test "deletes ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do
|
||||
@ -328,22 +316,20 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "Record shots")) |> render_click() =~
|
||||
gettext("Record shots")
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :add_shot_group, ammo_group))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#shot_group-form", shot_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "is invalid")
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form", shot_group: @shot_group_create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_create_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("prompts", "Shots recorded successfully")
|
||||
assert html =~ "Shots recorded successfully"
|
||||
end
|
||||
|
||||
@spec display_currency(float()) :: String.t()
|
||||
@ -360,21 +346,20 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
} do
|
||||
{:ok, show_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("actions", "Show used")
|
||||
refute html =~ gettext("$%{amount}", amount: display_currency(50.00))
|
||||
assert html =~ "Show used"
|
||||
refute html =~ "$#{display_currency(50.00)}"
|
||||
|
||||
percentage = ammo_group |> Ammo.get_percentage_remaining(current_user)
|
||||
refute html =~ "\n#{gettext("%{percentage}%", percentage: percentage)}\n"
|
||||
refute html =~ "\n#{"#{percentage}%"}\n"
|
||||
|
||||
html =
|
||||
show_live
|
||||
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_show_used-label"}]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ gettext("$%{amount}", amount: display_currency(50.00))
|
||||
|
||||
assert html =~ "$#{display_currency(50.00)}"
|
||||
percentage = ammo_group |> Ammo.get_percentage_remaining(current_user)
|
||||
assert html =~ "\n#{gettext("%{percentage}%", percentage: percentage)}\n"
|
||||
assert html =~ "\n#{"#{percentage}%"}\n"
|
||||
end
|
||||
end
|
||||
|
||||
@ -383,9 +368,8 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|
||||
test "displays ammo_group", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
|
||||
ammo_group = ammo_group |> Repo.preload(:ammo_type)
|
||||
assert html =~ gettext("Show Ammo")
|
||||
assert html =~ "Show Ammo"
|
||||
assert html =~ ammo_group.ammo_type.name
|
||||
end
|
||||
|
||||
@ -394,44 +378,41 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|
||||
assert show_live
|
||||
|> element(~s/a[aria-label="Edit ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> render_click() =~
|
||||
gettext("Edit Ammo")
|
||||
|> render_click() =~ "Edit Ammo"
|
||||
|
||||
assert_patch(show_live, Routes.ammo_group_show_path(conn, :edit, ammo_group))
|
||||
|
||||
# assert show_live
|
||||
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert show_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
show_live
|
||||
|> form("#ammo_group-form", ammo_group: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
|
||||
assert html =~ dgettext("prompts", "Ammo updated successfully")
|
||||
assert html =~ "Ammo updated successfully"
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "Record shots")) |> render_click() =~
|
||||
gettext("Record shots")
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.ammo_group_show_path(conn, :add_shot_group, ammo_group))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#shot_group-form", shot_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "is invalid")
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form", shot_group: @shot_group_create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_create_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
|
||||
assert html =~ dgettext("prompts", "Shots recorded successfully")
|
||||
assert html =~ "Shots recorded successfully"
|
||||
end
|
||||
end
|
||||
|
||||
@ -444,25 +425,24 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit shot group of #{shot_group.count} shots"]/)
|
||||
|> render_click() =~
|
||||
gettext("Edit Shot Records")
|
||||
|> render_click() =~ "Edit Shot Records"
|
||||
|
||||
assert_patch(
|
||||
index_live,
|
||||
Routes.ammo_group_show_path(conn, :edit_shot_group, ammo_group, shot_group)
|
||||
)
|
||||
|
||||
# assert index_live
|
||||
# |> form("#shot_group-form", shot_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "is invalid")
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form", shot_group: @shot_group_update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_update_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
|
||||
assert html =~ dgettext("actions", "Shot records updated successfully")
|
||||
assert html =~ "Shot records updated successfully"
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
|
@ -5,54 +5,51 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|
||||
use CanneryWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.{Ammo, Repo}
|
||||
|
||||
@moduletag :ammo_type_live_test
|
||||
|
||||
@create_attrs %{
|
||||
"bullet_type" => "some bullet_type",
|
||||
"case_material" => "some case_material",
|
||||
"desc" => "some desc",
|
||||
"manufacturer" => "some manufacturer",
|
||||
"name" => "some name",
|
||||
"grains" => 120
|
||||
bullet_type: "some bullet_type",
|
||||
case_material: "some case_material",
|
||||
desc: "some desc",
|
||||
manufacturer: "some manufacturer",
|
||||
name: "some name",
|
||||
grains: 120
|
||||
}
|
||||
@update_attrs %{
|
||||
"bullet_type" => "some updated bullet_type",
|
||||
"case_material" => "some updated case_material",
|
||||
"desc" => "some updated desc",
|
||||
"manufacturer" => "some updated manufacturer",
|
||||
"name" => "some updated name",
|
||||
"grains" => 456
|
||||
bullet_type: "some updated bullet_type",
|
||||
case_material: "some updated case_material",
|
||||
desc: "some updated desc",
|
||||
manufacturer: "some updated manufacturer",
|
||||
name: "some updated name",
|
||||
grains: 456
|
||||
}
|
||||
@invalid_attrs %{
|
||||
bullet_type: nil,
|
||||
case_material: nil,
|
||||
desc: nil,
|
||||
manufacturer: nil,
|
||||
name: nil,
|
||||
grains: nil
|
||||
}
|
||||
@ammo_group_attrs %{
|
||||
"notes" => "some ammo group",
|
||||
"count" => 20
|
||||
notes: "some ammo group",
|
||||
count: 20
|
||||
}
|
||||
@shot_group_attrs %{
|
||||
"notes" => "some shot group",
|
||||
"count" => 20
|
||||
notes: "some shot group",
|
||||
count: 20
|
||||
}
|
||||
|
||||
# @invalid_attrs %{
|
||||
# "bullet_type" => nil,
|
||||
# "case_material" => nil,
|
||||
# "desc" => nil,
|
||||
# "manufacturer" => nil,
|
||||
# "name" => nil,
|
||||
# "grains" => nil
|
||||
# }
|
||||
|
||||
defp create_ammo_type(%{current_user: current_user}) do
|
||||
%{ammo_type: ammo_type_fixture(@create_attrs, current_user)}
|
||||
[ammo_type: ammo_type_fixture(@create_attrs, current_user)]
|
||||
end
|
||||
|
||||
defp create_ammo_group(%{ammo_type: ammo_type, current_user: current_user}) do
|
||||
container = container_fixture(current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
|
||||
|
||||
%{ammo_group: ammo_group, container: container}
|
||||
[ammo_group: ammo_group, container: container]
|
||||
end
|
||||
|
||||
defp create_empty_ammo_group(%{ammo_type: ammo_type, current_user: current_user}) do
|
||||
@ -60,8 +57,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, ammo_group)
|
||||
ammo_group = ammo_group |> Repo.reload!()
|
||||
|
||||
%{ammo_group: ammo_group, container: container, shot_group: shot_group}
|
||||
[ammo_group: ammo_group, container: container, shot_group: shot_group]
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
@ -69,15 +65,14 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|
||||
test "lists all ammo_types", %{conn: conn, ammo_type: ammo_type} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
assert html =~ gettext("Catalog")
|
||||
assert html =~ "Catalog"
|
||||
assert html =~ ammo_type.bullet_type
|
||||
end
|
||||
|
||||
test "can sort by type", %{conn: conn, current_user: current_user} do
|
||||
rifle_type = ammo_type_fixture(%{"type" => "rifle"}, current_user)
|
||||
shotgun_type = ammo_type_fixture(%{"type" => "shotgun"}, current_user)
|
||||
pistol_type = ammo_type_fixture(%{"type" => "pistol"}, current_user)
|
||||
rifle_type = ammo_type_fixture(%{type: "rifle"}, current_user)
|
||||
shotgun_type = ammo_type_fixture(%{type: "shotgun"}, current_user)
|
||||
pistol_type = ammo_type_fixture(%{type: "pistol"}, current_user)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
@ -152,14 +147,12 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
test "saves new ammo_type", %{conn: conn, current_user: current_user, ammo_type: ammo_type} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "New Ammo type")) |> render_click() =~
|
||||
gettext("New Ammo type")
|
||||
|
||||
assert index_live |> element("a", "New Ammo type") |> render_click() =~ "New Ammo type"
|
||||
assert_patch(index_live, Routes.ammo_type_index_path(conn, :new))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_type-form", ammo_type: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_type-form")
|
||||
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
@ -168,7 +161,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} created successfully", name: ammo_type.name)
|
||||
assert html =~ "#{ammo_type.name} created successfully"
|
||||
assert html =~ "some bullet_type"
|
||||
end
|
||||
|
||||
@ -177,13 +170,13 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element(~s/a[aria-label="Edit #{ammo_type.name}"]/) |> render_click() =~
|
||||
gettext("Edit %{ammo_type_name}", ammo_type_name: ammo_type.name)
|
||||
"Edit #{ammo_type.name}"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_type_index_path(conn, :edit, ammo_type))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_type-form", ammo_type: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_type-form")
|
||||
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
@ -192,7 +185,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} updated successfully", name: ammo_type.name)
|
||||
assert html =~ "#{ammo_type.name} updated successfully"
|
||||
assert html =~ "some updated bullet_type"
|
||||
end
|
||||
|
||||
@ -201,14 +194,14 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
html = index_live |> element(~s/a[aria-label="Clone #{ammo_type.name}"]/) |> render_click()
|
||||
assert html =~ gettext("New Ammo type")
|
||||
assert html =~ "New Ammo type"
|
||||
assert html =~ "some bullet_type"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_type_index_path(conn, :clone, ammo_type))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_type-form", ammo_type: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_type-form")
|
||||
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
@ -217,7 +210,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} created successfully", name: ammo_type.name)
|
||||
assert html =~ "#{ammo_type.name} created successfully"
|
||||
assert html =~ "some bullet_type"
|
||||
end
|
||||
|
||||
@ -226,31 +219,30 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
html = index_live |> element(~s/a[aria-label="Clone #{ammo_type.name}"]/) |> render_click()
|
||||
assert html =~ gettext("New Ammo type")
|
||||
assert html =~ "New Ammo type"
|
||||
assert html =~ "some bullet_type"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_type_index_path(conn, :clone, ammo_type))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#ammo_type-form", ammo_type: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#ammo_type-form")
|
||||
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_type-form")
|
||||
|> render_submit(
|
||||
ammo_type: Map.merge(@create_attrs, %{"bullet_type" => "some updated bullet_type"})
|
||||
ammo_type: Map.merge(@create_attrs, %{bullet_type: "some updated bullet_type"})
|
||||
)
|
||||
|> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} created successfully", name: ammo_type.name)
|
||||
assert html =~ "#{ammo_type.name} created successfully"
|
||||
assert html =~ "some updated bullet_type"
|
||||
end
|
||||
|
||||
test "deletes ammo_type in listing", %{conn: conn, ammo_type: ammo_type} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element(~s/a[aria-label="Delete #{ammo_type.name}"]/) |> render_click()
|
||||
refute has_element?(index_live, "#ammo_type-#{ammo_type.id}")
|
||||
end
|
||||
@ -263,27 +255,27 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
%{conn: conn, ammo_group: ammo_group, current_user: current_user} do
|
||||
{:ok, index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("actions", "Show used")
|
||||
refute html =~ gettext("Used rounds")
|
||||
refute html =~ gettext("Total ever rounds")
|
||||
refute html =~ gettext("Used packs")
|
||||
refute html =~ gettext("Total ever packs")
|
||||
assert html =~ "Show used"
|
||||
refute html =~ "Used rounds"
|
||||
refute html =~ "Total ever rounds"
|
||||
refute html =~ "Used packs"
|
||||
refute html =~ "Total ever packs"
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_show_used-label"}]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ gettext("Used rounds")
|
||||
assert html =~ gettext("Total ever rounds")
|
||||
assert html =~ gettext("Used packs")
|
||||
assert html =~ gettext("Total ever packs")
|
||||
assert html =~ "Used rounds"
|
||||
assert html =~ "Total ever rounds"
|
||||
assert html =~ "Used packs"
|
||||
assert html =~ "Total ever packs"
|
||||
|
||||
assert html =~ "\n20\n"
|
||||
assert html =~ "\n0\n"
|
||||
assert html =~ "\n1\n"
|
||||
|
||||
shot_group_fixture(%{"count" => 5}, current_user, ammo_group)
|
||||
shot_group_fixture(%{count: 5}, current_user, ammo_group)
|
||||
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
@ -315,13 +307,13 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
{:ok, show_live, _html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
|
||||
|
||||
assert show_live |> element(~s/a[aria-label="Edit #{ammo_type.name}"]/) |> render_click() =~
|
||||
gettext("Edit %{ammo_type_name}", ammo_type_name: name)
|
||||
"Edit #{name}"
|
||||
|
||||
assert_patch(show_live, Routes.ammo_type_show_path(conn, :edit, ammo_type))
|
||||
|
||||
# assert show_live
|
||||
# |> form("#ammo_type-form", ammo_type: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert show_live
|
||||
|> form("#ammo_type-form")
|
||||
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
show_live
|
||||
@ -330,7 +322,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|> follow_redirect(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
|
||||
|
||||
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} updated successfully", name: ammo_type.name)
|
||||
assert html =~ "#{ammo_type.name} updated successfully"
|
||||
assert html =~ "some updated bullet_type"
|
||||
end
|
||||
end
|
||||
@ -370,8 +362,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
test "displays empty ammo groups on toggle",
|
||||
%{conn: conn, ammo_type: ammo_type, container: %{name: container_name}} do
|
||||
{:ok, show_live, html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
|
||||
|
||||
assert html =~ dgettext("actions", "Show used")
|
||||
assert html =~ "Show used"
|
||||
refute html =~ "\n20\n"
|
||||
|
||||
html =
|
||||
@ -393,7 +384,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ dgettext("actions", "Show used")
|
||||
assert html =~ "Show used"
|
||||
refute html =~ "\n20\n"
|
||||
|
||||
html =
|
||||
|
@ -5,48 +5,46 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
|
||||
use CanneryWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Containers
|
||||
|
||||
@moduletag :container_live_test
|
||||
|
||||
@create_attrs %{
|
||||
"desc" => "some desc",
|
||||
"location" => "some location",
|
||||
"name" => "some name",
|
||||
"type" => "some type"
|
||||
desc: "some desc",
|
||||
location: "some location",
|
||||
name: "some name",
|
||||
type: "some type"
|
||||
}
|
||||
@update_attrs %{
|
||||
"desc" => "some updated desc",
|
||||
"location" => "some updated location",
|
||||
"name" => "some updated name",
|
||||
"type" => "some updated type"
|
||||
desc: "some updated desc",
|
||||
location: "some updated location",
|
||||
name: "some updated name",
|
||||
type: "some updated type"
|
||||
}
|
||||
@invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
|
||||
@ammo_type_attrs %{
|
||||
"bullet_type" => "some bullet_type",
|
||||
"case_material" => "some case_material",
|
||||
"desc" => "some desc",
|
||||
"manufacturer" => "some manufacturer",
|
||||
"name" => "some name",
|
||||
"grains" => 120
|
||||
bullet_type: "some bullet_type",
|
||||
case_material: "some case_material",
|
||||
desc: "some desc",
|
||||
manufacturer: "some manufacturer",
|
||||
name: "some name",
|
||||
grains: 120
|
||||
}
|
||||
@ammo_group_attrs %{
|
||||
"notes" => "some ammo group",
|
||||
"count" => 20
|
||||
notes: "some ammo group",
|
||||
count: 20
|
||||
}
|
||||
|
||||
# @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
|
||||
|
||||
defp create_container(%{current_user: current_user}) do
|
||||
container = container_fixture(@create_attrs, current_user)
|
||||
%{container: container}
|
||||
[container: container]
|
||||
end
|
||||
|
||||
defp create_ammo_group(%{container: container, current_user: current_user}) do
|
||||
ammo_type = ammo_type_fixture(@ammo_type_attrs, current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
|
||||
|
||||
%{ammo_type: ammo_type, ammo_group: ammo_group}
|
||||
[ammo_type: ammo_type, ammo_group: ammo_group]
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
@ -55,7 +53,7 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
test "lists all containers", %{conn: conn, container: container} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
assert html =~ gettext("Containers")
|
||||
assert html =~ "Containers"
|
||||
assert html =~ container.location
|
||||
end
|
||||
|
||||
@ -67,7 +65,7 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ gettext("Containers")
|
||||
assert html =~ "Containers"
|
||||
assert html =~ container.location
|
||||
end
|
||||
|
||||
@ -77,22 +75,20 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
assert html =~ container.location
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/,
|
||||
search: %{search_term: container.location}
|
||||
)
|
||||
|> render_change() =~ container.location
|
||||
|> 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))
|
||||
|
||||
refute index_live
|
||||
|> form(~s/form[phx-change="search"]/, search: %{search_term: "something_else"})
|
||||
|> render_change() =~ container.location
|
||||
|> 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 index_live
|
||||
|> form(~s/form[phx-change="search"]/, search: %{search_term: ""})
|
||||
|> render_change() =~ container.location
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ""}) =~ container.location
|
||||
|
||||
assert_patch(index_live, Routes.container_index_path(conn, :index))
|
||||
end
|
||||
@ -100,22 +96,20 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
test "saves new container", %{conn: conn, container: container} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "New Container")) |> render_click() =~
|
||||
gettext("New Container")
|
||||
|
||||
assert index_live |> element("a", "New Container") |> render_click() =~ "New Container"
|
||||
assert_patch(index_live, Routes.container_index_path(conn, :new))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#container-form", container: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#container-form")
|
||||
|> render_change(container: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#container-form", container: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#container-form")
|
||||
|> render_submit(container: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("prompts", "%{name} created successfully", name: container.name)
|
||||
assert html =~ "#{container.name} created successfully"
|
||||
assert html =~ "some location"
|
||||
end
|
||||
|
||||
@ -127,22 +121,22 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element(~s/a[aria-label="Edit #{container.name}"]/) |> render_click() =~
|
||||
gettext("Edit %{name}", name: container.name)
|
||||
"Edit #{container.name}"
|
||||
|
||||
assert_patch(index_live, Routes.container_index_path(conn, :edit, container))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#container-form", container: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#container-form")
|
||||
|> render_change(container: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#container-form", container: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#container-form")
|
||||
|> render_submit(container: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
container = container.id |> Containers.get_container!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} updated successfully", name: container.name)
|
||||
assert html =~ "#{container.name} updated successfully"
|
||||
assert html =~ "some updated location"
|
||||
end
|
||||
|
||||
@ -154,23 +148,23 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
html = index_live |> element(~s/a[aria-label="Clone #{container.name}"]/) |> render_click()
|
||||
assert html =~ gettext("New Container")
|
||||
assert html =~ "New Container"
|
||||
assert html =~ "some location"
|
||||
|
||||
assert_patch(index_live, Routes.container_index_path(conn, :clone, container))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#container-form", container: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#container-form")
|
||||
|> render_change(container: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#container-form", container: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#container-form")
|
||||
|> render_submit(container: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
container = container.id |> Containers.get_container!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} created successfully", name: container.name)
|
||||
assert html =~ "#{container.name} created successfully"
|
||||
assert html =~ "some location"
|
||||
end
|
||||
|
||||
@ -182,30 +176,29 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element(~s/a[aria-label="Clone #{container.name}"]/) |> render_click() =~
|
||||
gettext("New Container")
|
||||
"New Container"
|
||||
|
||||
assert_patch(index_live, Routes.container_index_path(conn, :clone, container))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#container-form", container: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#container-form")
|
||||
|> render_change(container: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#container-form",
|
||||
|> form("#container-form")
|
||||
|> render_submit(
|
||||
container: Map.merge(@create_attrs, %{location: "some updated location"})
|
||||
)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
container = container.id |> Containers.get_container!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} created successfully", name: container.name)
|
||||
assert html =~ "#{container.name} created successfully"
|
||||
assert html =~ "some updated location"
|
||||
end
|
||||
|
||||
test "deletes container in listing", %{conn: conn, container: container} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element(~s/a[aria-label="Delete #{container.name}"]/) |> render_click()
|
||||
refute has_element?(index_live, "#container-#{container.id}")
|
||||
end
|
||||
@ -219,7 +212,6 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
container: %{name: name, location: location} = container
|
||||
} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
|
||||
|
||||
assert html =~ name
|
||||
assert html =~ location
|
||||
end
|
||||
@ -232,32 +224,32 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
{:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container))
|
||||
|
||||
assert show_live |> element(~s/a[aria-label="Edit #{container.name}"]/) |> render_click() =~
|
||||
gettext("Edit %{name}", name: container.name)
|
||||
"Edit #{container.name}"
|
||||
|
||||
assert_patch(show_live, Routes.container_show_path(conn, :edit, container))
|
||||
|
||||
# assert show_live
|
||||
# |> form("#container-form", container: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert show_live
|
||||
|> form("#container-form")
|
||||
|> render_change(container: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
show_live
|
||||
|> form("#container-form", container: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#container-form")
|
||||
|> render_submit(container: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.container_show_path(conn, :show, container))
|
||||
|
||||
container = container.id |> Containers.get_container!(current_user)
|
||||
assert html =~ dgettext("prompts", "%{name} updated successfully", name: container.name)
|
||||
assert html =~ "#{container.name} updated successfully"
|
||||
assert html =~ "some updated location"
|
||||
end
|
||||
|
||||
test "can sort by type",
|
||||
%{conn: conn, container: container, current_user: current_user} do
|
||||
rifle_type = ammo_type_fixture(%{"type" => "rifle"}, current_user)
|
||||
rifle_type = ammo_type_fixture(%{type: "rifle"}, current_user)
|
||||
{1, [rifle_ammo_group]} = ammo_group_fixture(rifle_type, container, current_user)
|
||||
shotgun_type = ammo_type_fixture(%{"type" => "shotgun"}, current_user)
|
||||
shotgun_type = ammo_type_fixture(%{type: "shotgun"}, current_user)
|
||||
{1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_type, container, current_user)
|
||||
pistol_type = ammo_type_fixture(%{"type" => "pistol"}, current_user)
|
||||
pistol_type = ammo_type_fixture(%{type: "pistol"}, current_user)
|
||||
{1, [pistol_ammo_group]} = ammo_group_fixture(pistol_type, container, current_user)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
|
||||
|
@ -5,14 +5,13 @@ defmodule CanneryWeb.HomeLiveTest do
|
||||
|
||||
use CanneryWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import CanneryWeb.Gettext
|
||||
|
||||
@moduletag :home_live_test
|
||||
|
||||
test "disconnected and connected render", %{conn: conn} do
|
||||
{:ok, home_live, disconnected_html} = live(conn, "/")
|
||||
assert disconnected_html =~ gettext("Welcome to %{name}", name: "Cannery")
|
||||
assert render(home_live) =~ gettext("Welcome to %{name}", name: "Cannery")
|
||||
assert disconnected_html =~ "Welcome to Cannery"
|
||||
assert render(home_live) =~ "Welcome to Cannery"
|
||||
end
|
||||
|
||||
test "displays version number", %{conn: conn} do
|
||||
|
@ -5,13 +5,12 @@ defmodule CanneryWeb.InviteLiveTest do
|
||||
|
||||
use CanneryWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import CanneryWeb.Gettext
|
||||
alias Cannery.Accounts.Invites
|
||||
|
||||
@moduletag :invite_live_test
|
||||
@create_attrs %{"name" => "some name"}
|
||||
@update_attrs %{"name" => "some updated name"}
|
||||
# @invalid_attrs %{"name" => nil}
|
||||
@create_attrs %{name: "some name"}
|
||||
@update_attrs %{name: "some updated name"}
|
||||
@invalid_attrs %{name: nil}
|
||||
|
||||
describe "Index" do
|
||||
setup [:register_and_log_in_user]
|
||||
@ -24,32 +23,27 @@ defmodule CanneryWeb.InviteLiveTest do
|
||||
test "lists all invites", %{conn: conn, invite: invite} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~ gettext("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))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "Create Invite")) |> render_click() =~
|
||||
gettext("New Invite")
|
||||
|
||||
assert index_live |> element("a", "Create Invite") |> render_click() =~ "New Invite"
|
||||
assert_patch(index_live, Routes.invite_index_path(conn, :new))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#invite-form", invite: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#invite-form")
|
||||
|> render_change(invite: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#invite-form", invite: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#invite-form")
|
||||
|> render_submit(invite: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~
|
||||
dgettext("prompts", "%{invite_name} created successfully", invite_name: "some name")
|
||||
|
||||
assert html =~ "some name"
|
||||
assert html =~ "some name created successfully"
|
||||
end
|
||||
|
||||
test "updates invite in listing", %{conn: conn, invite: invite} do
|
||||
@ -57,27 +51,21 @@ defmodule CanneryWeb.InviteLiveTest do
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit invite for #{invite.name}"]/)
|
||||
|> render_click() =~
|
||||
gettext("Edit Invite")
|
||||
|> render_click() =~ "Edit Invite"
|
||||
|
||||
assert_patch(index_live, Routes.invite_index_path(conn, :edit, invite))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#invite-form", invite: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#invite-form")
|
||||
|> render_change(invite: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#invite-form", invite: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#invite-form")
|
||||
|> render_submit(invite: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~
|
||||
dgettext("prompts", "%{invite_name} updated successfully",
|
||||
invite_name: "some updated name"
|
||||
)
|
||||
|
||||
assert html =~ "some updated name"
|
||||
assert html =~ "some updated name updated successfully"
|
||||
end
|
||||
|
||||
test "deletes invite in listing", %{conn: conn, invite: invite} do
|
||||
|
@ -6,22 +6,20 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
use CanneryWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import Cannery.Fixtures
|
||||
import CanneryWeb.Gettext
|
||||
|
||||
@moduletag :range_live_test
|
||||
@create_attrs %{"ammo_left" => 5, "notes" => "some notes"}
|
||||
@update_attrs %{"count" => 16, "notes" => "some updated notes"}
|
||||
# @invalid_attrs %{"count" => nil, "notes" => nil}
|
||||
@create_attrs %{ammo_left: 5, notes: "some notes"}
|
||||
@update_attrs %{count: 16, notes: "some updated notes"}
|
||||
@invalid_attrs %{count: nil, notes: nil}
|
||||
|
||||
defp create_shot_group(%{current_user: current_user}) do
|
||||
container = container_fixture(%{"staged" => true}, current_user)
|
||||
container = container_fixture(%{staged: true}, current_user)
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
|
||||
{1, [ammo_group]} =
|
||||
ammo_group_fixture(%{"staged" => true}, ammo_type, container, current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(%{staged: true}, ammo_type, container, current_user)
|
||||
|
||||
shot_group =
|
||||
%{"count" => 5, "date" => ~N[2022-02-13 03:17:00], "notes" => "some notes"}
|
||||
%{count: 5, date: ~N[2022-02-13 03:17:00], notes: "some notes"}
|
||||
|> shot_group_fixture(current_user, ammo_group)
|
||||
|
||||
[
|
||||
@ -38,29 +36,28 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
test "lists all shot_groups", %{conn: conn, shot_group: shot_group} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ gettext("Range day")
|
||||
assert html =~ "Range day"
|
||||
assert html =~ shot_group.notes
|
||||
end
|
||||
|
||||
test "can sort by type",
|
||||
%{conn: conn, container: container, current_user: current_user} do
|
||||
rifle_ammo_type = ammo_type_fixture(%{"type" => "rifle"}, current_user)
|
||||
rifle_ammo_type = ammo_type_fixture(%{type: "rifle"}, current_user)
|
||||
{1, [rifle_ammo_group]} = ammo_group_fixture(rifle_ammo_type, container, current_user)
|
||||
|
||||
rifle_shot_group =
|
||||
shot_group_fixture(%{"notes" => "group_one"}, current_user, rifle_ammo_group)
|
||||
rifle_shot_group = shot_group_fixture(%{notes: "group_one"}, current_user, rifle_ammo_group)
|
||||
|
||||
shotgun_ammo_type = ammo_type_fixture(%{"type" => "shotgun"}, current_user)
|
||||
shotgun_ammo_type = ammo_type_fixture(%{type: "shotgun"}, current_user)
|
||||
{1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_ammo_type, container, current_user)
|
||||
|
||||
shotgun_shot_group =
|
||||
shot_group_fixture(%{"notes" => "group_two"}, current_user, shotgun_ammo_group)
|
||||
shot_group_fixture(%{notes: "group_two"}, current_user, shotgun_ammo_group)
|
||||
|
||||
pistol_ammo_type = ammo_type_fixture(%{"type" => "pistol"}, current_user)
|
||||
pistol_ammo_type = ammo_type_fixture(%{type: "pistol"}, current_user)
|
||||
{1, [pistol_ammo_group]} = ammo_group_fixture(pistol_ammo_type, container, current_user)
|
||||
|
||||
pistol_shot_group =
|
||||
shot_group_fixture(%{"notes" => "group_three"}, current_user, pistol_ammo_group)
|
||||
shot_group_fixture(%{notes: "group_three"}, current_user, pistol_ammo_group)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
@ -113,22 +110,20 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
assert html =~ shot_group.notes
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/,
|
||||
search: %{search_term: shot_group.notes}
|
||||
)
|
||||
|> render_change() =~ shot_group.notes
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: shot_group.notes}) =~ shot_group.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :search, shot_group.notes))
|
||||
|
||||
refute index_live
|
||||
|> form(~s/form[phx-change="search"]/, search: %{search_term: "something_else"})
|
||||
|> render_change() =~ shot_group.notes
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: "something_else"}) =~ shot_group.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :search, "something_else"))
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/, search: %{search_term: ""})
|
||||
|> render_change() =~ shot_group.notes
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ""}) =~ shot_group.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :index))
|
||||
end
|
||||
@ -136,22 +131,20 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "Record shots")) |> render_click() =~
|
||||
gettext("Record shots")
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :add_shot_group, ammo_group))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#shot_group-form", shot_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "is invalid")
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form", shot_group: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("prompts", "Shots recorded successfully")
|
||||
assert html =~ "Shots recorded successfully"
|
||||
assert html =~ "some notes"
|
||||
end
|
||||
|
||||
@ -160,14 +153,13 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit shot record of #{shot_group.count} shots"]/)
|
||||
|> render_click() =~
|
||||
gettext("Edit Shot Records")
|
||||
|> render_click() =~ "Edit Shot Records"
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :edit, shot_group))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#shot_group-form", shot_group: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "is invalid")
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
@ -175,7 +167,7 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("actions", "Shot records updated successfully")
|
||||
assert html =~ "Shot records updated successfully"
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
|
@ -5,26 +5,24 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
|
||||
use CanneryWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import CanneryWeb.Gettext
|
||||
|
||||
@moduletag :tag_live_test
|
||||
|
||||
@create_attrs %{
|
||||
"bg_color" => "#100000",
|
||||
"name" => "some name",
|
||||
"text_color" => "#000000"
|
||||
bg_color: "#100000",
|
||||
name: "some name",
|
||||
text_color: "#000000"
|
||||
}
|
||||
@update_attrs %{
|
||||
"bg_color" => "#100001",
|
||||
"name" => "some updated name",
|
||||
"text_color" => "#000001"
|
||||
bg_color: "#100001",
|
||||
name: "some updated name",
|
||||
text_color: "#000001"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
bg_color: nil,
|
||||
name: nil,
|
||||
text_color: nil
|
||||
}
|
||||
|
||||
# @invalid_attrs %{
|
||||
# "bg_color" => nil,
|
||||
# "name" => nil,
|
||||
# "text_color" => nil
|
||||
# }
|
||||
|
||||
def create_tag(%{current_user: current_user}) do
|
||||
tag = tag_fixture(current_user)
|
||||
@ -37,7 +35,7 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
test "lists all tags", %{conn: conn, tag: tag} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.tag_index_path(conn, :index))
|
||||
|
||||
assert html =~ gettext("Tags")
|
||||
assert html =~ "Tags"
|
||||
assert html =~ tag.bg_color
|
||||
end
|
||||
|
||||
@ -47,22 +45,20 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
assert html =~ tag.name
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/,
|
||||
search: %{search_term: tag.name}
|
||||
)
|
||||
|> render_change() =~ tag.name
|
||||
|> 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))
|
||||
|
||||
refute index_live
|
||||
|> form(~s/form[phx-change="search"]/, search: %{search_term: "something_else"})
|
||||
|> render_change() =~ tag.name
|
||||
|> 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 index_live
|
||||
|> form(~s/form[phx-change="search"]/, search: %{search_term: ""})
|
||||
|> render_change() =~ tag.name
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ""}) =~ tag.name
|
||||
|
||||
assert_patch(index_live, Routes.tag_index_path(conn, :index))
|
||||
end
|
||||
@ -70,22 +66,20 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
test "saves new tag", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "New Tag")) |> render_click() =~
|
||||
dgettext("actions", "New Tag")
|
||||
|
||||
assert index_live |> element("a", "New Tag") |> render_click() =~ "New Tag"
|
||||
assert_patch(index_live, Routes.tag_index_path(conn, :new))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#tag-form", tag: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#tag-form")
|
||||
|> render_change(tag: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#tag-form", tag: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#tag-form")
|
||||
|> render_submit(tag: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.tag_index_path(conn, :index))
|
||||
|
||||
assert html =~ dgettext("actions", "%{name} created successfully", name: "some name")
|
||||
assert html =~ "some name created successfully"
|
||||
assert html =~ "#100000"
|
||||
end
|
||||
|
||||
@ -93,23 +87,21 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
{:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element(~s/a[aria-label="Edit #{tag.name}"]/) |> render_click() =~
|
||||
dgettext("actions", "Edit Tag")
|
||||
"Edit Tag"
|
||||
|
||||
assert_patch(index_live, Routes.tag_index_path(conn, :edit, tag))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#tag-form", tag: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
assert index_live
|
||||
|> form("#tag-form")
|
||||
|> render_change(tag: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#tag-form", tag: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#tag-form")
|
||||
|> render_submit(tag: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.tag_index_path(conn, :index))
|
||||
|
||||
assert html =~
|
||||
dgettext("prompts", "%{name} updated successfully", name: "some updated name")
|
||||
|
||||
assert html =~ "some updated name updated successfully"
|
||||
assert html =~ "#100001"
|
||||
end
|
||||
|
||||
|
@ -4,19 +4,16 @@ defmodule CanneryWeb.ErrorViewTest do
|
||||
"""
|
||||
|
||||
use CanneryWeb.ConnCase, async: true
|
||||
import CanneryWeb.Gettext
|
||||
# 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", []) =~
|
||||
dgettext("errors", "Not found")
|
||||
assert render_to_string(CanneryWeb.ErrorView, "404.html", []) =~ "Not found"
|
||||
end
|
||||
|
||||
test "renders 500.html" do
|
||||
assert render_to_string(CanneryWeb.ErrorView, "500.html", []) =~
|
||||
dgettext("errors", "Internal Server Error")
|
||||
assert render_to_string(CanneryWeb.ErrorView, "500.html", []) =~ "Internal Server Error"
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user