1
0
mirror of https://github.com/django/django.git synced 2025-01-09 01:46:20 +00:00
django/tests/admin_views/test_related_object_lookups.py
Coen van der Kamp 10d9d0ccb2 Fixed #34622 -- Improved accessibility of related widget wrapper in admin.
This improves accessibility for screen reader users by adding
"aria-disabled" and removing "alt".

Thanks Thibaud Colas for the report.
2023-06-05 14:43:51 +02:00

77 lines
2.7 KiB
Python

from django.contrib.admin.tests import AdminSeleniumTestCase
from django.contrib.auth.models import User
from django.test import override_settings
from django.urls import reverse
@override_settings(ROOT_URLCONF="admin_views.urls")
class SeleniumTests(AdminSeleniumTestCase):
available_apps = ["admin_views"] + AdminSeleniumTestCase.available_apps
def setUp(self):
self.superuser = User.objects.create_superuser(
username="super", password="secret", email="super@example.com"
)
self.admin_login(
username="super", password="secret", login_url=reverse("admin:index")
)
def test_related_object_link_images_empty_alt(self):
from selenium.webdriver.common.by import By
album_add_url = reverse("admin:admin_views_album_add")
self.selenium.get(self.live_server_url + album_add_url)
tests = [
"add_id_owner",
"change_id_owner",
"delete_id_owner",
"view_id_owner",
]
for link_id in tests:
with self.subTest(link_id):
link_image = self.selenium.find_element(
By.XPATH, f'//*[@id="{link_id}"]/img'
)
self.assertEqual(link_image.get_attribute("alt"), "")
def test_related_object_lookup_link_initial_state(self):
from selenium.webdriver.common.by import By
album_add_url = reverse("admin:admin_views_album_add")
self.selenium.get(self.live_server_url + album_add_url)
tests = [
"change_id_owner",
"delete_id_owner",
"view_id_owner",
]
for link_id in tests:
with self.subTest(link_id):
link = self.selenium.find_element(By.XPATH, f'//*[@id="{link_id}"]')
self.assertEqual(link.get_attribute("aria-disabled"), "true")
def test_related_object_lookup_link_enabled(self):
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
album_add_url = reverse("admin:admin_views_album_add")
self.selenium.get(self.live_server_url + album_add_url)
select_element = self.selenium.find_element(By.XPATH, '//*[@id="id_owner"]')
option = Select(select_element).options[-1]
self.assertEqual(option.text, "super")
select_element.click()
option.click()
tests = [
"add_id_owner",
"change_id_owner",
"delete_id_owner",
"view_id_owner",
]
for link_id in tests:
with self.subTest(link_id):
link = self.selenium.find_element(By.XPATH, f'//*[@id="{link_id}"]')
self.assertIsNone(link.get_attribute("aria-disabled"))