HTML and CSS Reference
In-Depth Information
15.2 The User Form
The user form is in charge of collecting the user's desired chat name. As the server
currently has no concept of connected users, it does not need to validate the user
name in any way, i.e., two users may be online at the same time using the same
name. The controller requires a DOM form element as its view, and expects this to
contain at least one text input, from which it will read the username when the form
is submitted.
When the form is submitted, the controller will assign the user to a property of
the model object, to make it available to the rest of the application. Then it will emit
an event, allowing other parts of the application to act on the newly arrived user.
15.2.1 Setting the View
The first task is to set the view, i.e., assign the DOM element that is the visual
representation of the component. Setting Up the Test Case
We start by setting up the test case and adding the first test, which expects user-
FormController to be an object. Listing 15.3 shows the initial test case. Save it
in test/user _ form _ controller _ test.js .
Listing 15.3 Expecting the object to exist
(function () {
var userController =;
TestCase("UserFormControllerTest", {
"test should be object": function () {
Listing 15.4 passes the test by setting up the userFormController object.
Save the listing in src/user _ form _ controller.js .
Listing 15.4 Defining the controller
tddjs.namespace("chat").userFormController = {};
Search WWH ::

Custom Search