mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Tablebase failures now render one message per class, with a Retry action when fetching again can help. The generic class no longer interpolates inspect(reason) into the page; the reason goes to the log instead. Positions outside the tablebase offer the next puzzle (in a session) or the existing back link, rather than a futile retry. Train's no-puzzles and exhausted-difficulty flashes become in-page states with Retry and Change difficulty. The guest pool gets the same treatment, and GuestLimits.remaining/1 lets a guest see the wall, or the empty pool, without spending a puzzle.
This commit is contained in:
@@ -80,11 +80,21 @@ defmodule ChesstrainerWeb.EndgameLive.GuestTrainTest do
|
||||
end
|
||||
|
||||
describe "without puzzles" do
|
||||
test "shows an empty state", %{conn: conn} do
|
||||
test "shows an empty state with a retry that does not spend a puzzle", %{conn: conn} do
|
||||
{:ok, view, _html} = live(conn, ~p"/guest-train")
|
||||
|
||||
assert render(view) =~ "No endgames are available yet"
|
||||
assert has_element?(view, "#guest-pool-empty")
|
||||
assert has_element?(view, "#retry-pool")
|
||||
refute has_element?(view, "#endgame-board")
|
||||
assert {:ok, 5} = GuestLimits.remaining(@guest_address)
|
||||
|
||||
endgame = endgame_fixture()
|
||||
seed_tablebase(endgame.fen, moves: grading_moves())
|
||||
|
||||
view |> element("#retry-pool") |> render_click()
|
||||
|
||||
assert has_element?(view, "#endgame-board")
|
||||
assert :sys.get_state(view.pid).socket.assigns.guest_remaining == 4
|
||||
end
|
||||
end
|
||||
|
||||
@@ -133,6 +143,31 @@ defmodule ChesstrainerWeb.EndgameLive.GuestTrainTest do
|
||||
|
||||
assert :sys.get_state(view.pid).socket.assigns.guest_remaining == 4
|
||||
end
|
||||
|
||||
test "shows an in-page state when no puzzles are left, and retry loads one", %{conn: conn} do
|
||||
endgame = endgame_fixture()
|
||||
seed_tablebase(endgame.fen, moves: grading_moves())
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/guest-train")
|
||||
solve_current(view)
|
||||
|
||||
Repo.delete!(endgame)
|
||||
|
||||
view |> element("#next-puzzle-button") |> render_click()
|
||||
|
||||
assert has_element?(view, "#guest-pool-exhausted")
|
||||
assert has_element?(view, "#retry-pool")
|
||||
refute has_element?(view, "#endgame-board")
|
||||
assert :sys.get_state(view.pid).socket.assigns.guest_remaining == 4
|
||||
|
||||
new_endgame = endgame_fixture()
|
||||
seed_tablebase(new_endgame.fen, moves: grading_moves())
|
||||
|
||||
view |> element("#retry-pool") |> render_click()
|
||||
|
||||
assert :sys.get_state(view.pid).socket.assigns.endgame.id == new_endgame.id
|
||||
assert :sys.get_state(view.pid).socket.assigns.guest_remaining == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "daily budget" do
|
||||
|
||||
Reference in New Issue
Block a user