from unittest import skip
from .base import FunctionalTest

class ItemValidationTest(FunctionalTest):

    def test_cannot_add_empty_list_items(self):
        self.fail("write me!")
from unittest import skip
from .base import FunctionalTest

class ItemValidationTest(FunctionalTest):

    def test_cannot_add_empty_list_items(self):
        # Edith goes to the home page and accidentally tries to submit and empty
        # list item. She hits Enter on the empty input box
        self.browser.get(self.server_url)
        self.browser.find_element_by_id('id_new_item').send_keys('\n')

        # The home page refreshes, and there is an error message saying
        # that list items cannot be blank
        error = self.browser.find_element_by_css_selector('.has_error')
        self.assertEqual(error.text, "You can't have an empty list item")

        # She tries again with some text for the item, which now works
        self.browser.find_element_by_id('id_new_item').send_keys('Buy milk\n')
        self.check_for_row_in_list_table('1: Buy milk')

        # Perversely, she now decides to submit a second blank list item
        self.browser.find_element_by_id('id_new_item').send_keys('\n')

        # She receives a similar warning on the list page
        self.check_for_row_in_list_table('1: Buy milk')
        error = self.browser.find_element_by_css_selector('.has-error')
        self.assertEqual(error.text, "You can't have an empty list item")

        # And she can correct it by filling some text in
        self.browser.find_element_by_id('id_new_item').send_keys('Make tea\n')
        self.check_for_row_in_list_table('1: Buy milk')
        self.check_for_row_in_list_table('2: Make tea')

Create test to detect submission of empty list items
Create test to detect submission of empty list items

  from unittest import skip
  from .base import FunctionalTest
  
  class ItemValidationTest(FunctionalTest):
  
      def test_cannot_add_empty_list_items(self):
-         self.fail("write me!")
+         # Edith goes to the home page and accidentally tries to submit and empty
+         # list item. She hits Enter on the empty input box
+         self.browser.get(self.server_url)
+         self.browser.find_element_by_id('id_new_item').send_keys('\n')
+ 
+         # The home page refreshes, and there is an error message saying
+         # that list items cannot be blank
+         error = self.browser.find_element_by_css_selector('.has_error')
+         self.assertEqual(error.text, "You can't have an empty list item")
+ 
+         # She tries again with some text for the item, which now works
+         self.browser.find_element_by_id('id_new_item').send_keys('Buy milk\n')
+         self.check_for_row_in_list_table('1: Buy milk')
+ 
+         # Perversely, she now decides to submit a second blank list item
+         self.browser.find_element_by_id('id_new_item').send_keys('\n')
+ 
+         # She receives a similar warning on the list page
+         self.check_for_row_in_list_table('1: Buy milk')
+         error = self.browser.find_element_by_css_selector('.has-error')
+         self.assertEqual(error.text, "You can't have an empty list item")
+ 
+         # And she can correct it by filling some text in
+         self.browser.find_element_by_id('id_new_item').send_keys('Make tea\n')
+         self.check_for_row_in_list_table('1: Buy milk')
+         self.check_for_row_in_list_table('2: Make tea')
+ 
Create test to detect submission of empty list items
## Code Before:
from unittest import skip
from .base import FunctionalTest

class ItemValidationTest(FunctionalTest):

    def test_cannot_add_empty_list_items(self):
        self.fail("write me!")
## Instruction:
Create test to detect submission of empty list items
## Code After:
from unittest import skip
from .base import FunctionalTest

class ItemValidationTest(FunctionalTest):

    def test_cannot_add_empty_list_items(self):
        # Edith goes to the home page and accidentally tries to submit and empty
        # list item. She hits Enter on the empty input box
        self.browser.get(self.server_url)
        self.browser.find_element_by_id('id_new_item').send_keys('\n')

        # The home page refreshes, and there is an error message saying
        # that list items cannot be blank
        error = self.browser.find_element_by_css_selector('.has_error')
        self.assertEqual(error.text, "You can't have an empty list item")

        # She tries again with some text for the item, which now works
        self.browser.find_element_by_id('id_new_item').send_keys('Buy milk\n')
        self.check_for_row_in_list_table('1: Buy milk')

        # Perversely, she now decides to submit a second blank list item
        self.browser.find_element_by_id('id_new_item').send_keys('\n')

        # She receives a similar warning on the list page
        self.check_for_row_in_list_table('1: Buy milk')
        error = self.browser.find_element_by_css_selector('.has-error')
        self.assertEqual(error.text, "You can't have an empty list item")

        # And she can correct it by filling some text in
        self.browser.find_element_by_id('id_new_item').send_keys('Make tea\n')
        self.check_for_row_in_list_table('1: Buy milk')
        self.check_for_row_in_list_table('2: Make tea')
