fix(navigation): keep menu icon glyphs out of the links' accessible names

Font Awesome 6 paints each icon through ::before with a private-use
character, and the menu's <i> elements carried no aria-hidden, so every
menu link's accessible name began with that glyph: the Login link was
announced as " Login". Screen readers read the glyph, and exact
name matches such as Playwright's getByRole("link", { name: /^login$/i })
never found the link, which left infinito-nexus's post-login check that
the Login control is gone passing without ever looking at it.

The icons of the navigation macro and of the language menu are now
aria-hidden, as Font Awesome recommends for decorative icons. A unit
test holds every icon of the rendered header to it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-10 16:03:08 +02:00
parent d115fc99b2
commit e00ff9437c
2 changed files with 35 additions and 18 deletions

View File

@@ -9,14 +9,46 @@ class AnchorCollector(HTMLParser):
def __init__(self):
super().__init__()
self.anchors = []
self.icons = []
def handle_starttag(self, tag, attrs):
if tag == "a":
self.anchors.append(dict(attrs))
if tag == "i":
self.icons.append(dict(attrs))
class TestNavigationTemplate(unittest.TestCase):
def test_top_level_dropdowns_have_bootstrap_toggle_attribute(self):
parser = self._render_header()
dropdown_toggles = [
anchor
for anchor in parser.anchors
if "nav-link" in anchor.get("class", "")
and "dropdown-toggle" in anchor.get("class", "")
]
self.assertEqual(len(dropdown_toggles), 2)
for toggle in dropdown_toggles:
self.assertEqual(toggle.get("data-bs-toggle"), "dropdown")
language_links = [
anchor for anchor in parser.anchors if anchor.get("hreflang") == "de"
]
self.assertEqual(len(language_links), 1)
self.assertEqual(language_links[0]["href"], "/de/")
def test_menu_icons_stay_out_of_the_accessible_name(self):
parser = self._render_header()
self.assertTrue(parser.icons)
self.assertEqual(
[icon for icon in parser.icons if icon.get("aria-hidden") != "true"],
[],
"a Font Awesome glyph without aria-hidden joins the link's accessible name",
)
def _render_header(self):
template_dir = Path(__file__).resolve().parents[2] / "app" / "templates"
environment = Environment(
loader=FileSystemLoader(template_dir),
@@ -68,22 +100,7 @@ class TestNavigationTemplate(unittest.TestCase):
parser = AnchorCollector()
parser.feed(rendered)
dropdown_toggles = [
anchor
for anchor in parser.anchors
if "nav-link" in anchor.get("class", "")
and "dropdown-toggle" in anchor.get("class", "")
]
self.assertEqual(len(dropdown_toggles), 2)
for toggle in dropdown_toggles:
self.assertEqual(toggle.get("data-bs-toggle"), "dropdown")
language_links = [
anchor for anchor in parser.anchors if anchor.get("hreflang") == "de"
]
self.assertEqual(len(language_links), 1)
self.assertEqual(language_links[0]["href"], "/de/")
return parser
if __name__ == "__main__":