mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +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
149 lines
4.9 KiB
Elixir
149 lines
4.9 KiB
Elixir
defmodule Chesstrainer.FENTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias Chesstrainer.FEN
|
|
|
|
describe "color_from_fen/1" do
|
|
test "extracts white from the active-color field" do
|
|
assert FEN.color_from_fen("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1") == :white
|
|
end
|
|
|
|
test "extracts black from the active-color field" do
|
|
assert FEN.color_from_fen("6k1/5p2/6p1/8/7p/8/6PP/6K1 b - - 0 1") == :black
|
|
end
|
|
|
|
test "returns nil when the active-color field is missing" do
|
|
assert FEN.color_from_fen("8/8/8/8/8/8/8/8") == nil
|
|
end
|
|
end
|
|
|
|
describe "normalize/1" do
|
|
test "trims surrounding whitespace" do
|
|
fen = "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
|
assert FEN.normalize(" \n" <> fen <> "\t\n") == fen
|
|
end
|
|
|
|
test "rewrites fullmove 0 to 1" do
|
|
fen = "6k1/5p2/6p1/8/7p/8/6PP/6K1 b - - 0 0"
|
|
assert FEN.normalize(fen) == "6k1/5p2/6p1/8/7p/8/6PP/6K1 b - - 0 1"
|
|
end
|
|
|
|
test "rewrites fullmove 0 even when the FEN has surrounding whitespace" do
|
|
fen = "\n 6k1/5p2/6p1/8/7p/8/6PP/6K1 b - - 0 0 \t"
|
|
assert FEN.normalize(fen) == "6k1/5p2/6p1/8/7p/8/6PP/6K1 b - - 0 1"
|
|
end
|
|
|
|
test "leaves a non-zero fullmove untouched" do
|
|
fen = "8/8/3k4/8/8/3K1R2/8/8 w - - 0 5"
|
|
assert FEN.normalize(fen) == fen
|
|
end
|
|
|
|
test "leaves a standard starting position untouched" do
|
|
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
|
assert FEN.normalize(fen) == fen
|
|
end
|
|
|
|
test "passes through a non-FEN string unchanged" do
|
|
assert FEN.normalize("not a fen") == "not a fen"
|
|
end
|
|
|
|
test "passes through a partial FEN (fewer than 6 fields) unchanged" do
|
|
fen = "8/8/3k4/8/8/3K1R2/8/8 w - -"
|
|
assert FEN.normalize(fen) == fen
|
|
end
|
|
|
|
test "passes through a FEN with a leading-zero fullmove unchanged" do
|
|
# Fullmove 0 only matches the literal "0"; leading zeros stay so the
|
|
# validator can surface them rather than silently masking the typo.
|
|
fen = "8/8/3k4/8/8/3K1R2/8/8 w - - 0 00"
|
|
assert FEN.normalize(fen) == fen
|
|
end
|
|
end
|
|
|
|
describe "position_key/1" do
|
|
test "drops the halfmove and fullmove clocks" do
|
|
assert FEN.position_key("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1") ==
|
|
"8/8/3k4/8/8/3K1R2/8/8 w - -"
|
|
end
|
|
|
|
test "shares a key for FENs that differ only in the clocks" do
|
|
a = "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
|
b = "8/8/3k4/8/8/3K1R2/8/8 w - - 37 99"
|
|
|
|
assert FEN.position_key(a) == FEN.position_key(b)
|
|
end
|
|
|
|
test "keeps board, side to move, castling and en-passant distinct" do
|
|
base = "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
|
|
|
refute FEN.position_key(base) == FEN.position_key("8/8/3k4/8/8/3K1R2/8/8 b - - 0 1")
|
|
refute FEN.position_key(base) == FEN.position_key("8/8/3k4/8/8/3K1R3/8/8 w - - 0 1")
|
|
refute FEN.position_key(base) == FEN.position_key("8/8/3k4/8/8/3K1R2/8/8 w K - 0 1")
|
|
refute FEN.position_key(base) == FEN.position_key("8/8/3k4/8/8/3K1R2/8/8 w - e3 0 1")
|
|
end
|
|
|
|
test "trims surrounding whitespace" do
|
|
assert FEN.position_key(" 8/8/3k4/8/8/3K1R2/8/8 w - - 0 1\n") ==
|
|
"8/8/3k4/8/8/3K1R2/8/8 w - -"
|
|
end
|
|
|
|
test "passes through a non-FEN string" do
|
|
assert FEN.position_key("not a fen") == "not a fen"
|
|
end
|
|
end
|
|
|
|
describe "piece_count/1" do
|
|
test "counts kings and pieces, ignoring empty squares and slashes" do
|
|
assert FEN.piece_count("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1") == 3
|
|
end
|
|
|
|
test "counts a full seven-piece position" do
|
|
assert FEN.piece_count("6k1/5p2/6p1/8/7p/8/6PP/6K1 b - - 0 0") == 7
|
|
end
|
|
|
|
test "counts a position beyond the tablebase range" do
|
|
assert FEN.piece_count("3k4/2n2B2/1KP5/2B2p2/5b1p/7P/8/8 b - - 0 1") == 10
|
|
end
|
|
|
|
test "counts a board field without clocks" do
|
|
assert FEN.piece_count("8/8/3k4/8/8/3K1R2/8/8") == 3
|
|
end
|
|
|
|
test "returns nil for a malformed board" do
|
|
assert FEN.piece_count("not a fen") == nil
|
|
assert FEN.piece_count(nil) == nil
|
|
end
|
|
end
|
|
|
|
describe "board/1" do
|
|
test "returns eight ranks of eight squares" do
|
|
board = FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
|
|
|
|
assert length(board) == 8
|
|
assert Enum.all?(board, &(length(&1) == 8))
|
|
end
|
|
|
|
test "expands empty-square digits into nil squares" do
|
|
assert FEN.board("8/8/8/8/8/8/8/8") ==
|
|
List.duplicate(List.duplicate(nil, 8), 8)
|
|
end
|
|
|
|
test "maps each piece letter to its square" do
|
|
board = FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
|
|
|
|
assert Enum.at(board, 2) == [nil, nil, nil, "k", nil, nil, nil, nil]
|
|
assert Enum.at(board, 5) == [nil, nil, nil, "K", nil, "R", nil, nil]
|
|
end
|
|
|
|
test "reads only the board field" do
|
|
assert FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 37 99") ==
|
|
FEN.board("8/8/3k4/8/8/3K1R2/8/8")
|
|
end
|
|
|
|
test "returns nil for a malformed board" do
|
|
assert FEN.board("not a fen") == nil
|
|
assert FEN.board(nil) == nil
|
|
end
|
|
end
|
|
end
|