2015-11-04 18:21:17 +01:00
var common = require ( '../casper_lib/common.js' ) . common ;
common . start _and _log _in ( ) ;
2016-10-07 19:09:05 +02:00
casper . then ( function ( ) {
var menu _selector = '#settings-dropdown' ;
casper . waitUntilVisible ( menu _selector , function ( ) {
casper . click ( menu _selector ) ;
} ) ;
} ) ;
2015-11-04 18:21:17 +01:00
casper . then ( function ( ) {
casper . test . info ( 'Administration page' ) ;
casper . click ( 'a[href^="#administration"]' ) ;
2016-07-27 12:34:08 +02:00
} ) ;
casper . waitForSelector ( '#administration.tab-pane.active' , function ( ) {
casper . test . info ( 'Administration page is active' ) ;
2016-12-06 19:57:46 +01:00
casper . test . assertUrlMatch ( /^http:\/\/[^/]+\/#administration/ , 'URL suggests we are on administration page' ) ;
2015-11-04 18:21:17 +01:00
} ) ;
2016-05-12 10:28:00 +02:00
// Test only admins may create streams Setting
casper . waitForSelector ( 'input[type="checkbox"][id="id_realm_create_stream_by_admins_only"]' , function ( ) {
casper . click ( 'input[type="checkbox"][id="id_realm_create_stream_by_admins_only"]' ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-05-12 10:28:00 +02:00
2016-07-27 12:34:08 +02:00
} ) ;
casper . then ( function ( ) {
2016-05-12 10:28:00 +02:00
// Test setting was activated
casper . waitUntilVisible ( '#admin-realm-create-stream-by-admins-only-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-create-stream-by-admins-only-status' , 'Only Admins may now create new streams!' ) ;
casper . test . assertEval ( function ( ) {
return document . querySelector ( 'input[type="checkbox"][id="id_realm_create_stream_by_admins_only"]' ) . checked ;
} , 'Only admins may create streams Setting activated' ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
// Leave the page and return
2016-11-29 18:50:56 +01:00
casper . click ( '#settings-dropdown' ) ;
casper . click ( 'a[href^="#subscriptions"]' ) ;
casper . click ( '#settings-dropdown' ) ;
casper . click ( 'a[href^="#administration"]' ) ;
2016-07-27 12:34:08 +02:00
} ) ;
2016-05-12 10:28:00 +02:00
2016-07-27 12:34:08 +02:00
casper . waitForSelector ( 'input[type="checkbox"][id="id_realm_create_stream_by_admins_only"]' , function ( ) {
// Test Setting was saved
casper . test . assertEval ( function ( ) {
return document . querySelector ( 'input[type="checkbox"][id="id_realm_create_stream_by_admins_only"]' ) . checked ;
} , 'Only admins may create streams Setting saved' ) ;
2016-05-12 10:28:00 +02:00
2016-07-27 12:34:08 +02:00
// Deactivate setting
casper . click ( 'input[type="checkbox"][id="id_realm_create_stream_by_admins_only"]' ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-07-27 12:34:08 +02:00
} ) ;
casper . then ( function ( ) {
casper . waitUntilVisible ( '#admin-realm-create-stream-by-admins-only-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-create-stream-by-admins-only-status' , 'Any user may now create new streams!' ) ;
casper . test . assertEval ( function ( ) {
return ! ( document . querySelector ( 'input[type="checkbox"][id="id_realm_create_stream_by_admins_only"]' ) . checked ) ;
} , 'Only admins may create streams Setting deactivated' ) ;
2016-05-12 10:28:00 +02:00
} ) ;
} ) ;
2015-11-04 18:21:17 +01:00
// Test user deactivation and reactivation
casper . waitForSelector ( '.user_row[id="user_cordelia@zulip.com"]' , function ( ) {
casper . test . assertSelectorHasText ( '.user_row[id="user_cordelia@zulip.com"]' , 'Deactivate' ) ;
casper . click ( '.user_row[id="user_cordelia@zulip.com"] .deactivate' ) ;
2016-11-29 18:50:56 +01:00
casper . test . assertTextExists ( 'Deactivate cordelia@zulip.com' , 'Deactivate modal has right user' ) ;
casper . test . assertTextExists ( 'Deactivate now' , 'Deactivate now button available' ) ;
casper . click ( '#do_deactivate_user_button' ) ;
2015-11-04 18:21:17 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
casper . waitForSelector ( '.user_row[id="user_cordelia@zulip.com"].deactivated_user' , function ( ) {
casper . test . assertSelectorHasText ( '.user_row[id="user_cordelia@zulip.com"]' , 'Reactivate' ) ;
casper . click ( '.user_row[id="user_cordelia@zulip.com"] .reactivate' ) ;
} ) ;
2015-11-04 18:21:17 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
casper . waitForSelector ( '.user_row[id="user_cordelia@zulip.com"]:not(.deactivated_user)' , function ( ) {
casper . test . assertSelectorHasText ( '.user_row[id="user_cordelia@zulip.com"]' , 'Deactivate' ) ;
} ) ;
2015-11-04 18:21:17 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
// Test Deactivated users section of admin page
casper . waitForSelector ( '.user_row[id="user_cordelia@zulip.com"]' , function ( ) {
casper . test . assertSelectorHasText ( '.user_row[id="user_cordelia@zulip.com"]' , 'Deactivate' ) ;
casper . click ( '.user_row[id="user_cordelia@zulip.com"] .deactivate' ) ;
casper . test . assertTextExists ( 'Deactivate cordelia@zulip.com' , 'Deactivate modal has right user' ) ;
casper . test . assertTextExists ( 'Deactivate now' , 'Deactivate now button available' ) ;
casper . click ( '#do_deactivate_user_button' ) ;
} ) ;
2015-11-04 18:21:17 +01:00
} ) ;
casper . then ( function ( ) {
// Leave the page and return
2016-11-29 18:50:56 +01:00
casper . click ( '#settings-dropdown' ) ;
2016-11-01 22:32:10 +01:00
casper . click ( 'a[href^="#"]' ) ;
2016-11-29 18:50:56 +01:00
casper . click ( '#settings-dropdown' ) ;
casper . click ( 'a[href^="#administration"]' ) ;
2017-01-15 20:27:45 +01:00
casper . test . assertSelectorHasText ( "#administration a[aria-controls='deactivated-users']" , "Deactivated users" ) ;
2016-11-29 18:50:56 +01:00
casper . click ( "#administration a[aria-controls='deactivated-users']" ) ;
Fix flaky casper test in admin page.
When you deactivate a user, visit another page, and then
come back, the user shows up in another table (the
"Deactivated Users" table), and no longer has the
strikeout styling of a recently deactivated user.
Using the strikeout class as a selector to test if the
user has been reactivated will of course not be a good
test, and if you have a slow machine, lose a
race condition.
When you deactivate a user, visit another page,
and then come back, the user shows up in another
table, and no longer has the strikeout styling
of a recently deactivated user. Using strikeout
class to test if the user has been reactivated
will of course not be a good test, and if you
have a slow machine, lose a race condition.
2016-06-05 03:02:30 +02:00
casper . waitForSelector ( '#admin_deactivated_users_table .user_row[id="user_cordelia@zulip.com"] .reactivate' , function ( ) {
2015-11-04 18:21:17 +01:00
casper . test . assertSelectorHasText ( '#admin_deactivated_users_table .user_row[id="user_cordelia@zulip.com"]' , 'Reactivate' ) ;
casper . click ( '#admin_deactivated_users_table .user_row[id="user_cordelia@zulip.com"] .reactivate' ) ;
} ) ;
2016-07-27 12:34:08 +02:00
} ) ;
2015-11-04 18:21:17 +01:00
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
Fix flaky casper test in admin page.
When you deactivate a user, visit another page, and then
come back, the user shows up in another table (the
"Deactivated Users" table), and no longer has the
strikeout styling of a recently deactivated user.
Using the strikeout class as a selector to test if the
user has been reactivated will of course not be a good
test, and if you have a slow machine, lose a
race condition.
When you deactivate a user, visit another page,
and then come back, the user shows up in another
table, and no longer has the strikeout styling
of a recently deactivated user. Using strikeout
class to test if the user has been reactivated
will of course not be a good test, and if you
have a slow machine, lose a race condition.
2016-06-05 03:02:30 +02:00
casper . waitForSelector ( '#admin_deactivated_users_table .user_row[id="user_cordelia@zulip.com"] button:not(.reactivate)' , function ( ) {
2015-11-04 18:21:17 +01:00
casper . test . assertSelectorHasText ( '#admin_deactivated_users_table .user_row[id="user_cordelia@zulip.com"]' , 'Deactivate' ) ;
} ) ;
2016-11-29 18:50:56 +01:00
casper . test . assertSelectorHasText ( "#administration a[aria-controls='organization']" , "Organization" ) ;
casper . click ( "#administration a[aria-controls='organization']" ) ;
2015-11-04 18:21:17 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
// Test bot deactivation and reactivation
casper . waitForSelector ( '.user_row[id="user_new-user-bot@zulip.com"]' , function ( ) {
casper . test . assertSelectorHasText ( '.user_row[id="user_new-user-bot@zulip.com"]' , 'Deactivate' ) ;
casper . click ( '.user_row[id="user_new-user-bot@zulip.com"] .deactivate' ) ;
} ) ;
2015-11-04 18:21:17 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
casper . waitForSelector ( '.user_row[id="user_new-user-bot@zulip.com"].deactivated_user' , function ( ) {
casper . test . assertSelectorHasText ( '.user_row[id="user_new-user-bot@zulip.com"]' , 'Reactivate' ) ;
casper . click ( '.user_row[id="user_new-user-bot@zulip.com"] .reactivate' ) ;
} ) ;
2015-11-04 18:21:17 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
casper . waitForSelector ( '.user_row[id="user_new-user-bot@zulip.com"]:not(.deactivated_user)' , function ( ) {
casper . test . assertSelectorHasText ( '.user_row[id="user_new-user-bot@zulip.com"]' , 'Deactivate' ) ;
} ) ;
2015-11-04 18:21:17 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
// Test custom realm emoji
casper . waitForSelector ( '.admin-emoji-form' , function ( ) {
casper . fill ( 'form.admin-emoji-form' , {
2016-12-03 03:08:47 +01:00
name : 'MouseFace' ,
2017-01-12 00:17:43 +01:00
url : 'http://zulipdev.com:9991/static/images/integrations/logos/jenkins.png' ,
2016-07-27 12:34:08 +02:00
} ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-emoji-form input.button' ) ;
2016-02-12 21:08:56 +01:00
} ) ;
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
casper . waitUntilVisible ( 'div#admin-emoji-status' , function ( ) {
casper . test . assertSelectorHasText ( 'div#admin-emoji-status' , 'Custom emoji added!' ) ;
} ) ;
2016-02-12 21:08:56 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
casper . waitForSelector ( '.emoji_row' , function ( ) {
casper . test . assertSelectorHasText ( '.emoji_row .emoji_name' , 'MouseFace' ) ;
2016-10-07 00:19:19 +02:00
casper . test . assertExists ( '.emoji_row img[src="http://zulipdev.com:9991/static/images/integrations/logos/jenkins.png"]' ) ;
2016-07-27 12:34:08 +02:00
casper . click ( '.emoji_row button.delete' ) ;
} ) ;
2016-02-12 21:08:56 +01:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
casper . waitWhileSelector ( '.emoji_row' , function ( ) {
casper . test . assertDoesntExist ( '.emoji_row' ) ;
} ) ;
2016-02-12 21:08:56 +01:00
} ) ;
2016-02-13 19:17:15 +01:00
// Test custom realm filters
casper . waitForSelector ( '.admin-filter-form' , function ( ) {
casper . fill ( 'form.admin-filter-form' , {
2016-12-03 03:08:47 +01:00
pattern : '#(?P<id>[0-9]+)' ,
2017-01-12 00:17:43 +01:00
url _format _string : 'https://trac.example.com/ticket/%(id)s' ,
2016-02-13 19:17:15 +01:00
} ) ;
casper . click ( 'form.admin-filter-form input.btn' ) ;
} ) ;
casper . waitUntilVisible ( 'div#admin-filter-status' , function ( ) {
casper . test . assertSelectorHasText ( 'div#admin-filter-status' , 'Custom filter added!' ) ;
} ) ;
casper . waitForSelector ( '.filter_row' , function ( ) {
casper . test . assertSelectorHasText ( '.filter_row span.filter_pattern' , '#(?P<id>[0-9]+)' ) ;
casper . test . assertSelectorHasText ( '.filter_row span.filter_url_format_string' , 'https://trac.example.com/ticket/%(id)s' ) ;
casper . click ( '.filter_row button' ) ;
} ) ;
casper . waitWhileSelector ( '.filter_row' , function ( ) {
casper . test . assertDoesntExist ( '.filter_row' ) ;
} ) ;
casper . waitForSelector ( '.admin-filter-form' , function ( ) {
casper . fill ( 'form.admin-filter-form' , {
2016-12-03 03:08:47 +01:00
pattern : 'a$' ,
2017-01-12 00:17:43 +01:00
url _format _string : 'https://trac.example.com/ticket/%(id)s' ,
2016-02-13 19:17:15 +01:00
} ) ;
casper . click ( 'form.admin-filter-form input.btn' ) ;
} ) ;
casper . waitUntilVisible ( 'div#admin-filter-pattern-status' , function ( ) {
2016-12-14 23:55:32 +01:00
casper . test . assertSelectorHasText ( 'div#admin-filter-pattern-status' , 'Failed: Invalid filter pattern, you must use the following format OPTIONAL_PREFIX(?P<id>.+)' ) ;
2016-02-13 19:17:15 +01:00
} ) ;
2017-02-09 09:13:30 +01:00
var stream _name = "Scotland" ;
2016-05-20 22:08:42 +02:00
function get _suggestions ( str ) {
casper . then ( function ( ) {
casper . evaluate ( function ( str ) {
$ ( '.create_default_stream' )
. focus ( )
. val ( str )
. trigger ( $ . Event ( 'keyup' , { which : 0 } ) ) ;
} , str ) ;
} ) ;
}
function select _from _suggestions ( item ) {
casper . then ( function ( ) {
casper . evaluate ( function ( item ) {
var tah = $ ( '.create_default_stream' ) . data ( ) . typeahead ;
tah . mouseenter ( {
2017-01-12 00:17:43 +01:00
currentTarget : $ ( '.typeahead:visible li:contains("' + item + '")' ) [ 0 ] ,
2016-05-20 22:08:42 +02:00
} ) ;
tah . select ( ) ;
} , { item : item } ) ;
} ) ;
}
// Test default stream creation and addition
casper . then ( function ( ) {
casper . click ( '#settings-dropdown' ) ;
casper . click ( 'a[href^="#subscriptions"]' ) ;
casper . click ( '#settings-dropdown' ) ;
casper . click ( 'a[href^="#administration"]' ) ;
2017-02-09 09:13:30 +01:00
casper . waitUntilVisible ( ".create_default_stream" , function ( ) {
// It matches with all the stream names which has 'O' as a substring (Rome, Scotland, Verona
// etc). 'O' is used to make sure that it works even if there are multiple suggestions.
// Uppercase 'O' is used instead of the lowercase version to make sure that the suggestions
// are case insensitive.
get _suggestions ( "O" ) ;
select _from _suggestions ( stream _name ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
2016-05-20 22:08:42 +02:00
casper . waitForSelector ( '.default_stream_row[id=' + stream _name + ']' , function ( ) {
casper . test . assertSelectorHasText ( '.default_stream_row[id=' + stream _name + '] .default_stream_name' , stream _name ) ;
} ) ;
2016-07-27 12:34:08 +02:00
} ) ;
casper . then ( function ( ) {
2016-05-20 22:08:42 +02:00
casper . waitForSelector ( '.default_stream_row[id=' + stream _name + ']' , function ( ) {
casper . test . assertSelectorHasText ( '.default_stream_row[id=' + stream _name + '] .default_stream_name' , stream _name ) ;
casper . click ( '.default_stream_row[id=' + stream _name + '] button.remove-default-stream' ) ;
} ) ;
2016-07-27 12:34:08 +02:00
} ) ;
casper . then ( function ( ) {
2016-05-20 22:08:42 +02:00
casper . waitWhileSelector ( '.default_stream_row[id=' + stream _name + ']' , function ( ) {
casper . test . assertDoesntExist ( '.default_stream_row[id=' + stream _name + ']' ) ;
} ) ;
} ) ;
2016-07-27 12:34:08 +02:00
2015-11-04 18:21:17 +01:00
// TODO: Test stream deletion
2016-06-21 21:34:41 +02:00
// Test turning message editing off and on
// go to home page
casper . then ( function ( ) {
casper . click ( '.global-filter[data-name="home"]' ) ;
} ) ;
2016-10-07 19:09:05 +02:00
// 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' ;
2016-06-21 21:34:41 +02:00
// send two messages
common . then _send _message ( 'stream' , {
stream : 'Verona' ,
subject : 'edits' ,
2017-01-12 00:17:43 +01:00
content : content1 ,
2016-06-21 21:34:41 +02:00
} ) ;
common . then _send _message ( 'stream' , {
stream : 'Verona' ,
subject : 'edits' ,
2017-01-12 00:17:43 +01:00
content : content2 ,
2016-06-21 21:34:41 +02:00
} ) ;
2016-09-30 13:08:39 +02:00
casper . then ( function ( ) {
2016-10-07 19:09:05 +02:00
casper . waitForText ( content1 ) ;
casper . waitForText ( content2 ) ;
2016-09-30 13:08:39 +02:00
} ) ;
2016-06-21 21:34:41 +02:00
// 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 ( ) ;
} ) ;
} ) ;
2016-07-27 12:34:08 +02:00
2016-10-07 19:09:05 +02:00
var edited _value = 'admin tests: test edit' ;
2016-06-21 21:34:41 +02:00
casper . waitForSelector ( ".message_edit_content" , function ( ) {
2016-10-07 19:09:05 +02:00
casper . evaluate ( function ( edited _value ) {
2016-06-21 21:34:41 +02:00
var msg = $ ( '#zhome .message_row:last' ) ;
2016-10-07 19:09:05 +02:00
msg . find ( '.message_edit_content' ) . val ( edited _value ) ;
2016-06-21 21:34:41 +02:00
msg . find ( '.message_edit_save' ) . click ( ) ;
2016-10-07 19:09:05 +02:00
} , edited _value ) ;
2016-06-21 21:34:41 +02:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
// check that the message was indeed edited
casper . waitWhileVisible ( "textarea.message_edit_content" , function ( ) {
2016-10-07 19:09:05 +02:00
casper . test . assertSelectorHasText ( ".last_message .message_content" , edited _value ) ;
2016-07-27 12:34:08 +02:00
} ) ;
2016-06-21 21:34:41 +02:00
} ) ;
2016-07-13 21:06:31 +02:00
// 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();
// });
// });
// casper.waitForSelector(".message_edit_content", function () {
// casper.evaluate(function () {
// var msg = $('#zhome .message_row:last');
// msg.find('.message_edit_content').val("test RE-edited");
// });
// });
2016-06-21 21:34:41 +02:00
// go to admin page
casper . then ( function ( ) {
casper . click ( '#settings-dropdown' ) ;
casper . click ( 'a[href^="#administration"]' ) ;
} ) ;
// deactivate "allow message editing"
casper . waitForSelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-07-27 12:34:08 +02:00
} ) ;
casper . then ( function ( ) {
2016-06-21 21:34:41 +02:00
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 ( ) {
casper . click ( '.global-filter[data-name="home"]' ) ;
} ) ;
2016-07-13 21:06:31 +02:00
// Commented out due to Issue #1243
// // try to save the half-finished edit
// casper.waitForSelector('.message_table', function () {
// casper.then(function () {
// casper.evaluate(function () {
// var msg = $('#zhome .message_row:last');
// msg.find('.message_edit_save').click();
// });
// });
// });
2016-06-21 21:34:41 +02:00
2016-07-13 21:06:31 +02:00
// // make sure we get the right error message, and that the message hasn't actually changed
// casper.waitForSelector("div.edit_error", function () {
2016-12-02 15:16:33 +01:00
// casper.test.assertSelectorHasText(
// 'div.edit_error',
// 'Error saving edit: Your organization has turned off message editing.');
2016-07-13 21:06:31 +02:00
// casper.test.assertSelectorHasText(".last_message .message_content", "test edited");
// });
2016-06-21 21:34:41 +02:00
2016-10-22 02:38:56 +02:00
// Check that edit link has changed to "View Source" in the popover menu
2016-06-21 21:34:41 +02:00
// TODO: also check that the edit icon no longer appears next to the message
casper . then ( function ( ) {
2016-07-13 21:06:31 +02:00
casper . waitForSelector ( '.message_row' ) ;
// Note that this could have a false positive, e.g. if all the messages aren't
// loaded yet. See Issue #1243
2016-06-21 21:34:41 +02:00
casper . evaluate ( function ( ) {
var msg = $ ( '#zhome .message_row:last' ) ;
msg . find ( '.info' ) . click ( ) ;
} ) ;
2016-10-22 02:38:56 +02:00
casper . waitUntilVisible ( '.popover_edit_message' , function ( ) {
casper . test . assertSelectorHasText ( '.popover_edit_message' , 'View Source' ) ;
} ) ;
2016-06-21 21:34:41 +02: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' ) ;
casper . click ( 'a[href^="#administration"]' ) ;
} ) ;
casper . waitForSelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-06-21 21:34:41 +02:00
casper . waitUntilVisible ( '#admin-realm-message-editing-status' , function ( ) {
2016-07-08 02:25:55 +02:00
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.' ) ;
2016-06-21 21:34:41 +02:00
casper . test . assertEval ( function ( ) {
return document . querySelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) . checked ;
} , 'Allow message editing Setting re-activated' ) ;
} ) ;
} ) ;
2016-07-13 21:06:31 +02:00
// Commented out due to Issue #1243
2016-07-13 21:06:31 +02:00
// go back home
// casper.then(function () {
// casper.click('.global-filter[data-name="home"]');
// });
2016-07-13 21:06:31 +02:00
// // save our edit
// casper.waitForSelector('.message_table', function () {
// 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");
// });
2016-06-21 21:34:41 +02:00
// check that the edit link reappears in popover menu
// TODO check for edit icon next to message on hover
2016-07-13 21:06:31 +02:00
// 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();
// });
// });
2016-06-21 21:34:41 +02:00
2016-07-13 21:06:31 +02:00
// go to admin page
2016-07-08 02:25:55 +02:00
casper . then ( function ( ) {
casper . test . info ( 'Administration page' ) ;
casper . click ( 'a[href^="#administration"]' ) ;
2016-12-06 19:57:46 +01:00
casper . test . assertUrlMatch ( /^http:\/\/[^/]+\/#administration/ , 'URL suggests we are on administration page' ) ;
2016-07-08 02:25:55 +02:00
casper . test . assertExists ( '#administration.tab-pane.active' , 'Administration page is active' ) ;
} ) ;
2016-09-14 02:20:13 +02:00
casper . waitForSelector ( 'form.admin-realm-form input.button' ) ;
2016-07-27 12:34:08 +02:00
// deactivate message editing
casper . waitForSelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
casper . evaluate ( function ( ) {
$ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( '4' ) ;
2016-07-08 02:25:55 +02:00
} ) ;
2016-07-27 12:34:08 +02:00
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-07-27 12:34:08 +02:00
} ) ;
2016-07-08 02:25:55 +02:00
2016-07-27 12:34:08 +02: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' ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
2016-07-08 02:25:55 +02:00
// allow message editing again, and check that the old edit limit is still there
casper . waitForSelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
casper . click ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-07-08 02:25:55 +02:00
} ) ;
2016-07-27 12:34:08 +02: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' ) ;
} ) ;
} ) ;
2016-07-08 02:25:55 +02:00
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
2016-07-08 02:25:55 +02:00
// allow arbitrary message editing
casper . waitForSelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
casper . evaluate ( function ( ) {
$ ( 'input[type="text"][id="id_realm_message_content_edit_limit_minutes"]' ) . val ( '0' ) ;
} ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-07-08 02:25:55 +02:00
} ) ;
2016-07-27 12:34:08 +02:00
} ) ;
2016-07-08 02:25:55 +02:00
2016-07-27 12:34:08 +02: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 ( ) {
2016-07-08 02:25:55 +02:00
// disallow message editing, with illegal edit limit value. should be fixed by admin.js
casper . waitForSelector ( 'input[type="checkbox"][id="id_realm_allow_message_editing"]' , function ( ) {
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"]' ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-07-08 02:25:55 +02:00
} ) ;
} ) ;
2016-07-27 12:34:08 +02: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' ) ;
} ) ;
} ) ;
2016-07-08 02:25:55 +02:00
2016-08-04 17:32:41 +02:00
casper . then ( function ( ) {
casper . test . info ( "Changing realm default language" ) ;
casper . evaluate ( function ( ) {
$ ( '#id_realm_default_language' ) . val ( 'de' ) . change ( ) ;
} ) ;
2016-09-14 02:20:13 +02:00
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-08-04 17:32:41 +02:00
} ) ;
casper . waitUntilVisible ( '#admin-realm-default-language-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-default-language-status' , 'Default language changed!' ) ;
} ) ;
2016-11-02 21:51:56 +01:00
// Test authentication methods setting
casper . waitForSelector ( 'input[type="checkbox"]' , function ( ) {
casper . click ( ".method_row[data-method='Email'] input[type='checkbox']" ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
} ) ;
// Test setting was activated--default is checked
casper . then ( function ( ) {
// Scroll to bottom so that casper snapshots show the auth methods table
this . scrollToBottom ( ) ;
// Test setting was activated
casper . waitUntilVisible ( '#admin-realm-authentication-methods-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-authentication-methods-status' , 'Authentication methods saved!' ) ;
casper . test . assertEval ( function ( ) {
return ! ( document . querySelector ( ".method_row[data-method='Email'] input[type='checkbox']" ) . checked ) ;
} ) ;
} ) ;
} ) ;
casper . then ( function ( ) {
// Leave the page and return
casper . click ( '#settings-dropdown' ) ;
casper . click ( 'a[href^="#subscriptions"]' ) ;
casper . click ( '#settings-dropdown' ) ;
casper . click ( 'a[href^="#administration"]' ) ;
casper . waitForSelector ( ".method_row[data-method='Email'] input[type='checkbox']" , function ( ) {
// Test Setting was saved
casper . test . assertEval ( function ( ) {
return ! ( document . querySelector ( ".method_row[data-method='Email'] input[type='checkbox']" ) . checked ) ;
} ) ;
} ) ;
} ) ;
// Deactivate setting--default is checked
casper . then ( function ( ) {
casper . click ( ".method_row[data-method='Email'] input[type='checkbox']" ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
casper . waitUntilVisible ( '#admin-realm-authentication-methods-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-authentication-methods-status' , 'Authentication methods saved!' ) ;
casper . test . assertEval ( function ( ) {
return document . querySelector ( ".method_row[data-method='Email'] input[type='checkbox']" ) . checked ;
} ) ;
} ) ;
} ) ;
2015-11-04 18:21:17 +01:00
common . then _log _out ( ) ;
casper . run ( function ( ) {
casper . test . done ( ) ;
} ) ;