diff --git a/functional_tests.py b/functional_tests.py index a3a197767c5ba9da2b5a89b53dce9286134207ae..8ca42923f926eeac13347ca76cc6a1413ac3faad 100644 --- a/functional_tests.py +++ b/functional_tests.py @@ -12,13 +12,10 @@ class NewVisitorTest(unittest.TestCase): def tearDown(self): self.browser.quit() - def test_uses_home_template(self): - response = self.client.get('/') - self.assertTemplateUsed(response, 'home.html') - - def test_can_save_a_POST_request(self): - response = self.client.post('/', data={'item_text': 'A new list item'}) - self.assertIn('A new list item', response.content.decode()) + def check_for_row_in_list_table(self, row_text): + table = self.browser.find_element_by_id('id_list_table') + rows = table.find_elements_by_tag_name('tr') + self.assertIn(row_text, [row.text for row in rows]) def test_can_start_a_list_and_retrieve_it_later(self): # Edith has heard about a cool new online to-do app. She goes @@ -34,6 +31,15 @@ class NewVisitorTest(unittest.TestCase): header_text = self.browser.find_element_by_tag_name('h1').text self.assertIn('Ardian Jati Permadi', header_text) + + # She check the comment when there is no item + comment = self.browser.find_element_by_id('comment') + self.assertEqual( + comment.text, + 'yey, waktunya berlibur' + ) + + # She is invited to enter a to-do item straight away inputbox = self.browser.find_element_by_id('id_new_item') self.assertEqual( @@ -46,14 +52,12 @@ class NewVisitorTest(unittest.TestCase): # is tying fly-fishing lures) inputbox.send_keys('Buy peacock feathers') + # When she hits enter, the page updates, and now the page lists # "1: Buy peacock feathers" as an item in a to-do list inputbox.send_keys(Keys.ENTER) time.sleep(1) - - table = self.browser.find_element_by_id('id_list_table') - rows = table.find_elements_by_tag_name('tr') - self.assertIn('1: Buy peacock feathers', [row.text for row in rows]) + self.check_for_row_in_list_table('1: Buy peacock feathers') # There is still a text box inviting her to add another item. She @@ -63,20 +67,42 @@ class NewVisitorTest(unittest.TestCase): inputbox.send_keys(Keys.ENTER) time.sleep(1) + # The page updates again, and now shows both items on her list - table = self.browser.find_element_by_id('id_list_table') - rows = table.find_elements_by_tag_name('tr') - self.assertIn('1: Buy peacock feathers', [row.text for row in rows]) - self.assertIn( - '2: Use peacock feathers to make a fly', - [row.text for row in rows] + self.check_for_row_in_list_table('1: Buy peacock feathers') + self.check_for_row_in_list_table('2: Use peacock feathers to make a fly') + + + # She check the comment when there is few items + comment = self.browser.find_element_by_id('comment') + self.assertEqual( + comment.text, + 'sibuk tapi santai' + ) + + + # Add additional items to change the comment + for i in range(4): + inputbox = self.browser.find_element_by_id('id_new_item') + inputbox.send_keys('Additional item %d' % i) + inputbox.send_keys(Keys.ENTER) + time.sleep(1) + + + # She check the comment when there is many items + comment = self.browser.find_element_by_id('comment') + self.assertEqual( + comment.text, + 'oh tidak' ) - # Edith wonders whether the site will remember her list. Then she sees + + # Edith wonders whether the site will remember her list. Then she sees # that the site has generated a unique URL for her -- there is some # explanatory text to that effect. - self.fail('Finish the test!') + + # She visits that URL - her to-do list is still there. # Satisfied, she goes back to sleep diff --git a/lists/templates/home.html b/lists/templates/home.html index 76d1e8d85ddf4cc233abc55d63b55cd09e41e790..2af79a6133cc02ad333347b5f2cd5e91be176e02 100644 --- a/lists/templates/home.html +++ b/lists/templates/home.html @@ -16,5 +16,14 @@ <tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr> {% endfor %} </table> + + {% if items|length > 5 %} + <p id="comment">oh tidak</p> + {% elif items|length > 0 %} + <p id="comment">sibuk tapi santai</p> + {% else %} + <p id="comment">yey, waktunya berlibur</p> + {% endif %} + </body> </html> \ No newline at end of file