mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
back home button on daily puzzle
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
defmodule ChesstrainerWeb.EndgameLive.Play do
|
defmodule ChesstrainerWeb.EndgameLive.Play do
|
||||||
use ChesstrainerWeb, :live_view
|
use ChesstrainerWeb, :live_view
|
||||||
|
|
||||||
|
alias Chesstrainer.Accounts.Scope
|
||||||
alias Chesstrainer.Endgames
|
alias Chesstrainer.Endgames
|
||||||
alias ChesstrainerWeb.EndgameLive.PlayCore
|
alias ChesstrainerWeb.EndgameLive.PlayCore
|
||||||
alias ChesstrainerWeb.PlayComponents
|
alias ChesstrainerWeb.PlayComponents
|
||||||
@@ -32,9 +33,12 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
|||||||
</p>
|
</p>
|
||||||
</:subtitle>
|
</:subtitle>
|
||||||
<:actions>
|
<:actions>
|
||||||
<.button navigate={~p"/endgames"}>
|
<.button :if={Scope.premium?(@current_scope)} navigate={~p"/endgames"}>
|
||||||
<.icon name="hero-arrow-left" /> Back to endgames
|
<.icon name="hero-arrow-left" /> Back to endgames
|
||||||
</.button>
|
</.button>
|
||||||
|
<.button :if={!Scope.premium?(@current_scope)} navigate={~p"/"}>
|
||||||
|
<.icon name="hero-arrow-left" /> Back home
|
||||||
|
</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
|||||||
@@ -211,6 +211,50 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "back link" do
|
||||||
|
test "points home for an anonymous visitor", %{conn: conn} do
|
||||||
|
endgame = endgame_fixture()
|
||||||
|
seed_tablebase(endgame.fen)
|
||||||
|
|
||||||
|
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play")
|
||||||
|
|
||||||
|
assert has_element?(view, ~s{a[href="/"]}, "Back home")
|
||||||
|
refute has_element?(view, ~s{a[href="/endgames"]})
|
||||||
|
end
|
||||||
|
|
||||||
|
test "points home for a signed-in free user", %{conn: conn} do
|
||||||
|
user = Chesstrainer.AccountsFixtures.user_fixture()
|
||||||
|
endgame = endgame_fixture()
|
||||||
|
seed_tablebase(endgame.fen)
|
||||||
|
|
||||||
|
{:ok, view, _html} =
|
||||||
|
conn
|
||||||
|
|> log_in_user(user)
|
||||||
|
|> live(~p"/endgames/#{endgame.public_code}/play")
|
||||||
|
|
||||||
|
assert has_element?(view, ~s{a[href="/"]}, "Back home")
|
||||||
|
refute has_element?(view, ~s{a[href="/endgames"]})
|
||||||
|
end
|
||||||
|
|
||||||
|
test "points to the endgame index for a premium user", %{conn: conn} do
|
||||||
|
{:ok, user} =
|
||||||
|
Chesstrainer.AccountsFixtures.user_fixture()
|
||||||
|
|> Ecto.Changeset.change(plan: :premium)
|
||||||
|
|> Repo.update()
|
||||||
|
|
||||||
|
endgame = endgame_fixture()
|
||||||
|
seed_tablebase(endgame.fen)
|
||||||
|
|
||||||
|
{:ok, view, _html} =
|
||||||
|
conn
|
||||||
|
|> log_in_user(user)
|
||||||
|
|> live(~p"/endgames/#{endgame.public_code}/play")
|
||||||
|
|
||||||
|
assert has_element?(view, ~s{a[href="/endgames"]}, "Back to endgames")
|
||||||
|
refute has_element?(view, ~s{a[href="/"]}, "Back home")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "tablebase availability" do
|
describe "tablebase availability" do
|
||||||
test "blocks the attempt when the tablebase is cooling down", %{conn: conn} do
|
test "blocks the attempt when the tablebase is cooling down", %{conn: conn} do
|
||||||
# Six pieces routes to Lichess, so the cooldown applies (five or fewer
|
# Six pieces routes to Lichess, so the cooldown applies (five or fewer
|
||||||
|
|||||||
@@ -67,6 +67,6 @@ defmodule ChesstrainerWeb.EndgameLive.PlayerIndexTest do
|
|||||||
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play")
|
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play")
|
||||||
|
|
||||||
assert has_element?(view, "#endgame-board")
|
assert has_element?(view, "#endgame-board")
|
||||||
assert has_element?(view, ~s{a[href="/endgames"]})
|
assert has_element?(view, ~s{a[href="/"]})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user