mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
* commented out lesson and learning strip until lessons are established * reword the hero section * change layout and working on puzzle section - remove top div as it was redundant * amend flash message on replay * switch cancel session for return home * remove system theme toggle since this is the default, leaving only light and dark toggles * add keyboard and screen reader support for play (#72) First draft covering the accessibility work in #72:\n\n- labelled SAN/UCI move input, validated against the tablebase and applied\n by the board hook, plus an accessible promotion picker\n- live-region announcements for moves, checks, checkmates and solve/fail,\n and a hidden text summary of the position\n- accessible labels, focus ring, skip link, keyboard-friendly review table\n and non-colour grade cues\n- WCAG AA text contrast roles and a responsive play surface\n- regression tests for move entry, announcements and link-style CTAs
This commit is contained in:
@@ -25,6 +25,14 @@ defmodule ChesstrainerWeb.LandingComponentsTest do
|
||||
assert html =~ "Today’s position"
|
||||
end
|
||||
|
||||
test "describes the board as an image for assistive technology" do
|
||||
html = render_component(&LandingComponents.board_preview/1, %{endgame: @endgame})
|
||||
|
||||
assert html =~ ~s(role="img")
|
||||
assert html =~ "Chess position. White to move"
|
||||
assert html =~ "rook on f3"
|
||||
end
|
||||
|
||||
test "falls back to a neutral position without an endgame" do
|
||||
html = render_component(&LandingComponents.board_preview/1, %{endgame: nil})
|
||||
|
||||
|
||||
@@ -31,14 +31,13 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
||||
end
|
||||
|
||||
describe "colour_mode_toggle/1" do
|
||||
test "renders all three modes as a labelled radiogroup" do
|
||||
test "renders light and dark modes as a labelled radiogroup" do
|
||||
html = render_component(&Layouts.colour_mode_toggle/1, %{})
|
||||
|
||||
assert html =~ ~s(role="radiogroup")
|
||||
assert html =~ ~s(aria-label="Colour mode")
|
||||
|
||||
for {mode, label} <- [
|
||||
{"system", "System colour mode"},
|
||||
{"light", "Light colour mode"},
|
||||
{"dark", "Dark colour mode"}
|
||||
] do
|
||||
@@ -47,6 +46,7 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
||||
assert html =~ ~s(role="radio")
|
||||
end
|
||||
|
||||
refute html =~ ~s(data-phx-theme="system")
|
||||
assert html =~ ~s(aria-checked="true")
|
||||
end
|
||||
|
||||
@@ -57,4 +57,13 @@ defmodule ChesstrainerWeb.LayoutsTest do
|
||||
assert html =~ ~s(class="nav-right")
|
||||
end
|
||||
end
|
||||
|
||||
describe "pill button" do
|
||||
test "renders the navigation call to action as a link" do
|
||||
html = render_component(&Layouts.navbar/1, %{current_scope: nil})
|
||||
|
||||
assert html =~ ~r/<a[^>]*class="nav-cta"/
|
||||
refute html =~ ~r/<button[^>]*class="nav-cta"/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
defmodule ChesstrainerWeb.Board.PositionTextTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias ChesstrainerWeb.Board.PositionText
|
||||
|
||||
test "names the side to move and every piece" do
|
||||
assert PositionText.summary("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1") ==
|
||||
"White to move. White: king on d3, rook on f3. Black: king on d6."
|
||||
end
|
||||
|
||||
test "describes black to move" do
|
||||
assert PositionText.summary("8/8/3k4/8/8/3K1R2/8/8 b - - 0 1") =~
|
||||
"Black to move."
|
||||
end
|
||||
|
||||
test "includes pawns and both colours" do
|
||||
summary = PositionText.summary("8/8/3k4/8/8/3K1R2/4P3/8 w - - 0 1")
|
||||
|
||||
assert summary =~ "White: king on d3, rook on f3, pawn on e2."
|
||||
assert summary =~ "Black: king on d6."
|
||||
end
|
||||
|
||||
test "falls back when the FEN cannot be read" do
|
||||
assert PositionText.summary("not a fen") == "Chess position."
|
||||
assert PositionText.summary(nil) == "Chess position."
|
||||
end
|
||||
end
|
||||
@@ -69,7 +69,7 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
||||
refute html =~ "Phoenix Framework"
|
||||
|
||||
eyebrow = LazyHTML.query(document, ".eyebrow")
|
||||
assert LazyHTML.text(eyebrow) =~ "Endgames, made clear"
|
||||
assert LazyHTML.text(eyebrow) =~ "Endgames, simplified"
|
||||
assert LazyHTML.attribute(LazyHTML.query(eyebrow, "svg"), "aria-hidden") == ["true"]
|
||||
|
||||
assert LazyHTML.attribute(LazyHTML.query(document, ~s(meta[name="description"])), "content") ==
|
||||
@@ -216,19 +216,13 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
||||
refute html =~ ~p"/users/register"
|
||||
end
|
||||
|
||||
test "renders curated cards and the daily board", %{conn: conn} do
|
||||
{beginner, intermediate, advanced} = curated!()
|
||||
test "renders the daily board", %{conn: conn} do
|
||||
curated!()
|
||||
daily = DailyPuzzles.today()
|
||||
|
||||
html = conn |> get(~p"/") |> html_response(200)
|
||||
document = LazyHTML.from_document(html)
|
||||
|
||||
assert LazyHTML.attribute(LazyHTML.query(document, ".puzzle-card"), "href") == [
|
||||
"/endgames/#{beginner.public_code}/play",
|
||||
"/endgames/#{intermediate.public_code}/play",
|
||||
"/endgames/#{advanced.public_code}/play"
|
||||
]
|
||||
|
||||
board = LazyHTML.text(LazyHTML.query(document, ".board-caption"))
|
||||
assert board =~ daily.key
|
||||
|
||||
@@ -238,7 +232,6 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
||||
|
||||
assert LazyHTML.text(LazyHTML.query(document, ".board-topline")) =~ "White"
|
||||
assert html =~ "Try today's puzzle"
|
||||
assert html =~ "<span>puzzles</span>"
|
||||
end
|
||||
|
||||
test "hero CTA links to the daily puzzle", %{conn: conn} do
|
||||
@@ -274,7 +267,6 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
||||
document = LazyHTML.from_document(html)
|
||||
|
||||
assert html =~ "Featured position"
|
||||
assert html =~ "<span>puzzles</span>"
|
||||
refute html =~ "puzzle-card"
|
||||
|
||||
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [
|
||||
|
||||
@@ -961,7 +961,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
|
||||
assert_receive {^ref, {:push_event, "review_position", _}}, 100
|
||||
assert_receive {^ref, {:push_event, "review_position", _}}, 100
|
||||
|
||||
view |> element("#best-move-panel tr[phx-value-uci='d1d5']") |> render_click()
|
||||
view |> element("#best-move-panel button[phx-value-uci='d1d5']") |> render_click()
|
||||
|
||||
assert_receive {^ref, {:push_event, "best_line_move", %{from: "d1", to: "d5"}}}, 100
|
||||
|
||||
@@ -1044,4 +1044,84 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
|
||||
assert panel =~ "Qd7+"
|
||||
end
|
||||
end
|
||||
|
||||
describe "keyboard move input" do
|
||||
defp open_with_moves(conn) do
|
||||
endgame = endgame_fixture()
|
||||
seed_tablebase(endgame.fen, moves: grading_moves())
|
||||
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play")
|
||||
view
|
||||
end
|
||||
|
||||
test "accepts SAN and asks the board to apply it", %{conn: conn} do
|
||||
view = open_with_moves(conn)
|
||||
%{proxy: {ref, _topic, _}} = view
|
||||
|
||||
view |> form("#move-input-form", move: "Qd7+") |> render_submit()
|
||||
|
||||
assert_receive {^ref, {:push_event, "apply_move", %{from: "d1", to: "d7", san: "Qd7+"}}},
|
||||
100
|
||||
end
|
||||
|
||||
test "accepts UCI", %{conn: conn} do
|
||||
view = open_with_moves(conn)
|
||||
%{proxy: {ref, _topic, _}} = view
|
||||
|
||||
view |> form("#move-input-form", move: "d1d5") |> render_submit()
|
||||
|
||||
assert_receive {^ref, {:push_event, "apply_move", %{from: "d1", to: "d5"}}}, 100
|
||||
end
|
||||
|
||||
test "reports an illegal move without asking the board to play it", %{conn: conn} do
|
||||
view = open_with_moves(conn)
|
||||
%{proxy: {ref, _topic, _}} = view
|
||||
|
||||
html = view |> form("#move-input-form", move: "Qh8") |> render_submit()
|
||||
|
||||
assert html =~ "Not a legal move here"
|
||||
refute_receive {^ref, {:push_event, "apply_move", _}}, 100
|
||||
end
|
||||
|
||||
test "labels the input and explains both move formats", %{conn: conn} do
|
||||
view = open_with_moves(conn)
|
||||
|
||||
assert has_element?(view, "label[for='move-input']", "Your move")
|
||||
assert has_element?(view, "#move-input-help", "SAN or UCI")
|
||||
assert has_element?(view, "#move-input[aria-describedby='move-input-help']")
|
||||
end
|
||||
end
|
||||
|
||||
describe "screen reader announcements" do
|
||||
test "announces the opening position and whose move it is", %{conn: conn} do
|
||||
endgame = endgame_fixture()
|
||||
seed_tablebase(endgame.fen)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame.public_code}/play")
|
||||
|
||||
announcer = view |> element("#board-announcer") |> render()
|
||||
assert announcer =~ "You play White."
|
||||
assert announcer =~ "White to move."
|
||||
|
||||
summary = view |> element("#position-summary") |> render()
|
||||
assert summary =~ "king on"
|
||||
end
|
||||
|
||||
test "announces a failed puzzle and the best move", %{conn: conn} do
|
||||
{view, _fens} = seeded_attempt(conn)
|
||||
|
||||
announcer = view |> element("#board-announcer") |> render()
|
||||
assert announcer =~ "Failed."
|
||||
assert announcer =~ "Best was"
|
||||
end
|
||||
|
||||
test "announces the reviewed position", %{conn: conn} do
|
||||
{view, _fens} = seeded_attempt(conn)
|
||||
|
||||
view |> element("button", "Review") |> render_click()
|
||||
|
||||
announcer = view |> element("#board-announcer") |> render()
|
||||
assert announcer =~ "Reviewing position"
|
||||
assert announcer =~ "After Qd4"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -87,7 +87,7 @@ defmodule ChesstrainerWeb.EndgameLive.TrainTest do
|
||||
assert has_element?(view, "#difficulty-medium")
|
||||
assert has_element?(view, "#difficulty-hard")
|
||||
assert has_element?(view, "#close-difficulty[href='/']")
|
||||
assert has_element?(view, "a", "Cancel")
|
||||
assert has_element?(view, "a", "Return Home")
|
||||
refute has_element?(view, "#puzzle-search")
|
||||
assert has_element?(view, "#rating-guide")
|
||||
assert render(view) =~ "Choose a difficulty"
|
||||
|
||||
Reference in New Issue
Block a user