HTML and CSS Reference
In-Depth Information
15.5 The Message Form
The message form allows users to post messages. The steps required to test and
implement it are going to be very similar to the user form controller we created
previously: it needs a form element as its view; it will handle the form's submit event
through its handleSubmit method; and finally it will publish the message as an
event on the model object, which passes it to the server.
15.5.1 Setting up the Test
The first thing we need to do is to set up the test case and expect the controller
object to exist. Listing 15.64 shows the initial test case.
Listing 15.64 Setting up the messageFormController test case
(function () {
var messageController = tddjs.chat.messageFormController;
TestCase("FormControllerTestCase", {
"test should be object": function () {
assertObject(messageController);
}
});
}());
Running the test prompts us to define the object with a big fat red “F.” Listing
15.65 does the grunt work.
Listing 15.65 Defining the message form controller
(function () {
var chat = tddjs.namespace("chat");
chat.messageFormController = {};
}());
15.5.2 Setting the View
Just like the user form controller, this controller needs to add the “js-chat” class name
to its view and observe the “submit” event with the handleSubmit method bound
to the controller. In fact, setting the view for the message form controller should
work exactly like the one we previously wrote. We'll try to be slightly smarter than
to simply repeat the entire process; it seems obvious that the two form controllers
should share parts of their implementation.
 
 
Search WWH ::




Custom Search