diff --git a/functional_tests/test_list_item_validation.py b/functional_tests/test_list_item_validation.py index 5f7af07..e2ea012 100644 --- a/functional_tests/test_list_item_validation.py +++ b/functional_tests/test_list_item_validation.py @@ -5,6 +5,12 @@ class ItemValidationTest(FunctionalTest): def get_error_element(self): return self.browser.find_element_by_css_selector('.has-error') + def cause_validation_error(self): + self.browser.get(self.server_url) + self.get_item_input_box().send_keys('\n') + error = self.get_error_element() + self.assertTrue(error.is_displayed()) + def test_cannot_add_empty_list_items(self): # Rob goes to the home page and accidentally tires to submit # an empty list item. He hits Enter on the empty input box. @@ -50,10 +56,7 @@ def test_cannot_add_duplicate_items(self): def test_error_messages_are_cleared_on_input(self): # Rob starts a new list in a way that causes a validation error: - self.browser.get(self.server_url) - self.get_item_input_box().send_keys('\n') - error = self.get_error_element() - self.assertTrue(error.is_displayed()) + self.cause_validation_error() # He starts typing in the input box to clear the error self.get_item_input_box().send_keys('a') @@ -64,3 +67,13 @@ def test_error_messages_are_cleared_on_input(self): # is_displayed() informs us whether an element is visible or not + def test_error_messages_are_cleared_on_click_inside_element(self): + # Rob starts a new list in a way that causes a validation error + self.cause_validation_error() + + # He clicks the box to clear the error + self.get_item_input_box().click() + + # He is pleased to have the error message disappear + error = self.get_error_element() + self.assertFalse(error.is_displayed()) diff --git a/lists/static/list.js b/lists/static/list.js index ee54867..de5150d 100644 --- a/lists/static/list.js +++ b/lists/static/list.js @@ -1,6 +1,14 @@ /*global $, test, equal */ -$('input').on('keypress', function() { - $('.has-error').hide(); +$(document).ready(function () { + $('input').on('keypress', function() { + $('.has-error').hide(); + }); +}); + +$(document).ready(function () { + $('input').on('click', function() { + $('.has-error').hide(); + }); }); diff --git a/lists/static/tests/tests.html b/lists/static/tests/tests.html index c635ac9..7836534 100644 --- a/lists/static/tests/tests.html +++ b/lists/static/tests/tests.html @@ -10,7 +10,7 @@