Skip to content

Commit

Permalink
Merge 8358d5c into 4a16b69
Browse files Browse the repository at this point in the history
  • Loading branch information
basilelegal committed Jun 12, 2015
2 parents 4a16b69 + 8358d5c commit ae4f028
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cms/static/cms/js/modules/cms.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ $(document).ready(function () {
row = iframe.contents().find('.save-box:eq(0)');
}
row.hide(); // hide submit-row
form = iframe.contents().find('form');
//avoids conflict between the browser's form validation and Django's validation
form.submit(function(e){
if (that.hideFrame) { //submit button was clicked
that.modal.find('.cms_modal-frame iframe').hide();
//page has been saved, run checkup
that.saved = true;
}
});
var buttons = row.find('input, a, button');
var render = $('<span />'); // seriously jquery...

Expand Down Expand Up @@ -507,10 +516,13 @@ $(document).ready(function () {
that.options.newPlugin = null;
// reset onClose when delete is triggered
if(item.hasClass('deletelink')) that.options.onClose = null;
// hide iframe
that.modal.find('.cms_modal-frame iframe').hide();
// page has been saved or deleted, run checkup
that.saved = true;
if (! item.hasClass('default')) {// hide iframe when using buttons other than submit
that.modal.find('.cms_modal-frame iframe').hide();
// page has been saved or deleted, run checkup
that.saved = true;
} else { // submit button uses the form's submit event
that.hideFrame = true;
}
}
});

Expand Down
3 changes: 3 additions & 0 deletions cms/test_utils/project/placeholderapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Example1(models.Model):
date_field = models.DateField(null=True)
placeholder = PlaceholderField('placeholder')
publish = models.BooleanField(default=True)
decimal_field = models.DecimalField(
max_digits=5, decimal_places=1,
blank=True, null=True,)

static_admin_url = ''

Expand Down
82 changes: 82 additions & 0 deletions cms/tests/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, NoAlertPresentException

from cms.api import create_page, create_title, add_plugin
Expand Down Expand Up @@ -446,3 +447,84 @@ def test_static_placeholders_permissions(self):
# test static placeholder permission (content of static placeholders is editable)
self.driver.get('%s/en/?%s' % (self.live_server_url, get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')))
self.assertTrue(self.driver.find_element_by_class_name(self.placeholder_name))


class FrontAdminTest(CMSLiveTests):

def setUp(self):
self.user = self.get_superuser()
Site.objects.create(domain='example.org', name='example.org')
self.base_url = self.live_server_url
self.driver.implicitly_wait(2)
super(FrontAdminTest, self).setUp()

def test_cms_modal_html5_validation_error(self):
User = get_user_model()
try:
apphook_pool.register(Example1App)
except AppAlreadyRegistered:
pass
self.reload_urls()
create_page('Home', 'simple.html', 'fr', published=True)
ex1 = Example1.objects.create(
char_1='char_1', char_2='char_1', char_3='char_3', char_4='char_4',
date_field=datetime.datetime.now()
)
create_page('apphook', 'simple.html', 'fr', published=True,
apphook=Example1App)
url = '%s/%s/?%s' % (
self.live_server_url, '/apphook/detail/class/%s'
% ex1.pk, get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')
)
self.driver.get(url)
username_input = self.driver.find_element_by_id("id_cms-username")
username_input.send_keys(getattr(self.user, User.USERNAME_FIELD))
password_input = self.driver.find_element_by_id("id_cms-password")
password_input.send_keys(getattr(self.user, User.USERNAME_FIELD))
password_input.submit()
self.wait_page_loaded()

# Load modal iframe
add_button = self.driver.find_element_by_css_selector(
'.cms_plugin-placeholderapp-example1-add-0'
)
open_modal_actions = ActionChains(self.driver)
open_modal_actions.double_click(add_button)
open_modal_actions.perform()
WebDriverWait(self.driver, 10).until(
EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe'))
)
# Fills form with an html5 error
char_1_input = self.driver.find_element_by_id("id_char_1")
char_1_input.send_keys("test")
char_2_input = self.driver.find_element_by_id("id_char_2")
char_2_input.send_keys("test")
char_3_input = self.driver.find_element_by_id("id_char_3")
char_3_input.send_keys("test")
char_4_input = self.driver.find_element_by_id("id_char_4")
char_4_input.send_keys("test")
id_date_input = self.driver.find_element_by_id("id_date_field")
id_date_input.send_keys('2036-01-01')
id_decimal_input = self.driver.find_element_by_id("id_decimal_field")
id_decimal_input.send_keys('t')

self.driver.switch_to_default_content()
submit_button = self.driver.find_element_by_css_selector('.default')
submit_button.click()

# check if the iframe is still displayed because of the html5 error
modal_iframe = self.driver.find_element_by_css_selector('iframe')
self.assertTrue(modal_iframe.is_displayed())

# corrects html5 error
self.driver.switch_to_frame(modal_iframe)
id_decimal_input = self.driver.find_element_by_id("id_decimal_field")
id_decimal_input.send_keys(Keys.BACK_SPACE + '1.2')
self.driver.switch_to_default_content()
submit_button = self.driver.find_element_by_css_selector('.default')
submit_button.click()
time.sleep(0.5)
with self.assertRaises(NoSuchElementException):
self.driver.find_element_by_css_selector('iframe')
example = Example1.objects.get(char_1='test')
self.assertEqual(float(example.decimal_field), 1.2)

0 comments on commit ae4f028

Please sign in to comment.