Repository: django/django
File: tests/admin_views/tests.py (Python)

Code before:
            By.CSS_SELECTOR, "div#content ul.object-tools li"
        )
        self.assertGreater(len(object_tools), 0)
        self.take_screenshot("change_list")

    @screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
    def test_pagination_layout(self):
        from selenium.webdriver.common.by import By

        self.admin_login(
            username="super", password="secret", login_url=reverse("admin:index")
        )
        objects = [UnorderedObject(name=f"obj-{i}") for i in range(1, 23)]
        UnorderedObject.objects.bulk_create(objects)
        self.selenium.get(
            self.live_server_url
            + reverse("admin:admin_views_unorderedobject_changelist")
        )
        pages = self.selenium.find_elements(By.CSS_SELECTOR, "nav.paginator ul li")
        self.assertGreater(len(pages), 1)
        show_all = self.selenium.find_element(By.CSS_SELECTOR, "a.showall")
        self.assertTrue(show_all.is_displayed())
        self.take_screenshot("pagination")

    @screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
    def test_changelist_filter_sidebar_width(self):
        from selenium.webdriver.common.by import By

        self.admin_login(
            username="super", password="secret", login_url=reverse("admin:index")
        )
        self.selenium.get(
            self.live_server_url + reverse("admin:admin_views_person_changelist")
        )
        changelist_filter = self.selenium.find_element(By.ID, "changelist-filter")
        # Verify the filter width is constrained to max-width (240px).
        self.assertLessEqual(changelist_filter.rect["width"], 240)
        self.take_screenshot("filter_sidebar")


@override_settings(ROOT_URLCONF="admin_views.urls")
class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
    @classmethod
    def setUpTestData(cls):
        cls.superuser = User.objects.create_superuser(
            username="super", password="secret", email="super@example.com"
        )

    def setUp(self):
        self.client.force_login(self.superuser)


Review comment (security):
```diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py
index 4e2d13efa8..edc13fe5ae 100644
--- a/tests/admin_views/models.py
+++ b/tests/admin_views/models.py
@@ -668,7 +668,13 @@ class ReadOnlyPizza(Pizza):
 
 class Album(models.Model):
     owner = models.ForeignKey(User, models.SET_NULL, null=True, blank=True)
-    title = models.CharField(max_length=30)
+    title = models.CharField(
+        max_length=30,
+        verbose_name=(
+            "very very very very very very very very very "
+            "loooooooooooooooooooooooooooooooooooooooooong name"
+        )
+    )
 
 
 class Song(models.Model):
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 8ba3b53c41..96065d0846 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -7086,18 +7086,19 @@ class SeleniumTests(AdminSeleniumTestCase):
         self.take_screenshot("pagination")
 
     @screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
-    def test_changelist_filter_sidebar_width(self):
+    def test_changelist_filter_sidebar_with_long_verbose_name(self):
         from selenium.webdriver.common.by import By
 
         self.admin_login(
             username="super", password="secret", login_url=reverse("admin:index")
         )
+        Album.objects.create(title="oasis")
         self.selenium.get(
-            self.live_server_url + reverse("admin:admin_views_person_changelist")
+            self.live_server_url + reverse("admin:admin_views_album_changelist")
         )
         changelist_filter = self.selenium.find_element(By.ID, "changelist-filter")
+        self.assertTrue(changelist_filter.is_displayed())
         # Verify the filter width is constrained to max-width (240px).
-        self.assertLessEqual(changelist_filter.rect["width"], 240)
         self.take_screenshot("filter_sidebar")
```

I think we can actually reproduce the issue when it has a `verbose_name` containing long words like this.

<img width="2560" height="1162" alt="image" src="https://github.com/user-attachments/assets/43ed6969-35de-47ef-9a6b-b3a94d0c8afd" />


Code after:
        course = Course.objects.create(
            title="Django Class", materials="django_documents"
        )
        expected_legend_tags_text = [
            "Materials:",
            "Difficulty:",
            "Categories:",
            "Start datetime:",
        ]
        url = reverse("admin:admin_views_course_change", args=(course.pk,))
        self.selenium.get(self.live_server_url + url)
        fieldsets = self.selenium.find_elements(
            By.CSS_SELECTOR, "fieldset.aligned fieldset"
        )
        for index, fieldset in enumerate(fieldsets):
            legend = fieldset.find_element(By.TAG_NAME, "legend")
            self.assertEqual(legend.text, expected_legend_tags_text[index])

    @screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
    @override_settings(MESSAGE_LEVEL=10)
    def test_messages(self):
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support.ui import Select

        with override_settings(MESSAGE_LEVEL=10):
            self.admin_login(
                username="super", password="secret", login_url=reverse("admin:index")
            )
            UserMessenger.objects.create()
            for level in ["warning", "info", "error", "success", "debug"]:
                self.selenium.get(
                    self.live_server_url
                    + reverse("admin:admin_views_usermessenger_changelist"),
                )
                checkbox = self.selenium.find_element(
                    By.CSS_SELECTOR, "tr input.action-select"
                )
                checkbox.click()
                Select(self.selenium.find_element(By.NAME, "action")).select_by_value(
                    f"message_{level}"
                )
                self.selenium.find_element(By.XPATH, '//button[text()="Run"]').click()
                message = self.selenium.find_element(
                    By.CSS_SELECTOR, "ul.messagelist li"
                )
                self.assertEqual(message.get_attribute("innerText"), f"Test {level}")
                self.take_screenshot(level)

    @screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
    def test_list_editable_with_filter(self):
        from selenium.webdriver.common.by import By