Files
chess-endgame-trainer/test/chesstrainer_web/components/layouts_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

70 lines
2.1 KiB
Elixir

defmodule ChesstrainerWeb.LayoutsTest do
use ChesstrainerWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Chesstrainer.Accounts.Scope
alias Chesstrainer.Accounts.User
alias ChesstrainerWeb.Layouts
describe "navbar/1" do
test "signed-in users get a profile menu" do
scope = Scope.for_user(%User{username: "alice"})
html = render_component(&Layouts.navbar/1, %{current_scope: scope})
assert html =~ "alice"
assert html =~ ~s(class="nav-user-menu")
assert html =~ ~p"/users/profile"
assert html =~ ~p"/users/profile/settings"
assert html =~ ~p"/users/profile/data"
assert html =~ ~p"/users/log-out"
end
test "guests get log in and register links" do
html = render_component(&Layouts.navbar/1, %{current_scope: nil})
assert html =~ ~p"/users/log-in"
assert html =~ ~p"/users/register"
refute html =~ ~s(class="nav-user-menu")
end
end
describe "colour_mode_toggle/1" 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} <- [
{"light", "Light colour mode"},
{"dark", "Dark colour mode"}
] do
assert html =~ ~s(data-phx-theme="#{mode}")
assert html =~ ~s(aria-label="#{label}")
assert html =~ ~s(role="radio")
end
refute html =~ ~s(data-phx-theme="system")
assert html =~ ~s(aria-checked="true")
end
test "is rendered by the navbar" do
html = render_component(&Layouts.navbar/1, %{current_scope: nil})
assert html =~ ~s(aria-label="Colour mode")
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