mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Compare commits
No commits in common. "fac097168096b2417b1d03c5e6f12bbe88d05516" and "6634695a412ba3a0fbfd86410c3a891afa86da3a" have entirely different histories.
fac0971680
...
6634695a41
@ -8,16 +8,13 @@
|
|||||||
width: 1.5%;
|
width: 1.5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.board__container {
|
|
||||||
grid-area: board;
|
|
||||||
}
|
|
||||||
|
|
||||||
.board {
|
.board {
|
||||||
background: $background-color;
|
background: $background-color;
|
||||||
border-collapse: unset;
|
border-collapse: unset;
|
||||||
border-radius: 2.8%;
|
border-radius: 2.8%;
|
||||||
border-spacing: 1px;
|
border-spacing: 1px;
|
||||||
color: $foreground-color;
|
color: $foreground-color;
|
||||||
|
grid-area: board;
|
||||||
height: var(--board-size);
|
height: var(--board-size);
|
||||||
padding: calc(var(--board-size) / 20);
|
padding: calc(var(--board-size) / 20);
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
@ -15,9 +15,9 @@ defmodule ChessWeb.GameController do
|
|||||||
conn
|
conn
|
||||||
|> current_user()
|
|> current_user()
|
||||||
|> Game.for_user()
|
|> Game.for_user()
|
||||||
|> Game.ordered()
|
|> Game.ordered
|
||||||
|> preload([:user, :opponent])
|
|> preload([:user, :opponent])
|
||||||
|> Repo.all()
|
|> Repo.all
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> render("index.html", games: games, changeset: changeset)
|
|> render("index.html", games: games, changeset: changeset)
|
||||||
@ -42,7 +42,7 @@ defmodule ChessWeb.GameController do
|
|||||||
|> Repo.preload(:user)
|
|> Repo.preload(:user)
|
||||||
|> Repo.preload(:opponent)
|
|> Repo.preload(:opponent)
|
||||||
)
|
)
|
||||||
|> Mailer.deliver_later()
|
|> Mailer.deliver_later
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Game created successfully.")
|
|> put_flash(:info, "Game created successfully.")
|
||||||
@ -53,7 +53,7 @@ defmodule ChessWeb.GameController do
|
|||||||
conn
|
conn
|
||||||
|> current_user()
|
|> current_user()
|
||||||
|> User.opponents()
|
|> User.opponents()
|
||||||
|> Repo.all()
|
|> Repo.all
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> render("new.html", changeset: changeset, opponents: opponents)
|
|> render("new.html", changeset: changeset, opponents: opponents)
|
||||||
|
|||||||
@ -37,7 +37,5 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="game-state game-state--<%= @game.state %>">
|
<div class="game-state game-state--null"></div>
|
||||||
<%= states[@game.state] %>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<div class="form">
|
<div class="form">
|
||||||
<h2><%= gettext "Password" %></h2>
|
<h2><%= gettext "Password" %></h2>
|
||||||
|
|
||||||
<%= form_for @changeset, password_path(@conn, :update), [class: "update-password", novalidate: true], fn f -> %>
|
<%= form_for @changeset, password_path(@conn, :update), [class: "update-password"], fn f -> %>
|
||||||
<%= if @changeset.action do %>
|
<%= if @changeset.action do %>
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<div class="form">
|
<div class="form">
|
||||||
<h2><%= gettext "Profile" %></h2>
|
<h2><%= gettext "Profile" %></h2>
|
||||||
|
|
||||||
<%= form_for @changeset, profile_path(@conn, :update), [class: "update-profile", novalidate: true], fn f -> %>
|
<%= form_for @changeset, profile_path(@conn, :update), [class: "update-profile"], fn f -> %>
|
||||||
<%= if @changeset.action do %>
|
<%= if @changeset.action do %>
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@ -7,8 +7,8 @@ defmodule ChessWeb.GameView do
|
|||||||
|
|
||||||
def won_lost(conn, game) do
|
def won_lost(conn, game) do
|
||||||
if game_over?(game) && game.state == "checkmate" do
|
if game_over?(game) && game.state == "checkmate" do
|
||||||
(your_turn?(conn, game) &&
|
your_turn?(conn, game) &&
|
||||||
gettext("You lost")) ||
|
gettext("You lost") ||
|
||||||
gettext("You won")
|
gettext("You won")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -21,12 +21,9 @@ defmodule ChessWeb.GameView do
|
|||||||
cond do
|
cond do
|
||||||
GameState.game_over?(game) ->
|
GameState.game_over?(game) ->
|
||||||
states()[game.state]
|
states()[game.state]
|
||||||
|
|
||||||
your_turn?(conn, game) ->
|
your_turn?(conn, game) ->
|
||||||
gettext("Your turn")
|
gettext("Your turn")
|
||||||
|
true -> nil
|
||||||
true ->
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,18 +34,16 @@ defmodule ChessWeb.GameView do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def your_turn?(conn, game) do
|
def your_turn?(conn, game) do
|
||||||
conn
|
player_colour(conn, game) == game.turn
|
||||||
|> current_user()
|
|
||||||
|> player_colour(game) == game.turn
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def player_colour(user, game) do
|
def player_colour(user, game) do
|
||||||
(user.id == game.user_id && "white") || "black"
|
user.id == game.user_id && "white" || "black"
|
||||||
end
|
end
|
||||||
|
|
||||||
def files(conn, game) do
|
def files(conn, game) do
|
||||||
ranks(conn, game)
|
ranks(conn, game)
|
||||||
|> Enum.reverse()
|
|> Enum.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
def ranks(conn, game) do
|
def ranks(conn, game) do
|
||||||
@ -79,7 +74,7 @@ defmodule ChessWeb.GameView do
|
|||||||
%{
|
%{
|
||||||
"checkmate" => gettext("Checkmate!"),
|
"checkmate" => gettext("Checkmate!"),
|
||||||
"stalemate" => gettext("Stalemate"),
|
"stalemate" => gettext("Stalemate"),
|
||||||
"check" => gettext("Check")
|
"check" => gettext("Check"),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
defmodule ChessWeb.BoardLive do
|
defmodule ChessWeb.BoardLive do
|
||||||
use Phoenix.LiveView, container: {:div, class: "board__container"}
|
use Phoenix.LiveView
|
||||||
|
|
||||||
alias Chess.Store.User
|
alias Chess.Store.User
|
||||||
alias Chess.Store.Game
|
alias Chess.Store.Game
|
||||||
|
|||||||
@ -60,7 +60,7 @@ defmodule ChessWeb.GameControllerTest do
|
|||||||
|> login(user)
|
|> login(user)
|
||||||
|> get(game_path(conn, :show, game))
|
|> get(game_path(conn, :show, game))
|
||||||
|
|
||||||
assert html_response(conn, 200) =~ "<div data-game-id=\"#{game.id}\">"
|
assert html_response(conn, 200) =~ "<div id=\"game\" data-game-id=\"#{game.id}\">"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not show a game if the user is not a player", %{conn: conn} do
|
test "does not show a game if the user is not a player", %{conn: conn} do
|
||||||
@ -74,25 +74,25 @@ defmodule ChessWeb.GameControllerTest do
|
|||||||
conn
|
conn
|
||||||
|> login(other_user)
|
|> login(other_user)
|
||||||
|
|
||||||
assert_error_sent(404, fn ->
|
assert_error_sent 404, fn ->
|
||||||
get(conn, game_path(conn, :show, game.id))
|
get conn, game_path(conn, :show, game.id)
|
||||||
end)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders page not found when id is nonexistent", %{conn: conn} do
|
test "renders page not found when id is nonexistent", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
conn = login(conn, user)
|
conn = login(conn, user)
|
||||||
|
|
||||||
assert_error_sent(404, fn ->
|
assert_error_sent 404, fn ->
|
||||||
get(conn, game_path(conn, :show, -1))
|
get conn, game_path(conn, :show, -1)
|
||||||
end)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "deletes game", %{conn: conn} do
|
test "deletes game", %{conn: conn} do
|
||||||
game = Repo.insert!(%Game{})
|
game = Repo.insert! %Game{}
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
conn = login(conn, user)
|
conn = login(conn, user)
|
||||||
conn = delete(conn, game_path(conn, :delete, game))
|
conn = delete conn, game_path(conn, :delete, game)
|
||||||
assert redirected_to(conn) == game_path(conn, :index)
|
assert redirected_to(conn) == game_path(conn, :index)
|
||||||
refute Repo.get(Game, game.id)
|
refute Repo.get(Game, game.id)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,12 +7,11 @@ defmodule Chess.Features.ProfileTest do
|
|||||||
import Chess.AuthenticationHelpers
|
import Chess.AuthenticationHelpers
|
||||||
|
|
||||||
test "user can update their details", %{session: session} do
|
test "user can update their details", %{session: session} do
|
||||||
user =
|
user = insert(:user, %{
|
||||||
insert(:user, %{
|
name: "Link",
|
||||||
name: "Link",
|
email: "link@hyrule.com",
|
||||||
email: "link@hyrule.com",
|
password: "ilovezelda"
|
||||||
password: "ilovezelda"
|
})
|
||||||
})
|
|
||||||
|
|
||||||
session
|
session
|
||||||
|> login(user.email, "ilovezelda")
|
|> login(user.email, "ilovezelda")
|
||||||
@ -26,12 +25,11 @@ defmodule Chess.Features.ProfileTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "name cannot be blank", %{session: session} do
|
test "name cannot be blank", %{session: session} do
|
||||||
user =
|
user = insert(:user, %{
|
||||||
insert(:user, %{
|
name: "Link",
|
||||||
name: "Link",
|
email: "link@hyrule.com",
|
||||||
email: "link@hyrule.com",
|
password: "ilovezelda"
|
||||||
password: "ilovezelda"
|
})
|
||||||
})
|
|
||||||
|
|
||||||
session
|
session
|
||||||
|> login(user.email, "ilovezelda")
|
|> login(user.email, "ilovezelda")
|
||||||
@ -42,16 +40,17 @@ defmodule Chess.Features.ProfileTest do
|
|||||||
|> click(button("Update Profile"))
|
|> click(button("Update Profile"))
|
||||||
|
|
||||||
session
|
session
|
||||||
|> assert_has(css("[data-role='name-error']", text: "can't be blank"))
|
|> assert_has(
|
||||||
|
css("[data-role='name-error']", text: "can't be blank")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "email cannot be blank", %{session: session} do
|
test "email cannot be blank", %{session: session} do
|
||||||
user =
|
user = insert(:user, %{
|
||||||
insert(:user, %{
|
name: "Link",
|
||||||
name: "Link",
|
email: "link@hyrule.com",
|
||||||
email: "link@hyrule.com",
|
password: "ilovezelda"
|
||||||
password: "ilovezelda"
|
})
|
||||||
})
|
|
||||||
|
|
||||||
session
|
session
|
||||||
|> login(user.email, "ilovezelda")
|
|> login(user.email, "ilovezelda")
|
||||||
@ -62,6 +61,8 @@ defmodule Chess.Features.ProfileTest do
|
|||||||
|> click(button("Update Profile"))
|
|> click(button("Update Profile"))
|
||||||
|
|
||||||
session
|
session
|
||||||
|> assert_has(css("[data-role='email-error']", text: "can't be blank"))
|
|> assert_has(
|
||||||
|
css("[data-role='email-error']", text: "can't be blank")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user