summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/static/js/chat.js2
-rw-r--r--tests/frontend/specs/keystroke_chat.js39
2 files changed, 40 insertions, 1 deletions
diff --git a/src/static/js/chat.js b/src/static/js/chat.js
index 486c7256..4493ed15 100644
--- a/src/static/js/chat.js
+++ b/src/static/js/chat.js
@@ -150,7 +150,7 @@ var chat = (function()
$("#chatinput").keypress(function(evt)
{
//if the user typed enter, fire the send
- if(evt.which == 13)
+ if(evt.which == 13 || evt.which == 10)
{
evt.preventDefault();
self.send();
diff --git a/tests/frontend/specs/keystroke_chat.js b/tests/frontend/specs/keystroke_chat.js
new file mode 100644
index 00000000..f882a360
--- /dev/null
+++ b/tests/frontend/specs/keystroke_chat.js
@@ -0,0 +1,39 @@
+describe("send chat message", function(){
+ //create a new pad before each test run
+ beforeEach(function(cb){
+ helper.newPad(cb);
+ this.timeout(5000);
+ });
+
+ it("opens chat, sends a message and makes sure it exists on the page", function(done) {
+ var inner$ = helper.padInner$;
+ var chrome$ = helper.padChrome$;
+ var chatValue = "JohnMcLear";
+
+ //click on the chat button to make chat visible
+ var $chatButton = chrome$("#chaticon");
+ $chatButton.click();
+ var $chatInput = chrome$("#chatinput");
+ $chatInput.sendkeys('JohnMcLear'); // simulate a keypress of typing JohnMcLear
+ $chatInput.sendkeys('{enter}'); // simulate a keypress of enter actually does evt.which = 10 not 13
+
+ //check if chat shows up
+ helper.waitFor(function(){
+ return chrome$("#chattext").children("p").length !== 0; // wait until the chat message shows up
+ }).done(function(){
+ var $firstChatMessage = chrome$("#chattext").children("p");
+ var containsMessage = $firstChatMessage.text().indexOf("JohnMcLear") !== -1; // does the string contain JohnMcLear?
+ expect(containsMessage).to.be(true); // expect the first chat message to contain JohnMcLear
+
+ // do a slightly more thorough check
+ var username = $firstChatMessage.children("b");
+ var usernameValue = username.text();
+ var time = $firstChatMessage.children(".time");
+ var timeValue = time.text();
+ var expectedStringIncludingUserNameAndTime = usernameValue + timeValue + " " + "JohnMcLear";
+ expect(expectedStringIncludingUserNameAndTime).to.be($firstChatMessage.text());
+ done();
+ });
+
+ });
+});