2019-10-25 09:45:13 +02:00
var common = require ( '../casper_lib/common.js' ) ;
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
2017-06-07 07:59:51 +02:00
var msgs _qty ;
casper . then ( function ( ) {
casper . waitUntilVisible ( "#zhome" ) ;
} ) ;
casper . then ( function ( ) {
msgs _qty = this . evaluate ( function ( ) {
return $ ( '#zhome .message_row' ) . length ;
} ) ;
} ) ;
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' ,
2016-12-03 23:18:30 +01:00
content : "We reply to this message" ,
2014-03-07 23:05:39 +01:00
} ,
{ recipient : "cordelia@zulip.com" ,
2016-12-03 23:18:30 +01:00
content : "And reply to this message" ,
} ,
2014-03-07 23:05:39 +01:00
] ) ;
2013-06-11 23:08:11 +02:00
2017-06-07 07:59:51 +02:00
casper . then ( function ( ) {
casper . waitFor ( function check _length ( ) {
return casper . evaluate ( function ( expected _length ) {
return $ ( '#zhome .message_row' ) . length === expected _length ;
} , msgs _qty + 2 ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
2013-06-13 16:56:50 +02:00
// 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
} ) ;
2018-11-13 17:16:02 +01:00
function check _compose _is _cleared ( ) {
common . check _form (
'#send_message_form' ,
{
stream _message _recipient _stream : '' ,
stream _message _recipient _topic : '' ,
} ,
"Stream empty on new compose"
) ;
}
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#compose' , function ( ) {
2016-10-07 19:04:59 +02:00
casper . test . assertVisible ( '#stream-message' , 'Stream input box visible' ) ;
2018-11-13 17:16:02 +01:00
check _compose _is _cleared ( ) ;
2016-09-08 14:10:41 +02:00
casper . click ( 'body' ) ;
2018-02-08 15:17:26 +01:00
casper . page . sendEvent ( 'keypress' , "x" ) ;
2016-09-08 14:10:41 +02:00
} ) ;
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 ( ) {
2018-03-06 15:07:55 +01:00
common . pm _recipient . expect ( "" ) ;
2016-09-08 14:10:41 +02:00
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 ( ) {
2016-10-07 19:04:59 +02:00
casper . waitUntilVisible ( '#stream-message' , function ( ) {
2018-11-13 17:16:02 +01:00
check _compose _is _cleared ( ) ;
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 ( ) {
2016-10-07 19:04:59 +02:00
casper . waitWhileVisible ( '#stream-message' , function ( ) {
2016-09-08 14:10:41 +02:00
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 ( ) {
2016-10-07 19:04:59 +02:00
casper . waitUntilVisible ( '#stream-message' , function ( ) {
2018-11-13 17:16:02 +01:00
common . check _form (
'#send_message_form' ,
{
stream _message _recipient _stream : "Verona" ,
stream _message _recipient _topic : "Reply test" ,
} ,
"Stream populated after reply by click"
) ;
2016-09-08 14:10:41 +02:00
// 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 ( ) {
2018-03-06 15:07:55 +01:00
common . pm _recipient . expect ( "cordelia@zulip.com" ) ;
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 ( ) {
2016-10-07 19:04:59 +02:00
casper . waitUntilVisible ( '#stream-message' , function ( ) {
2018-11-13 17:16:02 +01:00
common . check _form (
'#send_message_form' ,
{
stream _message _recipient _stream : "Verona" ,
stream _message _recipient _topic : "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 ( ) {
2016-10-07 19:04:59 +02:00
casper . waitWhileVisible ( '#stream-message' , function ( ) {
casper . test . assertNotVisible ( '#stream-message' , 'Close stream compose box' ) ;
2018-02-08 15:17:26 +01:00
casper . page . sendEvent ( 'keypress' , "x" ) ;
2016-09-08 14:10:41 +02:00
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"]' ) ;
} ) ;
2020-01-18 08:56:19 +01:00
casper . waitUntilVisible ( 'li[data-user-ids-string="8"].expanded_private_message.active-sub-filter' , function ( ) {
2013-07-15 23:44:59 +02:00
casper . page . sendEvent ( 'keypress' , 'c' ) ;
} ) ;
2016-09-08 14:10:41 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#compose' , function ( ) {
casper . test . assertEval ( function ( ) {
2018-11-13 17:16:02 +01:00
return document . activeElement === $ ( '.compose_table #stream_message_recipient_stream' ) [ 0 ] ;
2016-09-08 14:10:41 +02:00
} , '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 ( ',' ) ,
2018-12-18 19:34:45 +01:00
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 ( ) {
2018-03-06 15:07:55 +01:00
common . pm _recipient . expect ( recipients . join ( ',' ) ) ;
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"]' , {
2016-12-03 23:18:30 +01:00
content : '**Markdown Preview** >> Test for markdown preview' ,
2016-08-29 22:37:27 +02:00
} , false ) ;
casper . click ( "#markdown_preview" ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
2017-02-01 02:37:56 +01:00
casper . waitForSelectorTextChange ( "#preview_content" , 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
} ) ;