mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
* add anonymous guest training with a daily puzzle limit - /guest-train serves random endgames with no difficulty picker; signed-in visitors are redirected to /train - guests get 5 puzzles per UTC day, keyed by an in-memory HMAC of the client address; the raw address is never stored or logged - a sign-up wall replaces the next puzzle once the budget is spent - move the endgame library behind auth so guests cannot browse it - privacy disclosure tracked in #87 * remove chess-test endpoint and liveview
73 lines
2.3 KiB
Elixir
73 lines
2.3 KiB
Elixir
defmodule ChesstrainerWeb.EndgameLive.PlayerIndexTest do
|
|
use ChesstrainerWeb.ConnCase
|
|
|
|
import Phoenix.LiveViewTest
|
|
import Chesstrainer.EndgamesFixtures
|
|
import Chesstrainer.ThemesFixtures
|
|
|
|
alias Chesstrainer.Endgames
|
|
|
|
setup :register_and_log_in_user
|
|
|
|
test "groups endgames by Key and shows themes on expand", %{conn: conn} do
|
|
theme = theme_fixture(%{name: "Lucena"})
|
|
endgame = endgame_fixture()
|
|
other = endgame_fixture()
|
|
{:ok, _} = Endgames.update_endgame(endgame, %{}, [theme])
|
|
|
|
{:ok, view, html} = live(conn, ~p"/endgames")
|
|
|
|
assert html =~ "Endgames"
|
|
assert html =~ "max-w-7xl"
|
|
assert html =~ "/assets/js/app.js"
|
|
refute html =~ "/assets/js/marketing.js"
|
|
assert has_element?(view, "#key-group-K-v-K")
|
|
refute html =~ "Lucena"
|
|
|
|
view |> element("#key-group-K-v-K button") |> render_click()
|
|
|
|
html = render(view)
|
|
assert html =~ ~p"/endgames/#{endgame.public_code}/play"
|
|
assert html =~ ~p"/endgames/#{other.public_code}/play"
|
|
assert html =~ "Lucena"
|
|
end
|
|
|
|
test "links to the public code, never the database id", %{conn: conn} do
|
|
endgame = endgame_fixture()
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/endgames")
|
|
view |> element("#key-group-K-v-K button") |> render_click()
|
|
|
|
html = render(view)
|
|
assert html =~ ~s{/endgames/#{endgame.public_code}/play}
|
|
refute html =~ endgame.id
|
|
end
|
|
|
|
test "filters by theme", %{conn: conn} do
|
|
lucena = theme_fixture(%{name: "Lucena"})
|
|
philidor = theme_fixture(%{name: "Philidor"})
|
|
|
|
kr = endgame_fixture(fen: "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
|
|
kq = endgame_fixture(fen: "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1")
|
|
{:ok, _} = Endgames.update_endgame(kr, %{}, [lucena])
|
|
{:ok, _} = Endgames.update_endgame(kq, %{}, [philidor])
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/endgames")
|
|
|
|
view |> form("#theme-filter-form", %{theme_search: "Luc"}) |> render_change()
|
|
view |> element("button", "Lucena") |> render_click()
|
|
|
|
assert has_element?(view, "#key-group-KR-v-K")
|
|
refute has_element?(view, "#key-group-KQ-v-K")
|
|
end
|
|
|
|
test "navigating to a play page renders the board", %{conn: conn} do
|
|
endgame = endgame_fixture()
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play")
|
|
|
|
assert has_element?(view, "#endgame-board")
|
|
assert has_element?(view, ~s{a[href="/endgames"]})
|
|
end
|
|
end
|