Background Image
Table of Contents Table of Contents
Previous Page  253 / 478 Next Page
Information
Show Menu
Previous Page 253 / 478 Next Page
Page Background

CHAPTER 13

Dipping Our Toes, Very Tentatively,

into JavaScript

If the Good Lord had wanted us to enjoy ourselves, he wouldn’t have granted us his precious

gift of relentless misery.

— John Calvin (as portrayed in

Calvin and the Chipmunks )

Our new validation logic is good, but wouldn’t it be nice if the error messages disap‐

peared once the user started fixing the problem? For that we’d need a teeny-tiny bit of

JavaScript.

We are utterly spoiled by programming every day in such a joyful language as Python.

JavaScript is our punishment. So let’s dip our toes in, very gingerly.

I’m going to assume you know the basics of JavaScript syntax. If you

haven’t read

JavaScript: The Good Parts ,

go and get yourself a copy

right away! It’s not a very long book.

Starting with an FT

Let’s add a new functional test to the

ItemValidationTest

class:

functional_tests/test_list_item_validation.py (ch14l001).

def

test_error_messages_are_cleared_on_input

(

self

):

# Edith 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

.

browser

.

find_element_by_css_selector

(

'.has-error'

)

self

.

assertTrue

(

error

.

is_displayed

())

#

# She starts typing in the input box to clear the error

self

.

get_item_input_box

()

.

send_keys

(

'a'

)

225