Merge pull request #1355 from mluto/chat-no-empty-line

prevent empty chat-messages from being sent
This commit is contained in:
John McLear 2013-01-14 14:25:46 -08:00
commit bb9097e528
2 changed files with 29 additions and 0 deletions

View File

@ -75,6 +75,8 @@ var chat = (function()
send: function()
{
var text = $("#chatinput").val();
if(text.trim().length == 0)
return;
this._pad.collabClient.sendMessage({"type": "CHAT_MESSAGE", "text": text});
$("#chatinput").val("");
},

View File

@ -36,4 +36,31 @@ describe("send chat message", function(){
});
});
it("makes sure that an empty message can't be sent", function(done) {
var inner$ = helper.padInner$;
var chrome$ = helper.padChrome$;
//click on the chat button to make chat visible
var $chatButton = chrome$("#chaticon");
$chatButton.click();
var $chatInput = chrome$("#chatinput");
$chatInput.sendkeys('{enter}'); // simulate a keypress of enter (to send an empty message)
$chatInput.sendkeys('mluto'); // simulate a keypress of typing mluto
$chatInput.sendkeys('{enter}'); // simulate a keypress of enter (to send 'mluto')
//check if chat shows up
helper.waitFor(function(){
return chrome$("#chattext").children("p").length !== 0; // wait until the chat message shows up
}).done(function(){
// check that the empty message is not there
expect(chrome$("#chattext").children("p").length).to.be(1);
// check that the received message is not the empty one
var $firstChatMessage = chrome$("#chattext").children("p");
var containsMessage = $firstChatMessage.text().indexOf("mluto") !== -1;
expect(containsMessage).to.be(true);
done();
});
});
});