Add Python unit tests to ensure the skip link element is present

pull/12555/head
LB 2024-11-08 07:59:49 +10:00
rodzic 1772909551
commit 3c628b8ad2
2 zmienionych plików z 17 dodań i 1 usunięć

Wyświetl plik

@ -32,7 +32,7 @@
{% block js %}{% endblock %}
<a class="skiplink button" href="#main" data-controller="w-skip-link" data-action="w-skip-link#skip">{% trans 'Skip to main content' %}</a>
<a class="skiplink button" href="#main" data-controller="w-focus" data-action="w-focus#focus:prevent">{% trans 'Skip to main content' %}</a>
<div class="wrapper">
{% block furniture %}{% endblock %}

Wyświetl plik

@ -31,6 +31,22 @@ class TestHome(WagtailTestUtils, TestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Test Site")
def test_accessible_skip_link_exists(self):
response = self.client.get(reverse("wagtailadmin_home"))
self.assertEqual(response.status_code, 200)
soup = self.get_soup(response.content)
# Check that the skip link is present and has the correct attributes
skip_link = soup.select_one(".skiplink")
self.assertIsNotNone(skip_link)
self.assertEqual(skip_link["href"], "#main")
self.assertEqual(skip_link["data-controller"], "w-focus")
self.assertEqual(skip_link["data-action"], "w-focus#focus:prevent")
# Check that the main content area has the correct ID
main_content = soup.select_one("#main")
self.assertIsNotNone(main_content)
def test_admin_menu(self):
response = self.client.get(reverse("wagtailadmin_home"))
self.assertEqual(response.status_code, 200)