summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCauê Thenório <caue@thenorio.com.br>2023-07-07 10:58:07 -0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-10 10:09:07 +0200
commitf7cfa48283c94018861688f17ab3935d588fbcc3 (patch)
tree63b32dcc1da8cae23de4635b8ca8b947b7e7f3db
parent99bd373367e54790da25b64c1d21610ac0f9feda (diff)
Fixed #34696 -- Updated selection counter in admin changelist on Chrome.
-rw-r--r--django/contrib/admin/static/admin/js/actions.js3
-rw-r--r--tests/admin_changelist/tests.py35
2 files changed, 38 insertions, 0 deletions
diff --git a/django/contrib/admin/static/admin/js/actions.js b/django/contrib/admin/static/admin/js/actions.js
index 20a5c14353..6a2ae91a19 100644
--- a/django/contrib/admin/static/admin/js/actions.js
+++ b/django/contrib/admin/static/admin/js/actions.js
@@ -179,6 +179,9 @@
}
});
}
+ // Sync counter when navigating to the page, such as through the back
+ // button.
+ window.addEventListener('pageshow', (event) => updateCounter(actionCheckboxes, options));
};
// Call function fn when the DOM is loaded and ready. If it is already
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index 8fdd343b18..a926f9d826 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -1741,6 +1741,41 @@ class SeleniumTests(AdminSeleniumTestCase):
self.assertIs(c.get_property("checked"), True)
self.assertIs(checkboxes[-1].get_property("checked"), False)
+ def test_selection_counter_is_synced_when_page_is_shown(self):
+ from selenium.webdriver.common.by import By
+
+ self.admin_login(username="super", password="secret")
+ self.selenium.get(self.live_server_url + reverse("admin:auth_user_changelist"))
+
+ form_id = "#changelist-form"
+ first_row_checkbox_selector = (
+ f"{form_id} #result_list tbody tr:first-child .action-select"
+ )
+ selection_indicator_selector = f"{form_id} .action-counter"
+ selection_indicator = self.selenium.find_element(
+ By.CSS_SELECTOR, selection_indicator_selector
+ )
+ row_checkbox = self.selenium.find_element(
+ By.CSS_SELECTOR, first_row_checkbox_selector
+ )
+ # Select a row.
+ row_checkbox.click()
+ self.assertEqual(selection_indicator.text, "1 of 1 selected")
+ # Go to another page and get back.
+ self.selenium.get(
+ self.live_server_url + reverse("admin:admin_changelist_parent_changelist")
+ )
+ self.selenium.back()
+ # The selection indicator is synced with the selected checkboxes.
+ selection_indicator = self.selenium.find_element(
+ By.CSS_SELECTOR, selection_indicator_selector
+ )
+ row_checkbox = self.selenium.find_element(
+ By.CSS_SELECTOR, first_row_checkbox_selector
+ )
+ selected_rows = 1 if row_checkbox.is_selected() else 0
+ self.assertEqual(selection_indicator.text, f"{selected_rows} of 1 selected")
+
def test_select_all_across_pages(self):
from selenium.webdriver.common.by import By