-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX]: Users demo #44
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3acd24f
Fix User Show with handle_params/3
snewcomer f8a4b8f
Merge branch 'master' into sn/fix-user-show
snewcomer ea593b7
fix edit and new
snewcomer 182ff21
cleanup to edit and new
snewcomer c596688
fix user presence
snewcomer d623957
dont fail user delete
snewcomer 040cd45
Basic test working
snewcomer 68891af
add more tests
snewcomer 80cfb06
add arrow left assertion
snewcomer 46f4dc7
Add edit test
snewcomer 6eb6bb6
add subscribe to non presence user
snewcomer 75825d2
change list name
snewcomer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule DemoWeb.UserEditTest do | ||
use DemoWeb.ConnCase | ||
import Phoenix.LiveViewTest | ||
# alias Phoenix.LiveViewTest.DOM | ||
|
||
alias Demo.Accounts | ||
|
||
def user_fixture(attrs \\ %{}) do | ||
valid_attrs = %{ | ||
username: "user#{:rand.uniform(1000)}", | ||
email: "user-#{:rand.uniform(10000)}@test.com", | ||
phone_number: "555-555-5555" | ||
} | ||
|
||
{:ok, user} = | ||
attrs | ||
|> Enum.into(valid_attrs) | ||
|> Accounts.create_user() | ||
|
||
user | ||
end | ||
|
||
describe "user edit" do | ||
test "disconnected and connected mount", %{conn: conn} do | ||
user = user_fixture() | ||
conn = get(conn, "/users/#{user.id}/edit") | ||
|
||
assert html_response(conn, 200) =~ "Edit" | ||
|
||
{:ok, _view, _html} = live(conn) | ||
end | ||
|
||
test "can edit a user", %{conn: conn} do | ||
user = user_fixture() | ||
{:ok, view, html} = live(conn, "/users/#{user.id}/edit") | ||
assert html =~ user.email | ||
|
||
{:error, {:redirect, %{to: path}}} = render_submit(view, :save, %{"user" => %{"email" => "[email protected]"}}) | ||
|
||
assert path == "/users/#{user.id}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
defmodule DemoWeb.UserIndexTest do | ||
use DemoWeb.ConnCase | ||
import Phoenix.LiveViewTest | ||
alias Phoenix.LiveViewTest.DOM | ||
|
||
alias Demo.Accounts | ||
|
||
def user_fixture(attrs \\ %{}) do | ||
valid_attrs = %{ | ||
username: "user#{:rand.uniform(1000)}", | ||
email: "user-#{:rand.uniform(10000)}@test.com", | ||
phone_number: "555-555-5555" | ||
} | ||
|
||
{:ok, user} = | ||
attrs | ||
|> Enum.into(valid_attrs) | ||
|> Accounts.create_user() | ||
|
||
user | ||
end | ||
|
||
describe "user index" do | ||
test "disconnected and connected mount", %{conn: conn} do | ||
user = user_fixture() | ||
conn = get(conn, "/users") | ||
assert html_response(conn, 200) =~ "Listing Users" | ||
assert html_response(conn, 200) =~ "New User" | ||
assert html_response(conn, 200) =~ user.username | ||
|
||
{:ok, _view, _html} = live(conn) | ||
end | ||
end | ||
|
||
describe "user actions" do | ||
test "can click to next page", %{conn: conn} do | ||
for _i <- 1..20 do | ||
user_fixture() | ||
end | ||
{:ok, view, html} = live(conn, "/users") | ||
|
||
refute html =~ "page 2" | ||
html = render_keydown(view, :keydown, %{"code" => "ArrowRight"}) | ||
assert html =~ "page 2" | ||
|
||
refute html =~ "page 1" | ||
html = render_keydown(view, :keydown, %{"code" => "ArrowLeft"}) | ||
assert html =~ "page 1" | ||
end | ||
|
||
test "can delete a user", %{conn: conn} do | ||
user = user_fixture() | ||
{:ok, view, html} = live(conn, "/users") | ||
|
||
assert [ | ||
{"tr", [{"id", _}], | ||
[ | ||
{"td", [], [_user_id]}, | ||
{"td", [], [_user_email]}, | ||
{"td", [], [_ph_number]}, | ||
{"td", [], _} | ||
] | ||
} | ||
] = DOM.all(html, "##{user.id}") | ||
|
||
html = render_click(view, "delete_user", %{"user-id" => user.id}) | ||
|
||
assert [] = DOM.all(html, "##{user.id}") | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you thank you! Updated and nice job 👍