2017-02-09 09:42:27 +01:00
var common = require ( '../casper_lib/common.js' ) . common ;
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 ( ) {
casper . waitForText ( content1 ) ;
casper . waitForText ( content2 ) ;
} ) ;
// wait for message to be sent
casper . waitFor ( function ( ) {
return casper . evaluate ( function ( ) {
return current _msg _list . last ( ) . local _id === undefined ;
} ) ;
} ) ;
// 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-02-10 08:04:01 +01:00
casper . waitUntilVisible ( ".message_edit_content" , function ( ) {
2017-02-09 09:42:27 +01:00
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 ) ;
} ) ;
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 ) ;
} ) ;
} ) ;
// Commented out due to Issue #1243
// // edit the same message, but don't hit save this time
// casper.then(function () {
// casper.evaluate(function () {
// var msg = $('#zhome .message_row:last');
// msg.find('.info').click();
// $('.popover_edit_message').click();
// });
// });
2017-02-10 08:04:01 +01:00
// casper.waitUntilVisible(".message_edit_content", function () {
2017-02-09 09:42:27 +01:00
// casper.evaluate(function () {
// var msg = $('#zhome .message_row:last');
// msg.find('.message_edit_content').val("test RE-edited");
// });
// });
// go to admin page
casper . then ( function ( ) {
casper . click ( '#settings-dropdown' ) ;
2017-04-07 21:39:58 +02:00
casper . click ( 'a[href^="#organization"]' ) ;
2017-02-09 09:42:27 +01:00
} ) ;
// deactivate "allow message editing"
2017-02-10 08:04:01 +01:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
2017-02-09 09:42:27 +01:00
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
} ) ;
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
} ) ;
// Commented out due to Issue #1243
// // try to save the half-finished edit
2017-02-10 08:04:01 +01:00
// casper.waitUntilVisible('.message_table', function () {
2017-02-09 09:42:27 +01:00
// casper.then(function () {
// casper.evaluate(function () {
// var msg = $('#zhome .message_row:last');
// msg.find('.message_edit_save').click();
// });
// });
// });
// // make sure we get the right error message, and that the message hasn't actually changed
2017-02-10 08:04:01 +01:00
// casper.waitUntilVisible("div.edit_error", function () {
2017-02-09 09:42:27 +01:00
// casper.test.assertSelectorHasText(
// 'div.edit_error',
// 'Error saving edit: Your organization has turned off message editing.');
// casper.test.assertSelectorHasText(".last_message .message_content", "test edited");
// });
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
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"
casper . then ( function ( ) {
casper . click ( '#settings-dropdown' ) ;
2017-04-07 21:39:58 +02:00
casper . click ( 'a[href^="#organization"]' ) ;
2017-02-09 09:42:27 +01:00
} ) ;
2017-02-10 08:04:01 +01:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
2017-02-09 09:42:27 +01:00
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
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' ) ;
} ) ;
} ) ;
// Commented out due to Issue #1243
// go back home
// casper.then(function () {
2016-12-03 01:12:52 +01:00
// casper.click('.settings-header .exit');
2017-02-09 09:42:27 +01:00
// });
// // save our edit
2017-02-10 08:04:01 +01:00
// casper.waitUntilVisible('.message_table', function () {
2017-02-09 09:42:27 +01:00
// casper.then(function () {
// casper.evaluate(function () {
// var msg = $('#zhome .message_row:last');
// msg.find('.message_edit_save').click();
// });
// });
// });
// // check that edit went through
// casper.waitWhileVisible("textarea.message_edit_content", function () {
// casper.test.assertSelectorHasText(".last_message .message_content", "test RE-edited");
// });
// check that the edit link reappears in popover menu
// TODO check for edit icon next to message on hover
// casper.then(function () {
// casper.evaluate(function () {
// var msg = $('#zhome .message_row:last');
// msg.find('.info').click();
// });
// casper.test.assertExists('.popover_edit_message');
// casper.evaluate(function () {
// var msg = $('#zhome .message_row:last');
// msg.find('.info').click();
// });
// });
// 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-02-10 08:04:01 +01:00
casper . waitUntilVisible ( 'form.admin-realm-form input.button' ) ;
2017-02-09 09:42:27 +01:00
// deactivate message editing
2017-02-10 08:04:01 +01:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
2017-02-09 09:42:27 +01:00
casper . evaluate ( function ( ) {
$ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( '4' ) ;
} ) ;
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
} ) ;
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' ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
// allow message editing again, and check that the old edit limit is still there
2017-02-10 08:04:01 +01:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
2017-02-09 09:42:27 +01:00
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
} ) ;
} ) ;
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-02-10 08:04:01 +01:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , 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' ) ;
} ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
} ) ;
} ) ;
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-02-10 08:04:01 +01:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , 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' ) ;
} ) ;
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
} ) ;
} ) ;
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 ( ) ;
} ) ;