mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
* remove daisyui and rebuild styles * very basic setup of new design - missing components etc * basic navbar with reusable landing components * basic puzzle of the day * update todos * update todos * add curated landing puzzle cards with selectable board (#55) * update with footer * add button to solve today's puzzle * Make landing page a dead view Render the home page from PageController with a static board preview, link puzzle cards and CTAs to public-code play routes, count puzzles from the DB, and add a global footer. * Serve a marketing-only JS bundle on the landing page Build a small marketing entry point with phoenix_html and the plain-DOM navbar, select it on controller-rendered pages, and keep the full LiveView bundle for LiveView pages. * Add landing page SEO metadata Replace the Phoenix default title with a descriptive Lucid Chess title, and add description, canonical, Open Graph, and Twitter card tags to the landing page. * Complete the hero copy block Add the spark icon primitive and the Endgames, made clear eyebrow. The primary CTA keeps linking to the active puzzle rather than scrolling to the board. * Add a persisted global daily puzzle Assign one endgame per UTC day in a daily_puzzles table with a unique date, preferring endgames unused in the last 30 days and falling back to any. Concurrent first requests insert with on-conflict-ignore and read the winning row. The landing board now shows the daily puzzle. * remove unused CSS, nav links, time pill * allow devices to connect to dev server by changing IP address to 0.0.0.0 * Restore the colour-mode switch and add a dark palette * Use brand colour tokens on the play page * self host fonts - closes issue #62 * begin splitting CSS into modules * remove hover on hero chessboard, split more css modules * remove interactivity from hero chessboard * update todo
138 lines
4.4 KiB
Elixir
138 lines
4.4 KiB
Elixir
defmodule ChesstrainerWeb.EndgameLive.IndexTest do
|
|
use ChesstrainerWeb.ConnCase
|
|
|
|
import Phoenix.LiveViewTest
|
|
import Chesstrainer.EndgamesFixtures
|
|
import Chesstrainer.ThemesFixtures
|
|
|
|
alias Chesstrainer.Endgames
|
|
|
|
setup :register_and_log_in_admin
|
|
|
|
test "groups endgames by Key with a count", %{conn: conn} do
|
|
endgame_fixture()
|
|
endgame_fixture()
|
|
|
|
{:ok, view, html} = live(conn, ~p"/admin/endgames")
|
|
|
|
assert html =~ "max-w-7xl"
|
|
assert has_element?(view, "#key-group-K-v-K")
|
|
assert has_element?(view, "#key-group-count-K-v-K", "2")
|
|
end
|
|
|
|
test "trims the table to the key columns", %{conn: conn} do
|
|
endgame_fixture()
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/admin/endgames")
|
|
view |> element("#key-group-K-v-K button") |> render_click()
|
|
|
|
for label <- ~w(Key Color Result Themes Rating) do
|
|
assert has_element?(view, "th", label)
|
|
end
|
|
|
|
for label <- ~w(Fen Message Notes Attempted Solved) do
|
|
refute has_element?(view, "th", label)
|
|
end
|
|
end
|
|
|
|
test "lazy-loads a group's endgames when expanded", %{conn: conn} do
|
|
theme = theme_fixture(%{name: "Lucena"})
|
|
endgame = endgame_fixture()
|
|
{:ok, _} = Endgames.update_endgame(endgame, %{}, [theme])
|
|
|
|
{:ok, view, html} = live(conn, ~p"/admin/endgames")
|
|
|
|
# collapsed: the endgame row (and its themes) are not rendered yet
|
|
refute html =~ ~p"/endgames/#{endgame.public_code}/play"
|
|
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 =~ "Lucena"
|
|
end
|
|
|
|
describe "search" do
|
|
test "opens the endgame found by public code", %{conn: conn} do
|
|
endgame = endgame_fixture()
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/admin/endgames")
|
|
|
|
assert {:error, {:live_redirect, %{to: path}}} =
|
|
view
|
|
|> form("#endgame-search-form", %{query: endgame.public_code})
|
|
|> render_submit()
|
|
|
|
assert path == "/admin/endgames/#{endgame.id}"
|
|
end
|
|
|
|
test "opens the endgame found by database id", %{conn: conn} do
|
|
endgame = endgame_fixture()
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/admin/endgames")
|
|
|
|
assert {:error, {:live_redirect, %{to: path}}} =
|
|
view |> form("#endgame-search-form", %{query: endgame.id}) |> render_submit()
|
|
|
|
assert path == "/admin/endgames/#{endgame.id}"
|
|
end
|
|
|
|
test "lists every endgame containing a FEN fragment", %{conn: conn} do
|
|
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, view, _html} = live(conn, ~p"/admin/endgames")
|
|
|
|
html = view |> form("#endgame-search-form", %{query: "3k4"}) |> render_submit()
|
|
|
|
assert html =~ ~s{/admin/endgames/#{kr.id}}
|
|
assert html =~ ~s{/admin/endgames/#{kq.id}}
|
|
end
|
|
|
|
test "reports when nothing matches, and clears back to the grouped list", %{conn: conn} do
|
|
endgame_fixture()
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/admin/endgames")
|
|
|
|
html = view |> form("#endgame-search-form", %{query: "no such endgame"}) |> render_submit()
|
|
assert html =~ "No endgame matches"
|
|
|
|
view |> element("#clear-endgame-search") |> render_click()
|
|
|
|
assert has_element?(view, "#key-group-K-v-K")
|
|
refute render(view) =~ "No endgame matches"
|
|
end
|
|
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"/admin/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 "filters by Key", %{conn: conn} do
|
|
endgame_fixture(fen: "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
|
|
endgame_fixture(fen: "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1")
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/admin/endgames")
|
|
|
|
view |> form("#key-filter-form", %{key: "KQ v K"}) |> render_change()
|
|
|
|
assert has_element?(view, "#key-group-KQ-v-K")
|
|
refute has_element?(view, "#key-group-KR-v-K")
|
|
end
|
|
end
|