summaryrefslogtreecommitdiff
path: root/tests/admin_views
diff options
context:
space:
mode:
authorSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-08-17 18:32:40 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-08-20 09:05:16 +0200
commitd9ae7f5b580a0e8475bbfe84a86e1bd0fd404663 (patch)
tree7feefea3403ad350095514d77739ee0d644b964f /tests/admin_views
parent231c0d85931b5afde3e3caec0e6bc5ca6132bb7a (diff)
Fixed #35686 -- Added table headers to app list tables for screen readers.
Diffstat (limited to 'tests/admin_views')
-rw-r--r--tests/admin_views/tests.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 9dbe1e1432..9a031a1e51 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -799,7 +799,9 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
reverse("admin:admin_views_complexsortedperson_changelist"), {}
)
# Should have 5 columns (including action checkbox col)
- self.assertContains(response, '<th scope="col"', count=5)
+ result_list_table_re = re.compile('<table id="result_list">(.*?)</thead>')
+ result_list_table_head = result_list_table_re.search(str(response.content))[0]
+ self.assertEqual(result_list_table_head.count('<th scope="col"'), 5)
self.assertContains(response, "Name")
self.assertContains(response, "Colored name")
@@ -830,7 +832,11 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
reverse("admin:admin_views_%s_changelist" % url), {}
)
# Should have 3 columns including action checkbox col.
- self.assertContains(response, '<th scope="col"', count=3, msg_prefix=url)
+ result_list_table_re = re.compile('<table id="result_list">(.*?)</thead>')
+ result_list_table_head = result_list_table_re.search(str(response.content))[
+ 0
+ ]
+ self.assertEqual(result_list_table_head.count('<th scope="col"'), 3)
# Check if the correct column was selected. 2 is the index of the
# 'order' column in the model admin's 'list_display' with 0 being
# the implicit 'action_checkbox' and 1 being the column 'stuff'.
@@ -7498,12 +7504,26 @@ class CSSTest(TestCase):
# General index page
response = self.client.get(reverse("admin:index"))
self.assertContains(response, '<div class="app-admin_views module')
+ self.assertContains(
+ response,
+ '<thead class="visually-hidden"><tr><th scope="col">Model name</th>'
+ '<th scope="col">Add link</th><th scope="col">Change or view list link</th>'
+ "</tr></thead>",
+ html=True,
+ )
self.assertContains(response, '<tr class="model-actor">')
self.assertContains(response, '<tr class="model-album">')
# App index page
response = self.client.get(reverse("admin:app_list", args=("admin_views",)))
self.assertContains(response, '<div class="app-admin_views module')
+ self.assertContains(
+ response,
+ '<thead class="visually-hidden"><tr><th scope="col">Model name</th>'
+ '<th scope="col">Add link</th><th scope="col">Change or view list link</th>'
+ "</tr></thead>",
+ html=True,
+ )
self.assertContains(response, '<tr class="model-actor">')
self.assertContains(response, '<tr class="model-album">')