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:
@@ -225,6 +225,63 @@ defmodule ChesstrainerWeb.EndgameLive.TrainTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "empty pools" do
|
||||
setup :register_and_log_in_user
|
||||
|
||||
test "shows an in-page state when a difficulty has no puzzles", %{conn: conn} do
|
||||
{:ok, view, _html} = live(conn, ~p"/train")
|
||||
|
||||
view |> element("#difficulty-medium") |> render_click()
|
||||
|
||||
assert has_element?(view, "#pool-empty")
|
||||
assert has_element?(view, "#retry-pool")
|
||||
assert has_element?(view, "#difficulty-picker")
|
||||
refute has_element?(view, "#session-bar")
|
||||
|
||||
endgame = endgame_fixture(rating: 1500)
|
||||
seed_tablebase(endgame.fen)
|
||||
|
||||
view |> element("#retry-pool") |> render_click()
|
||||
|
||||
assert has_element?(view, "#session-bar")
|
||||
refute has_element?(view, "#pool-empty")
|
||||
end
|
||||
|
||||
test "shows an in-page end-of-run state when the difficulty is exhausted", %{conn: conn} do
|
||||
{view, [_endgame]} = start_medium_session(conn, 1)
|
||||
solve_current(view)
|
||||
|
||||
view |> element("#next-puzzle-button") |> render_click()
|
||||
|
||||
assert has_element?(view, "#pool-exhausted")
|
||||
assert has_element?(view, "#retry-pool")
|
||||
assert has_element?(view, "#change-difficulty")
|
||||
refute has_element?(view, "#endgame-board")
|
||||
|
||||
view |> element("#change-difficulty") |> render_click()
|
||||
|
||||
assert has_element?(view, "#difficulty-picker")
|
||||
assert :sys.get_state(view.pid).socket.assigns.session == nil
|
||||
end
|
||||
|
||||
test "retry loads a puzzle once the pool grows", %{conn: conn} do
|
||||
{view, [_endgame]} = start_medium_session(conn, 1)
|
||||
solve_current(view)
|
||||
|
||||
view |> element("#next-puzzle-button") |> render_click()
|
||||
assert has_element?(view, "#pool-exhausted")
|
||||
|
||||
rating = :sys.get_state(view.pid).socket.assigns.user_rating
|
||||
new_endgame = endgame_fixture(fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1", rating: round(rating))
|
||||
seed_tablebase(new_endgame.fen)
|
||||
|
||||
view |> element("#retry-pool") |> render_click()
|
||||
|
||||
assert :sys.get_state(view.pid).socket.assigns.endgame.id == new_endgame.id
|
||||
refute has_element?(view, "#pool-exhausted")
|
||||
end
|
||||
end
|
||||
|
||||
defp elapsed_id(view) do
|
||||
:sys.get_state(view.pid).socket.assigns.session.started_at_ms
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user