2015-10-14 00:21:23 +02:00
var common = require ( '../casper_lib/common.js' ) . common ;
2013-03-07 19:30:42 +01:00
2013-03-05 20:52:54 +01:00
common . start _and _log _in ( ) ;
2013-03-07 19:30:42 +01:00
2013-06-11 23:08:11 +02:00
// Send a message to try replying to
2014-03-07 23:05:39 +01:00
common . then _send _many ( [
{ stream : 'Verona' ,
subject : 'Reply test' ,
content : "We reply to this message"
} ,
{ recipient : "cordelia@zulip.com" ,
content : "And reply to this message"
}
] ) ;
2013-06-11 23:08:11 +02:00
2013-06-13 16:56:50 +02:00
casper . waitForText ( "And reply to this message" , function ( ) {
// TODO: Test opening the compose box from the left side buttons
2013-06-11 23:08:11 +02:00
casper . click ( 'body' ) ;
2013-05-15 20:06:06 +02:00
casper . page . sendEvent ( 'keypress' , "c" ) ;
2013-06-13 16:56:50 +02:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#compose' , function ( ) {
casper . test . assertVisible ( '#stream' , 'Stream input box visible' ) ;
common . check _form ( '#send_message_form' , { stream : '' , subject : '' } , "Stream empty on new compose" ) ;
casper . click ( 'body' ) ;
casper . page . sendEvent ( 'keypress' , "C" ) ;
} ) ;
2013-06-13 16:56:50 +02:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#private_message_recipient' , function ( ) {
common . check _form ( '#send_message_form' , { recipient : '' } , "Recipient empty on new PM" ) ;
casper . click ( 'body' ) ;
casper . page . sendEvent ( 'keypress' , 'c' ) ;
} ) ;
2013-06-13 16:56:50 +02:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#stream' , function ( ) {
common . check _form ( '#send_message_form' , { stream : '' , subject : '' } , "Stream empty on new compose" ) ;
2013-06-11 23:08:11 +02:00
2016-09-08 14:10:41 +02:00
// Check that when you reply to a message it pre-populates the stream and subject fields
casper . click ( 'body' ) ;
} ) ;
2013-07-15 23:44:59 +02:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitWhileVisible ( '#stream' , function ( ) {
casper . clickLabel ( "We reply to this message" ) ;
} ) ;
2013-06-13 16:56:50 +02:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#stream' , function ( ) {
common . check _form ( '#send_message_form' , { stream : "Verona" , subject : "Reply test" } , "Stream populated after reply by click" ) ;
// Or recipient field
casper . click ( 'body' ) ;
casper . clickLabel ( "And reply to this message" ) ;
} ) ;
2013-06-13 16:56:50 +02:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#private_message_recipient' , function ( ) {
common . check _form ( '#send_message_form' , { recipient : "cordelia@zulip.com" } , "Recipient populated after PM click" ) ;
2013-06-11 23:08:11 +02:00
2016-09-08 14:10:41 +02:00
common . keypress ( 27 ) ; //escape
casper . page . sendEvent ( 'keypress' , 'k' ) ;
casper . page . sendEvent ( 'keypress' , 'r' ) ;
} ) ;
2013-06-13 16:56:50 +02:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#stream' , function ( ) {
common . check _form ( '#send_message_form' , { stream : "Verona" , subject : "Reply test" } , "Stream populated after reply with `r`" ) ;
2013-03-07 19:30:42 +01:00
2016-09-08 14:10:41 +02:00
// Test "closing" the compose box
casper . click ( 'body' ) ;
} ) ;
2013-03-07 19:30:42 +01:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitWhileVisible ( '#stream' , function ( ) {
casper . test . assertNotVisible ( '#stream' , 'Close stream compose box' ) ;
casper . page . sendEvent ( 'keypress' , "C" ) ;
casper . click ( 'body' ) ;
} ) ;
2013-03-07 19:30:42 +01:00
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitWhileVisible ( '#private-message' , function ( ) {
casper . test . assertNotVisible ( '#private-message' , 'Close PM compose box' ) ;
} ) ;
2013-03-07 19:30:42 +01:00
} ) ;
2013-07-15 23:44:59 +02:00
// Test focus after narrowing to PMs with a user and typing 'c'
casper . then ( function ( ) {
casper . click ( '*[title="Narrow to your private messages with Cordelia Lear"]' ) ;
} ) ;
casper . waitUntilVisible ( '#tab_list li.private_message' , function ( ) {
casper . page . sendEvent ( 'keypress' , 'c' ) ;
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#compose' , function ( ) {
casper . test . assertEval ( function ( ) {
return document . activeElement === $ ( '#stream' ) [ 0 ] ;
} , 'Stream box focused after narrowing to PMs with a user and pressing `c`' ) ;
} ) ;
2013-07-15 23:44:59 +02:00
} ) ;
2013-07-26 00:54:25 +02:00
// Make sure multiple PM recipients display properly.
var recipients = [ 'cordelia@zulip.com' , 'othello@zulip.com' ] ;
casper . then ( function ( ) {
common . keypress ( 27 ) ; // escape to dismiss compose box
} ) ;
2014-03-07 20:58:18 +01:00
casper . waitWhileVisible ( '.message_comp' ) ;
2014-03-07 20:59:30 +01:00
common . then _send _many ( [
2014-03-07 20:58:18 +01:00
{ recipient : recipients . join ( ',' ) ,
content : 'A huddle to check spaces' } ] ) ;
2014-03-07 20:55:33 +01:00
casper . then ( function ( ) {
common . keypress ( 27 ) ; // escape to dismiss compose box
} ) ;
casper . then ( function ( ) {
2013-07-26 00:54:25 +02:00
common . un _narrow ( ) ;
} ) ;
2014-03-07 20:55:33 +01:00
casper . waitUntilVisible ( '#zhome' , function ( ) {
2013-07-26 00:54:25 +02:00
casper . clickLabel ( 'A huddle to check spaces' ) ;
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#compose' , function ( ) {
// It may be possible to get the textbox contents with CasperJS,
// but it's easier to just evaluate jQuery in page context here.
var displayed _recipients = casper . evaluate ( function ( ) {
return $ ( '#private_message_recipient' ) . val ( ) ;
} ) ;
casper . test . assertEquals ( displayed _recipients , recipients . join ( ', ' ) ,
'Recipients are displayed correctly in a huddle reply' ) ;
2013-07-26 00:54:25 +02:00
} ) ;
} ) ;
2016-08-29 22:37:27 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#markdown_preview' , function ( ) {
casper . test . assertNotVisible ( '#undo_markdown_preview' , 'Write button is hidden' ) ;
casper . click ( "#markdown_preview" ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
casper . waitWhileVisible ( "#markdown_preview" , function ( ) {
casper . test . assertVisible ( '#undo_markdown_preview' , 'Write button is visible' ) ;
2016-09-26 22:03:42 +02:00
casper . test . assertEquals ( casper . getHTML ( '#preview_content' ) , "Nothing to preview" , "Nothing to preview" ) ;
2016-08-29 22:37:27 +02:00
casper . click ( "#undo_markdown_preview" ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
casper . waitWhileVisible ( "#undo_markdown_preview" , function ( ) {
casper . test . assertVisible ( '#markdown_preview' , 'Preview button is visible.' ) ;
casper . test . assertNotVisible ( '#undo_markdown_preview' , 'Write button is hidden.' ) ;
2016-09-26 22:03:42 +02:00
casper . test . assertEquals ( casper . getHTML ( '#preview_content' ) , "" , "Markdown preview area is empty" ) ;
2016-08-29 22:37:27 +02:00
casper . fill ( 'form[action^="/json/messages"]' , {
content : '**Markdown Preview** >> Test for markdown preview'
} , false ) ;
casper . click ( "#markdown_preview" ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
casper . waitWhileVisible ( "#markdown_preview" , function ( ) {
2016-09-26 22:03:42 +02:00
casper . test . assertEquals ( casper . getHTML ( '#preview_content' ) , "<p><strong>Markdown Preview</strong> >> Test for markdown preview</p>" , "Check markdown is previewed properly" ) ;
2016-08-29 22:37:27 +02:00
} ) ;
} ) ;
2013-03-05 20:52:54 +01:00
common . then _log _out ( ) ;
2013-03-07 19:30:42 +01:00
casper . run ( function ( ) {
2013-06-13 16:56:50 +02:00
casper . test . done ( ) ;
2013-03-05 20:52:54 +01:00
} ) ;