2017-02-09 09:42:27 +01:00
var common = require ( '../casper_lib/common.js' ) . common ;
2017-12-27 23:12:52 +01:00
function submit _checked ( ) {
casper . then ( function ( ) {
casper . waitUntilVisible ( 'input:checked[type="checkbox"][id="id_realm_allow_message_editing"] + span' , function ( ) {
casper . click ( 'form.org-settings-form button.button' ) ;
} ) ;
} ) ;
}
function submit _unchecked ( ) {
casper . then ( function ( ) {
casper . waitUntilVisible ( 'input:not(:checked)[type="checkbox"][id="id_realm_allow_message_editing"] + span' , function ( ) {
casper . click ( 'form.org-settings-form button.button' ) ;
} ) ;
} ) ;
}
2017-02-09 09:42:27 +01:00
common . start _and _log _in ( ) ;
// For clarity these should be different than what 08-edit uses, until
// we find a more robust way to manage DB state between tests.
var content1 = 'admin: edit test message 1' ;
var content2 = 'admin: edit test message 2' ;
// send two messages
common . then _send _message ( 'stream' , {
stream : 'Verona' ,
subject : 'edits' ,
content : content1 ,
} ) ;
common . then _send _message ( 'stream' , {
stream : 'Verona' ,
subject : 'edits' ,
content : content2 ,
} ) ;
casper . then ( function ( ) {
2017-06-07 10:25:06 +02:00
casper . waitForSelectorText ( '#zhome .message_row' , content1 ) ;
casper . waitForSelectorText ( '#zhome .message_row' , content2 ) ;
2017-02-09 09:42:27 +01:00
} ) ;
// wait for message to be sent
2017-11-21 00:54:47 +01:00
casper . then ( function ( ) {
casper . waitFor ( function ( ) {
return casper . evaluate ( function ( ) {
return ! current _msg _list . last ( ) . locally _echoed ;
} ) ;
2017-02-09 09:42:27 +01:00
} ) ;
} ) ;
// edit the last message just sent
casper . then ( function ( ) {
casper . evaluate ( function ( ) {
var msg = $ ( '#zhome .message_row:last' ) ;
msg . find ( '.info' ) . click ( ) ;
$ ( '.popover_edit_message' ) . click ( ) ;
} ) ;
} ) ;
var edited _value = 'admin tests: test edit' ;
2017-11-21 00:54:47 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( ".message_edit_content" , function ( ) {
casper . evaluate ( function ( edited _value ) {
var msg = $ ( '#zhome .message_row:last' ) ;
msg . find ( '.message_edit_content' ) . val ( edited _value ) ;
msg . find ( '.message_edit_save' ) . click ( ) ;
} , edited _value ) ;
} ) ;
2017-02-09 09:42:27 +01:00
} ) ;
casper . then ( function ( ) {
// check that the message was indeed edited
casper . waitWhileVisible ( "textarea.message_edit_content" , function ( ) {
casper . test . assertSelectorHasText ( ".last_message .message_content" , edited _value ) ;
} ) ;
} ) ;
// go to admin page
2017-12-28 00:08:58 +01:00
common . then _click ( '#settings-dropdown' ) ;
common . then _click ( 'a[href^="#organization"]' ) ;
2017-02-09 09:42:27 +01:00
2017-11-21 00:54:47 +01:00
casper . then ( function ( ) {
casper . waitForSelector ( '#settings_overlay_container.show' , function ( ) {
casper . test . info ( 'Organization page is active' ) ;
casper . test . assertUrlMatch ( /^http:\/\/[^/]+\/#organization/ , 'URL suggests we are on organization page' ) ;
} ) ;
2017-05-18 14:06:57 +02:00
} ) ;
2017-12-28 00:08:58 +01:00
common . then _click ( "li[data-section='organization-settings']" ) ;
// deactivate "allow message editing"
common . then _click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"] + span' ) ;
2017-02-09 09:42:27 +01:00
2017-12-27 23:12:52 +01:00
submit _unchecked ( ) ;
2017-02-09 09:42:27 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#admin-realm-message-editing-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-message-editing-status' , 'Users can no longer edit their past messages!' ) ;
casper . test . assertEval ( function ( ) {
return ! ( document . querySelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) . checked ) ;
} , 'Allow message editing Setting de-activated' ) ;
} ) ;
} ) ;
// go back to home page
casper . then ( function ( ) {
2016-12-03 01:12:52 +01:00
casper . click ( '.settings-header .exit' ) ;
2017-02-09 09:42:27 +01:00
} ) ;
2017-03-08 13:57:42 +01:00
// Check that edit link has changed to "View source" in the popover menu
2017-02-09 09:42:27 +01:00
// TODO: also check that the edit icon no longer appears next to the message
2017-11-23 07:06:19 +01:00
casper . then ( function ( ) {
// This somehow makes the "View source" test deterministic. It seems that
// we are waiting on a wrong condition somewhere.
casper . wait ( 1000 ) ;
} ) ;
2017-02-09 09:42:27 +01:00
casper . then ( function ( ) {
2017-02-10 08:04:01 +01:00
casper . waitUntilVisible ( '.message_row' ) ;
2017-02-09 09:42:27 +01:00
// Note that this could have a false positive, e.g. if all the messages aren't
// loaded yet. See Issue #1243
casper . evaluate ( function ( ) {
var msg = $ ( '#zhome .message_row:last' ) ;
msg . find ( '.info' ) . click ( ) ;
} ) ;
casper . waitUntilVisible ( '.popover_edit_message' , function ( ) {
2017-03-08 13:57:42 +01:00
casper . test . assertSelectorHasText ( '.popover_edit_message' , 'View source' ) ;
2017-02-09 09:42:27 +01:00
} ) ;
casper . evaluate ( function ( ) {
var msg = $ ( '#zhome .message_row:last' ) ;
msg . find ( '.info' ) . click ( ) ;
} ) ;
} ) ;
// go back to admin page, and reactivate "allow message editing"
2017-12-28 00:08:58 +01:00
common . then _click ( '#settings-dropdown' ) ;
common . then _click ( 'a[href^="#organization"]' ) ;
common . then _click ( "li[data-section='organization-settings']" ) ;
common . then _click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"] + span' ) ;
2017-12-27 23:12:52 +01:00
submit _checked ( ) ;
2017-11-21 01:18:02 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#admin-realm-message-editing-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-message-editing-status' , 'Users can now edit topics for all their messages, and the content of messages which are less than 10 minutes old.' ) ;
casper . test . assertEval ( function ( ) {
return document . querySelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) . checked ;
} , 'Allow message editing Setting re-activated' ) ;
2017-02-09 09:42:27 +01:00
} ) ;
} ) ;
// go to admin page
casper . then ( function ( ) {
2017-04-07 21:39:58 +02:00
casper . test . info ( 'Organization page' ) ;
casper . click ( 'a[href^="#organization"]' ) ;
casper . test . assertUrlMatch ( /^http:\/\/[^\/]+\/#organization/ , 'URL suggests we are on organization page' ) ;
casper . test . assertExists ( '#settings_overlay_container.show' , 'Organization page is active' ) ;
2017-02-09 09:42:27 +01:00
} ) ;
2017-11-21 00:54:47 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( 'form.admin-realm-form button.button' ) ;
} ) ;
2017-02-09 09:42:27 +01:00
// deactivate message editing
2017-11-21 00:54:47 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"] + span' , function ( ) {
casper . evaluate ( function ( ) {
$ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( '4' ) ;
} ) ;
2017-02-09 09:42:27 +01:00
} ) ;
} ) ;
2017-12-28 00:08:58 +01:00
common . then _click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"] + span' ) ;
2017-12-27 23:12:52 +01:00
submit _unchecked ( ) ;
2017-02-09 09:42:27 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#admin-realm-message-editing-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-message-editing-status' , 'Users can no longer edit their past messages!' ) ;
casper . test . assertEval ( function ( ) {
return ! ( document . querySelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) . checked ) ;
} , 'Allow message editing Setting de-activated' ) ;
casper . test . assertEval ( function ( ) {
return $ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( ) === '4' ;
} , 'Message content edit limit now 4' ) ;
} ) ;
} ) ;
2017-12-28 00:08:58 +01:00
common . then _click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"] + span' ) ;
2017-12-27 23:25:14 +01:00
submit _checked ( ) ;
2017-02-09 09:42:27 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#admin-realm-message-editing-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-message-editing-status' , 'Users can now edit topics for all their messages, and the content of messages which are less than 4 minutes old.' ) ;
casper . test . assertEval ( function ( ) {
return document . querySelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) . checked ;
} , 'Allow message editing Setting activated' ) ;
casper . test . assertEval ( function ( ) {
return $ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( ) === '4' ;
} , 'Message content edit limit still 4' ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
// allow arbitrary message editing
2017-04-21 01:10:59 +02:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"] + span' , function ( ) {
2017-02-09 09:42:27 +01:00
casper . evaluate ( function ( ) {
$ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( '0' ) ;
} ) ;
2017-08-18 01:23:55 +02:00
casper . click ( 'form.org-settings-form button.button' ) ;
2017-02-09 09:42:27 +01:00
} ) ;
} ) ;
casper . then ( function ( ) {
casper . waitUntilVisible ( '#admin-realm-message-editing-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-message-editing-status' , 'Users can now edit the content and topics of all their past messages!' ) ;
casper . test . assertEval ( function ( ) {
return document . querySelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) . checked ;
} , 'Allow message editing Setting still activated' ) ;
casper . test . assertEval ( function ( ) {
return $ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( ) === '0' ;
} , 'Message content edit limit is 0' ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
// disallow message editing, with illegal edit limit value. should be fixed by admin.js
2017-04-21 01:10:59 +02:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"] + span' , function ( ) {
2017-02-09 09:42:27 +01:00
casper . evaluate ( function ( ) {
$ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( 'moo' ) ;
} ) ;
2017-04-21 01:10:59 +02:00
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"] + span' ) ;
2017-08-18 01:23:55 +02:00
casper . click ( 'form.org-settings-form button.button' ) ;
2017-02-09 09:42:27 +01:00
} ) ;
} ) ;
casper . then ( function ( ) {
casper . waitUntilVisible ( '#admin-realm-message-editing-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-message-editing-status' , 'Users can no longer edit their past messages!' ) ;
casper . test . assertEval ( function ( ) {
return ! ( document . querySelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) . checked ) ;
} , 'Allow message editing Setting de-activated' ) ;
casper . test . assertEval ( function ( ) {
return $ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( ) === '10' ;
} , 'Message content edit limit has been reset to its default' ) ;
} ) ;
} ) ;
common . then _log _out ( ) ;
casper . run ( function ( ) {
casper . test . done ( ) ;
} ) ;