|
1 | 1 | defmodule AresWeb.UserLive.RegistrationTest do |
2 | 2 | use AresWeb.ConnCase, async: true |
3 | 3 |
|
4 | | - # import Phoenix.LiveViewTest |
5 | | - # import Ares.AccountsFixtures |
6 | | - |
7 | | - # describe "Registration page" do |
8 | | - # test "renders registration page", %{conn: conn} do |
9 | | - # {:ok, _lv, html} = live(conn, ~p"/register") |
10 | | - |
11 | | - # assert html =~ "Registration" |
12 | | - # assert html =~ "Log in" |
13 | | - # end |
14 | | - |
15 | | - # test "redirects if already logged in", %{conn: conn} do |
16 | | - # result = |
17 | | - # conn |
18 | | - # |> log_in_user(user_fixture()) |
19 | | - # |> live(~p"/register") |
20 | | - # |> follow_redirect(conn, ~p"/") |
21 | | - |
22 | | - # assert {:ok, _conn} = result |
23 | | - # end |
24 | | - |
25 | | - # test "renders errors for invalid data", %{conn: conn} do |
26 | | - # {:ok, lv, _html} = live(conn, ~p"/register") |
27 | | - |
28 | | - # result = |
29 | | - # lv |
30 | | - # |> element("#registration_form") |
31 | | - # |> render_change(user: %{"email" => "with spaces"}) |
32 | | - |
33 | | - # assert result =~ "Registration" |
34 | | - # assert result =~ "must have the @ sign and no spaces" |
35 | | - # end |
36 | | - # end |
37 | | - |
38 | | - # describe "register user" do |
39 | | - # test "creates account but does not log in", %{conn: conn} do |
40 | | - # {:ok, lv, _html} = live(conn, ~p"/register") |
41 | | - |
42 | | - # email = unique_user_email() |
43 | | - # form = form(lv, "#registration_form", user: valid_user_attributes(email: email)) |
44 | | - |
45 | | - # fi = |
46 | | - # file_input(lv, "#registration_form", :cv, [ |
47 | | - # %{name: "cv.pdf", content: "dummy", type: "application/pdf"} |
48 | | - # ]) |
49 | | - |
50 | | - # render_upload(fi, "cv.pdf") |
51 | | - |
52 | | - # {:ok, _lv, html} = |
53 | | - # render_submit(form) |
54 | | - # |> follow_redirect(conn, ~p"/log-in") |
55 | | - |
56 | | - # assert html =~ |
57 | | - # ~r/An email was sent to .*, please access it to confirm your account/ |
58 | | - # end |
59 | | - |
60 | | - # test "renders errors for duplicated email", %{conn: conn} do |
61 | | - # {:ok, lv, _html} = live(conn, ~p"/register") |
62 | | - |
63 | | - # user = user_fixture(%{email: "[email protected]"}) |
64 | | - |
65 | | - # result = |
66 | | - # lv |
67 | | - # |> form("#registration_form", |
68 | | - # user: %{"email" => user.email} |
69 | | - # ) |
70 | | - # |> then(fn form -> |
71 | | - # fi = |
72 | | - # file_input(lv, "#registration_form", :cv, [ |
73 | | - # %{name: "cv.pdf", content: "dummy", type: "application/pdf"} |
74 | | - # ]) |
75 | | - |
76 | | - # render_upload(fi, "cv.pdf") |
77 | | - # form |
78 | | - # end) |
79 | | - # |> render_submit() |
80 | | - |
81 | | - # assert result =~ "has already been taken" |
82 | | - # end |
83 | | - # end |
84 | | - |
85 | | - # describe "registration navigation" do |
86 | | - # test "redirects to login page when the Log in button is clicked", %{conn: conn} do |
87 | | - # {:ok, lv, _html} = live(conn, ~p"/register") |
88 | | - |
89 | | - # {:ok, _login_live, login_html} = |
90 | | - # lv |
91 | | - # |> element("main a", "Log in") |
92 | | - # |> render_click() |
93 | | - # |> follow_redirect(conn, ~p"/log-in") |
94 | | - |
95 | | - # assert login_html =~ "Log in" |
96 | | - # end |
97 | | - # end |
| 4 | + import Phoenix.LiveViewTest |
| 5 | + import Ares.AccountsFixtures |
| 6 | + |
| 7 | + describe "Registration page" do |
| 8 | + test "renders registration page", %{conn: conn} do |
| 9 | + {:ok, _lv, html} = live(conn, ~p"/register") |
| 10 | + |
| 11 | + assert html =~ "Registration" |
| 12 | + assert html =~ "Log in" |
| 13 | + end |
| 14 | + |
| 15 | + test "redirects if already logged in", %{conn: conn} do |
| 16 | + result = |
| 17 | + conn |
| 18 | + |> log_in_user(user_fixture()) |
| 19 | + |> live(~p"/register") |
| 20 | + |> follow_redirect(conn, ~p"/") |
| 21 | + |
| 22 | + assert {:ok, _conn} = result |
| 23 | + end |
| 24 | + |
| 25 | + test "renders errors for invalid data", %{conn: conn} do |
| 26 | + {:ok, lv, _html} = live(conn, ~p"/register") |
| 27 | + |
| 28 | + result = |
| 29 | + lv |
| 30 | + |> element("#registration_form") |
| 31 | + |> render_change(user: %{"email" => "with spaces"}) |
| 32 | + |
| 33 | + assert result =~ "Registration" |
| 34 | + assert result =~ "must have the @ sign and no spaces" |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + describe "register user" do |
| 39 | + test "creates account but does not log in", %{conn: conn} do |
| 40 | + {:ok, lv, _html} = live(conn, ~p"/register") |
| 41 | + |
| 42 | + email = unique_user_email() |
| 43 | + form = form(lv, "#registration_form", user: valid_user_attributes(email: email)) |
| 44 | + |
| 45 | + fi = |
| 46 | + file_input(lv, "#registration_form", :cv, [ |
| 47 | + %{name: "cv.pdf", content: "dummy", type: "application/pdf"} |
| 48 | + ]) |
| 49 | + |
| 50 | + render_upload(fi, "cv.pdf") |
| 51 | + |
| 52 | + {:ok, _lv, html} = |
| 53 | + render_submit(form) |
| 54 | + |> follow_redirect(conn, ~p"/log-in") |
| 55 | + |
| 56 | + assert html =~ |
| 57 | + ~r/An email was sent to .*, please access it to confirm your account/ |
| 58 | + end |
| 59 | + |
| 60 | + test "renders errors for duplicated email", %{conn: conn} do |
| 61 | + {:ok, lv, _html} = live(conn, ~p"/register") |
| 62 | + |
| 63 | + user = user_fixture(%{email: "[email protected]"}) |
| 64 | + |
| 65 | + result = |
| 66 | + lv |
| 67 | + |> form("#registration_form", |
| 68 | + user: %{"email" => user.email} |
| 69 | + ) |
| 70 | + |> then(fn form -> |
| 71 | + fi = |
| 72 | + file_input(lv, "#registration_form", :cv, [ |
| 73 | + %{name: "cv.pdf", content: "dummy", type: "application/pdf"} |
| 74 | + ]) |
| 75 | + |
| 76 | + render_upload(fi, "cv.pdf") |
| 77 | + form |
| 78 | + end) |
| 79 | + |> render_submit() |
| 80 | + |
| 81 | + assert result =~ "has already been taken" |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | + describe "registration navigation" do |
| 86 | + test "redirects to login page when the Log in button is clicked", %{conn: conn} do |
| 87 | + {:ok, lv, _html} = live(conn, ~p"/register") |
| 88 | + |
| 89 | + {:ok, _login_live, login_html} = |
| 90 | + lv |
| 91 | + |> element("main a", "Log in") |
| 92 | + |> render_click() |
| 93 | + |> follow_redirect(conn, ~p"/log-in") |
| 94 | + |
| 95 | + assert login_html =~ "Log in" |
| 96 | + end |
| 97 | + end |
98 | 98 | end |
0 commit comments