diff options
| author | antoliny0919 <antoliny0919@gmail.com> | 2025-05-08 19:24:07 +0900 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-06-27 18:03:16 +0200 |
| commit | 3f59711581bd22ebd0f13fb040b15b69c0eee21f (patch) | |
| tree | 7b3eea333004013bbfdd1d48b6eb4644cd164c8f /tests | |
| parent | 29f5e1e97d660855d34c1ee5edbd5cfe094b6ca7 (diff) | |
Fixed #36366 -- Improved accessibility of pagination in the admin.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_changelist/tests.py | 35 | ||||
| -rw-r--r-- | tests/admin_views/test_history_view.py | 21 |
2 files changed, 50 insertions, 6 deletions
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index 7203daa6b0..cd2fe7c645 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -946,6 +946,41 @@ class ChangeListTests(TestCase): self.assertEqual(cl.paginator.count, 30) self.assertEqual(list(cl.paginator.page_range), [1, 2, 3]) + def test_pagination_render(self): + objs = [Swallow(origin=f"Swallow {i}", load=i, speed=i) for i in range(1, 5)] + Swallow.objects.bulk_create(objs) + + request = self.factory.get("/child/") + request.user = self.superuser + + admin = SwallowAdmin(Swallow, custom_site) + cl = admin.get_changelist_instance(request) + template = Template( + "{% load admin_list %}{% spaceless %}{% pagination cl %}{% endspaceless %}" + ) + context = Context({"cl": cl, "opts": cl.opts}) + pagination_output = template.render(context) + self.assertTrue( + pagination_output.startswith( + '<nav class="paginator" aria-labelledby="pagination">' + ) + ) + self.assertInHTML( + '<h2 id="pagination" class="visually-hidden">Pagination swallows</h2>', + pagination_output, + ) + self.assertTrue(pagination_output.endswith("</nav>")) + self.assertInHTML( + '<li><a role="button" href="" aria-current="page">1</a></li>', + pagination_output, + ) + self.assertInHTML( + '<li><a role="button" href="?p=2">2</a></li>', + pagination_output, + ) + self.assertEqual(pagination_output.count('aria-current="page"'), 1) + self.assertEqual(pagination_output.count('href=""'), 1) + def test_computed_list_display_localization(self): """ Regression test for #13196: output of functions should be localized diff --git a/tests/admin_views/test_history_view.py b/tests/admin_views/test_history_view.py index 7079c1d0d8..49a60aa306 100644 --- a/tests/admin_views/test_history_view.py +++ b/tests/admin_views/test_history_view.py @@ -80,20 +80,29 @@ class SeleniumTests(AdminSeleniumTestCase): self.selenium.get(self.live_server_url + user_history_url) paginator = self.selenium.find_element(By.CSS_SELECTOR, ".paginator") + self.assertEqual(paginator.tag_name, "nav") + labelledby = paginator.get_attribute("aria-labelledby") + description = self.selenium.find_element(By.CSS_SELECTOR, "#%s" % labelledby) + self.assertHTMLEqual( + description.get_attribute("outerHTML"), + '<h2 id="pagination" class="visually-hidden">Pagination user entries</h2>', + ) self.assertTrue(paginator.is_displayed()) + aria_current_link = paginator.find_elements(By.CSS_SELECTOR, "[aria-current]") + self.assertEqual(len(aria_current_link), 1) + # The current page. + current_page_link = aria_current_link[0] + self.assertEqual(current_page_link.get_attribute("aria-current"), "page") + self.assertEqual(current_page_link.get_attribute("href"), "") self.assertIn("%s entries" % LogEntry.objects.count(), paginator.text) self.assertIn(str(Paginator.ELLIPSIS), paginator.text) - # The current page. - current_page_link = self.selenium.find_element( - By.CSS_SELECTOR, "span.this-page" - ) self.assertEqual(current_page_link.text, "1") # The last page. - last_page_link = self.selenium.find_element(By.CSS_SELECTOR, ".end") + last_page_link = self.selenium.find_element(By.XPATH, "//ul/li[last()]/a") self.assertTrue(last_page_link.text, "20") # Select the second page. pages = paginator.find_elements(By.TAG_NAME, "a") - second_page_link = pages[0] + second_page_link = pages[1] self.assertEqual(second_page_link.text, "2") second_page_link.click() self.assertIn("?p=2", self.selenium.current_url) |
