-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to join user lobby from their profile page (#209)
* fix: make_lobby not creating lobby properly in tests * feat: add join button to user overview page This will tell the current user's client to the selected user's lobby. If the user is not in a lobby, or the current user's client is not connected, a flash message will be rendered with the error reason. * feat: do not render join button when user is not in a lobby * fix: respect server rules for joining * chore: formatter
- Loading branch information
1 parent
d3ba30b
commit 82eace8
Showing
5 changed files
with
168 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
defmodule TeiserverWeb.Live.Account.Profile.OverviewTest do | ||
use TeiserverWeb.ConnCase, async: false | ||
import Phoenix.LiveViewTest | ||
|
||
alias Central.Helpers.GeneralTestLib | ||
alias Teiserver.{Battle, TeiserverTestLib, Client} | ||
|
||
setup do | ||
{:ok, data} = | ||
TeiserverTestLib.player_permissions() | ||
|> GeneralTestLib.conn_setup() | ||
|> TeiserverTestLib.conn_setup() | ||
|
||
profile_user = GeneralTestLib.make_user() | ||
login_user(profile_user) | ||
|
||
%{conn: data[:conn], user: data[:user], profile_user: profile_user} | ||
end | ||
|
||
describe "join lobby" do | ||
test "clicking join joins the client to the user's lobby", %{ | ||
conn: conn, | ||
user: user, | ||
profile_user: profile_user | ||
} do | ||
login_user(user) | ||
|
||
lobby_id = TeiserverTestLib.make_lobby() | ||
|
||
Battle.force_add_user_to_lobby(profile_user.id, lobby_id) | ||
|
||
{:ok, view, _html} = live(conn, "/profile/#{profile_user.id}") | ||
|
||
view | ||
|> element("span[phx-click=join]") | ||
|> render_click() | ||
|
||
assert user.id in Battle.get_lobby_member_list(lobby_id) | ||
end | ||
|
||
test "only renders join button when user to join is in a lobby", %{ | ||
conn: conn, | ||
profile_user: profile_user | ||
} do | ||
lobby_id = TeiserverTestLib.make_lobby() | ||
|
||
{:ok, view, _html} = live(conn, "/profile/#{profile_user.id}") | ||
|
||
refute view | ||
|> element("span[phx-click=join]") | ||
|> has_element?() | ||
|
||
Battle.force_add_user_to_lobby(profile_user.id, lobby_id) | ||
|
||
assert view | ||
|> element("span[phx-click=join]") | ||
|> has_element?() | ||
end | ||
|
||
test "renders error flash when client is not connected", %{ | ||
conn: conn, | ||
profile_user: profile_user | ||
} do | ||
# Skip client login | ||
|
||
lobby_id = TeiserverTestLib.make_lobby() | ||
|
||
Battle.force_add_user_to_lobby(profile_user.id, lobby_id) | ||
|
||
{:ok, view, _html} = live(conn, "/profile/#{profile_user.id}") | ||
|
||
view | ||
|> element("span[phx-click=join]") | ||
|> render_click() | ||
|
||
assert render(view) =~ "Client is not connected" | ||
end | ||
end | ||
|
||
defp login_user(user) do | ||
user | ||
|> Map.merge(%{rank: 1, print_client_messages: false, print_server_messages: false}) | ||
|> Client.login(:spring, "127.0.0.1") | ||
end | ||
end |