HTML and CSS Reference
In-Depth Information Removing the Added Class
The final requirement for the user form controller is removing the “js-chat” class
name once a user is successfully set. Listing 15.33 shows the initial test.
Listing 15.33 Expecting the class to be removed upon completion
"test should remove class when successful": function () {
this.input.value = "Sharuhachi";
assertEquals("", this.element.className);
To pass the test, we simply reset the class name if a user name was found. Listing
15.34 shows the updated handleSubmit .
Listing 15.34 Resetting the view's class
function handleSubmit(event) {
if (this.view) {
var input = this.view.getElementsByTagName("input")[0];
var userName = input.value;
this.view.className = "";
this.model.currentUser = userName;
this.notify("user", userName);
} Rejecting Empty Usernames
If the user submits the form without entering a username, the chat client will fail
upon trying to post messages, because the server won't allow empty user names. In
other words, allowing an empty username from the user form controller will cause
an error in completely unrelated parts of the code, which could be fairly hard to
debug. Listing 15.35 expects the controller not to set an empty username.
Listing 15.35 Expecting handleSubmit not to notify with empty username
"test should not notify observers of empty username":
function () {
var observer = stubFn();
Search WWH ::

Custom Search