87 lines
2.5 KiB
Elixir
87 lines
2.5 KiB
Elixir
defmodule ComfycampWeb.UserLoginLiveTest do
|
|
use ComfycampWeb.ConnCase, async: true
|
|
|
|
import Phoenix.LiveViewTest
|
|
import Comfycamp.AccountsFixtures
|
|
|
|
describe "Log in page" do
|
|
test "renders log in page", %{conn: conn} do
|
|
{:ok, _lv, html} = live(conn, ~p"/users/log_in")
|
|
|
|
assert html =~ "Войти"
|
|
assert html =~ "Зарегистрироваться"
|
|
assert html =~ "Забыли пароль?"
|
|
end
|
|
|
|
test "redirects if already logged in", %{conn: conn} do
|
|
result =
|
|
conn
|
|
|> log_in_user(user_fixture())
|
|
|> live(~p"/users/log_in")
|
|
|> follow_redirect(conn, "/")
|
|
|
|
assert {:ok, _conn} = result
|
|
end
|
|
end
|
|
|
|
describe "user login" do
|
|
test "redirects if user login with valid credentials", %{conn: conn} do
|
|
password = "123456789abcd"
|
|
user = user_fixture(%{password: password})
|
|
|
|
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
|
|
|
|
form =
|
|
form(lv, "#login_form", user: %{email: user.email, password: password, remember_me: true})
|
|
|
|
conn = submit_form(form, conn)
|
|
|
|
assert redirected_to(conn) == ~p"/"
|
|
end
|
|
|
|
test "redirects to login page with a flash error if there are no valid credentials", %{
|
|
conn: conn
|
|
} do
|
|
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
|
|
|
|
form =
|
|
form(lv, "#login_form",
|
|
user: %{email: "test@email.com", password: "123456", remember_me: true}
|
|
)
|
|
|
|
conn = submit_form(form, conn)
|
|
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) == "Invalid email or password"
|
|
|
|
assert redirected_to(conn) == "/users/log_in"
|
|
end
|
|
end
|
|
|
|
describe "login navigation" do
|
|
test "redirects to registration page when the Register button is clicked", %{conn: conn} do
|
|
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
|
|
|
|
{:ok, _login_live, login_html} =
|
|
lv
|
|
|> element(~s|main a:fl-contains("Создайте")|)
|
|
|> render_click()
|
|
|> follow_redirect(conn, ~p"/users/register")
|
|
|
|
assert login_html =~ "Зарегистрироваться"
|
|
end
|
|
|
|
test "redirects to forgot password page when the Forgot Password button is clicked", %{
|
|
conn: conn
|
|
} do
|
|
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
|
|
|
|
{:ok, conn} =
|
|
lv
|
|
|> element(~s|main a:fl-contains("Забыли пароль?")|)
|
|
|> render_click()
|
|
|> follow_redirect(conn, ~p"/users/reset_password")
|
|
|
|
assert conn.resp_body =~ "Забыли пароль?"
|
|
end
|
|
end
|
|
end
|