From bdff97d373682d8e1693c24f3b9f4cf2445fd2a2 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 25 Apr 2020 17:15:16 -0700 Subject: [PATCH] Added tests for saving with pending actions in admin changelist. --- tests/admin_changelist/admin.py | 2 ++ tests/admin_changelist/tests.py | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py index 1e686bd6fb1..1194f26dd42 100644 --- a/tests/admin_changelist/admin.py +++ b/tests/admin_changelist/admin.py @@ -105,6 +105,8 @@ site.register(Child, DynamicListDisplayChildAdmin) class NoListDisplayLinksParentAdmin(admin.ModelAdmin): list_display_links = None + list_display = ['name'] + list_editable = ['name'] site.register(Parent, NoListDisplayLinksParentAdmin) diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index 1d55813e228..4dff1edb322 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -1306,3 +1306,52 @@ class SeleniumTests(AdminSeleniumTestCase): '%s #result_list tbody tr:first-child .action-select' % form_id) row_selector.click() self.assertEqual(selection_indicator.text, "1 of 1 selected") + + def test_save_with_changes_warns_on_pending_action(self): + from selenium.webdriver.support.ui import Select + + Parent.objects.create(name='parent') + + self.admin_login(username='super', password='secret') + self.selenium.get(self.live_server_url + reverse('admin:admin_changelist_parent_changelist')) + + name_input = self.selenium.find_element_by_id('id_form-0-name') + name_input.clear() + name_input.send_keys('other name') + Select( + self.selenium.find_element_by_name('action') + ).select_by_value('delete_selected') + self.selenium.find_element_by_name('_save').click() + alert = self.selenium.switch_to.alert + try: + self.assertEqual( + alert.text, + 'You have selected an action, but you haven\'t saved your ' + 'changes to individual fields yet. Please click OK to save. ' + 'You\'ll need to re-run the action.', + ) + finally: + alert.dismiss() + + def test_save_without_changes_warns_on_pending_action(self): + from selenium.webdriver.support.ui import Select + + Parent.objects.create(name='parent') + + self.admin_login(username='super', password='secret') + self.selenium.get(self.live_server_url + reverse('admin:admin_changelist_parent_changelist')) + + Select( + self.selenium.find_element_by_name('action') + ).select_by_value('delete_selected') + self.selenium.find_element_by_name('_save').click() + alert = self.selenium.switch_to.alert + try: + self.assertEqual( + alert.text, + 'You have selected an action, and you haven\'t made any ' + 'changes on individual fields. You\'re probably looking for ' + 'the Go button rather than the Save button.', + ) + finally: + alert.dismiss()