1
0
mirror of https://github.com/django/django.git synced 2024-12-30 13:05:45 +00:00
django/tests/admin_views/test_related_object_lookups.py
Nina Menezes 1699f8b52a Fixed #34628 -- Improved icons accessibility of related widget wrapper in admin.
This improves accessibility of icons by making them larger and grayscale
(when not selected).
2023-06-12 08:31:28 +02:00

79 lines
2.9 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_attributes(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"), "")
self.assertEqual(link_image.get_attribute("width"), "20")
self.assertEqual(link_image.get_attribute("height"), "20")
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"))