mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #34025 -- Fixed selecting ModelAdmin.autocomplete_fields after adding/changing related instances via popups.
Regression in c72f6f36c1.
Thanks Alexandre da Silva for the report.
This commit is contained in:
committed by
Mariusz Felisiak
parent
6e891a1722
commit
9976f3d4b8
@@ -6317,18 +6317,24 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||
finally:
|
||||
self.selenium.set_window_size(current_size["width"], current_size["height"])
|
||||
|
||||
def test_updating_related_objects_updates_fk_selects(self):
|
||||
def test_updating_related_objects_updates_fk_selects_except_autocompletes(self):
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import Select
|
||||
|
||||
born_country_select_id = "id_born_country"
|
||||
living_country_select_id = "id_living_country"
|
||||
living_country_select2_textbox_id = "select2-id_living_country-container"
|
||||
favorite_country_to_vacation_select_id = "id_favorite_country_to_vacation"
|
||||
continent_select_id = "id_continent"
|
||||
|
||||
def _get_HTML_inside_element_by_id(id_):
|
||||
return self.selenium.find_element(By.ID, id_).get_attribute("innerHTML")
|
||||
|
||||
def _get_text_inside_element_by_selector(selector):
|
||||
return self.selenium.find_element(By.CSS_SELECTOR, selector).get_attribute(
|
||||
"innerText"
|
||||
)
|
||||
|
||||
self.admin_login(
|
||||
username="super", password="secret", login_url=reverse("admin:index")
|
||||
)
|
||||
@@ -6353,12 +6359,16 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||
<option value="1" selected="">Argentina</option>
|
||||
""",
|
||||
)
|
||||
self.assertHTMLEqual(
|
||||
_get_HTML_inside_element_by_id(living_country_select_id),
|
||||
"""
|
||||
<option value="" selected="">---------</option>
|
||||
<option value="1">Argentina</option>
|
||||
""",
|
||||
# Argentina isn't added to the living_country select nor selected by
|
||||
# the select2 widget.
|
||||
self.assertEqual(
|
||||
_get_text_inside_element_by_selector(f"#{living_country_select_id}"), ""
|
||||
)
|
||||
self.assertEqual(
|
||||
_get_text_inside_element_by_selector(
|
||||
f"#{living_country_select2_textbox_id}"
|
||||
),
|
||||
"",
|
||||
)
|
||||
# Argentina won't appear because favorite_country_to_vacation field has
|
||||
# limit_choices_to.
|
||||
@@ -6386,13 +6396,18 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||
<option value="2">Spain</option>
|
||||
""",
|
||||
)
|
||||
self.assertHTMLEqual(
|
||||
_get_HTML_inside_element_by_id(living_country_select_id),
|
||||
"""
|
||||
<option value="" selected="">---------</option>
|
||||
<option value="1">Argentina</option>
|
||||
<option value="2" selected="">Spain</option>
|
||||
""",
|
||||
|
||||
# Spain is added to the living_country select and it's also selected by
|
||||
# the select2 widget.
|
||||
self.assertEqual(
|
||||
_get_text_inside_element_by_selector(f"#{living_country_select_id} option"),
|
||||
"Spain",
|
||||
)
|
||||
self.assertEqual(
|
||||
_get_text_inside_element_by_selector(
|
||||
f"#{living_country_select2_textbox_id}"
|
||||
),
|
||||
"Spain",
|
||||
)
|
||||
# Spain won't appear because favorite_country_to_vacation field has
|
||||
# limit_choices_to.
|
||||
@@ -6422,13 +6437,17 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||
<option value="2">Italy</option>
|
||||
""",
|
||||
)
|
||||
self.assertHTMLEqual(
|
||||
_get_HTML_inside_element_by_id(living_country_select_id),
|
||||
"""
|
||||
<option value="" selected="">---------</option>
|
||||
<option value="1">Argentina</option>
|
||||
<option value="2" selected="">Italy</option>
|
||||
""",
|
||||
# Italy is added to the living_country select and it's also selected by
|
||||
# the select2 widget.
|
||||
self.assertEqual(
|
||||
_get_text_inside_element_by_selector(f"#{living_country_select_id} option"),
|
||||
"Italy",
|
||||
)
|
||||
self.assertEqual(
|
||||
_get_text_inside_element_by_selector(
|
||||
f"#{living_country_select2_textbox_id}"
|
||||
),
|
||||
"Italy",
|
||||
)
|
||||
# favorite_country_to_vacation field has no options.
|
||||
self.assertHTMLEqual(
|
||||
|
||||
Reference in New Issue
Block a user