Added tests for saving with pending actions in admin changelist.

This commit is contained in:
Jon Dufresne 2020-04-25 17:15:16 -07:00 committed by Mariusz Felisiak
parent 68fc21b378
commit bdff97d373
2 changed files with 51 additions and 0 deletions

View File

@ -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)

View File

@ -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()