HTML and CSS Reference
In-Depth Information
chat.userFormController = tddjs.extend({}, util.observable);
chat.userFormController.setView = setView;
chat.userFormController.setModel = setModel;
chat.userFormController.handleSubmit = handleSubmit;
}());
With the controller now observable, we can make it notify its observers for the
“user” event, as Listing 15.31 shows.
Listing 15.31 Notifying “user” observers
function handleSubmit(event) {
event.preventDefault();
if (this.view) {
var input = this.view.getElementsByTagName("input")[0];
this.model.currentUser = input.value;
this.notify("user", input.value);
}
}
The tests pass. However, the two last tests share an awful lot in common, and
to keep duplication at bay we will elevate some common setup code. Listing 15.32
shows the updated test case.
Listing 15.32 Elevating shared test setup
TestCase("UserFormControllerHandleSubmitTest", {
setUp: function () {
userFormControllerSetUp.call(this);
this.input =
this.element.getElementsByTagName("input")[0];
this.model = {};
this.controller.setModel(this.model);
this.controller.setView(this.element);
},
/* ... */
});
The previous test case doesn't really need any of the new setup, and in fact some
of it would interfere with its tests. To still be able to use the shared setup, we add a
setup specific to the test that calls the shared setup with the test case as this and
then adds more setup code.
 
Search WWH ::




Custom Search