Files
chess-endgame-trainer/test/chesstrainer_web/components/landing_components_test.exs
T
owenrees 805c2f1150 Accessibility: keyboard move entry and screen reader support (#72) (#115)
* 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
2026-11-09 12:09:07 +01:00

85 lines
2.5 KiB
Elixir
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
defmodule ChesstrainerWeb.LandingComponentsTest do
use ChesstrainerWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Chesstrainer.Endgames.Endgame
alias Chesstrainer.Themes.Theme
alias ChesstrainerWeb.LandingComponents
@endgame %Endgame{
fen: "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1",
color: :white,
key: "KR v K"
}
test "renders the endgame's pieces, side to move, and caption" do
html = render_component(&LandingComponents.board_preview/1, %{endgame: @endgame})
assert html =~ "KR v K"
assert html =~ "To move"
assert html =~ "White"
assert html =~ "♔"
assert html =~ "♖"
assert html =~ "♚"
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})
assert html =~ "Featured position"
assert html =~ "White"
assert html =~ "♖"
end
test "renders themes under the position title" do
endgame = %{
fen: @endgame.fen,
color: :white,
key: "KR v K",
themes: [%Theme{name: "Lucena"}]
}
html = render_component(&LandingComponents.board_preview/1, %{endgame: endgame})
assert html =~ "Lucena"
end
test "renders the spark icon as a decorative primitive" do
html = render_component(&LandingComponents.icon_spark/1, %{})
assert html =~ "<svg"
assert html =~ ~s(aria-hidden="true")
assert html =~ "currentColor"
end
describe "count_label/1" do
test "shows counts below 100 exactly" do
assert LandingComponents.count_label(0) == "0"
assert LandingComponents.count_label(47) == "47"
assert LandingComponents.count_label(99) == "99"
end
test "floors counts of 100 or more to hundreds" do
assert LandingComponents.count_label(100) == "100+"
assert LandingComponents.count_label(199) == "100+"
assert LandingComponents.count_label(999) == "900+"
end
test "floors counts of 1000 or more to thousands" do
assert LandingComponents.count_label(1000) == "1000+"
assert LandingComponents.count_label(1999) == "1000+"
assert LandingComponents.count_label(2400) == "2000+"
end
end
end