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
} ) ;
2016-12-03 01:12:52 +01:00
casper . waitForSelector ( '#settings_overlay_container.show' , function ( ) {
2016-07-27 12:34:08 +02:00
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-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-12-03 01:12:52 +01:00
casper . waitUntilVisible ( 'input[type="checkbox"][id="id_realm_create_stream_by_admins_only"]' , function ( ) {
2016-07-27 12:34:08 +02:00
// 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
} ) ;
} ) ;
2016-12-03 01:12:52 +01:00
2016-07-27 12:34:08 +02:00
casper . then ( function ( ) {
// Test custom realm emoji
2016-12-03 01:12:52 +01:00
casper . click ( "li[data-section='emoji-settings']" ) ;
2016-12-03 01:12:52 +01:00
casper . waitUntilVisible ( '.admin-emoji-form' , function ( ) {
2016-07-27 12:34:08 +02:00
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-12-03 01:12:52 +01:00
} , true ) ;
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 ( ) {
2016-12-03 01:12:52 +01:00
casper . waitUntilVisible ( '.emoji_row' , function ( ) {
2016-07-27 12:34:08 +02:00
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 ( ) {
2016-12-03 01:12:52 +01:00
casper . waitWhileVisible ( '.emoji_row' , function ( ) {
2016-07-27 12:34:08 +02:00
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
2017-02-09 09:01:38 +01:00
casper . then ( function ( ) {
2016-12-03 01:12:52 +01:00
casper . click ( "li[data-section='filter-settings']" ) ;
2016-12-03 01:12:52 +01:00
casper . waitUntilVisible ( '.admin-filter-form' , function ( ) {
2017-02-09 09:01:38 +01:00
casper . fill ( 'form.admin-filter-form' , {
pattern : '#(?P<id>[0-9]+)' ,
url _format _string : 'https://trac.example.com/ticket/%(id)s' ,
} ) ;
casper . click ( 'form.admin-filter-form input.btn' ) ;
2016-02-13 19:17:15 +01:00
} ) ;
} ) ;
2017-02-09 09:01:38 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( 'div#admin-filter-status' , function ( ) {
casper . test . assertSelectorHasText ( 'div#admin-filter-status' , 'Custom filter added!' ) ;
} ) ;
2016-02-13 19:17:15 +01:00
} ) ;
2017-02-09 09:01:38 +01:00
casper . then ( function ( ) {
2016-12-03 01:12:52 +01:00
casper . waitUntilVisible ( '.filter_row' , function ( ) {
2017-02-09 09:01:38 +01:00
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' ) ;
} ) ;
2016-02-13 19:17:15 +01:00
} ) ;
2017-02-09 09:01:38 +01:00
casper . then ( function ( ) {
2016-12-03 01:12:52 +01:00
casper . waitWhileVisible ( '.filter_row' , function ( ) {
2017-02-09 09:01:38 +01:00
casper . test . assertDoesntExist ( '.filter_row' ) ;
} ) ;
2016-02-13 19:17:15 +01:00
} ) ;
2017-02-09 09:01:38 +01:00
casper . then ( function ( ) {
2016-12-03 01:12:52 +01:00
casper . waitUntilVisible ( '.admin-filter-form' , function ( ) {
2017-02-09 09:01:38 +01:00
casper . fill ( 'form.admin-filter-form' , {
pattern : 'a$' ,
url _format _string : 'https://trac.example.com/ticket/%(id)s' ,
} ) ;
casper . click ( 'form.admin-filter-form input.btn' ) ;
2016-02-13 19:17:15 +01:00
} ) ;
} ) ;
2017-02-09 09:01:38 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( 'div#admin-filter-pattern-status' , function ( ) {
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 ( ) {
2016-12-03 01:12:52 +01:00
casper . click ( "li[data-section='default-streams-list']" ) ;
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-12-03 01:12:52 +01:00
casper . waitUntilVisible ( '.default_stream_row[id=' + stream _name + ']' , function ( ) {
2016-05-20 22:08:42 +02:00
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-12-03 01:12:52 +01:00
casper . waitUntilVisible ( '.default_stream_row[id=' + stream _name + ']' , function ( ) {
2016-05-20 22:08:42 +02:00
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-12-03 01:12:52 +01:00
casper . waitWhileVisible ( '.default_stream_row[id=' + stream _name + ']' , function ( ) {
2016-05-20 22:08:42 +02:00
casper . test . assertDoesntExist ( '.default_stream_row[id=' + stream _name + ']' ) ;
} ) ;
} ) ;
2016-07-27 12:34:08 +02:00
2016-12-03 01:12:52 +01:00
2015-11-04 18:21:17 +01:00
// TODO: Test stream deletion
2017-02-27 03:43:13 +01:00
// Test uploading realm icon image
casper . then ( function ( ) {
casper . click ( "li[data-section='organization-settings']" ) ;
casper . test . assertExists ( 'img#realm-settings-icon[src^="https://secure.gravatar.com/avatar/"]' ) ;
casper . test . assertEqual ( casper . visible ( '#realm_icon_delete_button' ) , false ) ;
casper . fill ( 'form.admin-realm-form' , {
realm _icon _file _input : 'static/images/logo/zulip-icon-128x128.png' ,
} , true ) ;
casper . waitWhileVisible ( "#upload_icon_spinner .loading_indicator_spinner" , function ( ) {
casper . test . assertExists ( 'img#realm-settings-icon[src^="/user_avatars/1/realm/icon.png?version=2"]' ) ;
casper . test . assertEqual ( casper . visible ( '#realm_icon_delete_button' ) , true ) ;
} ) ;
} ) ;
// Test deleting realm icon image
casper . then ( function ( ) {
casper . click ( "li[data-section='organization-settings']" ) ;
casper . click ( "#realm_icon_delete_button" ) ;
casper . test . assertEqual ( casper . visible ( '#realm_icon_delete_button' ) , true ) ;
casper . waitWhileVisible ( "#upload_icon_spinner .loading_indicator_spinner" , function ( ) {
casper . test . assertExists ( 'img#realm-settings-icon[src^="https://secure.gravatar.com/avatar/"]' ) ;
casper . test . assertEqual ( casper . visible ( '#realm_icon_delete_button' ) , false ) ;
} ) ;
} ) ;
2016-08-04 17:32:41 +02:00
casper . then ( function ( ) {
2016-12-03 01:12:52 +01:00
casper . click ( "li[data-section='organization-settings']" ) ;
2017-02-10 06:58:09 +01:00
casper . waitUntilVisible ( '#id_realm_default_language' , function ( ) {
casper . test . info ( "Changing realm default language" ) ;
casper . evaluate ( function ( ) {
$ ( '#id_realm_default_language' ) . val ( 'de' ) . change ( ) ;
} ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
2016-08-04 17:32:41 +02:00
} ) ;
} ) ;
2017-02-10 06:58:09 +01:00
casper . then ( function ( ) {
casper . waitUntilVisible ( '#admin-realm-default-language-status' , function ( ) {
casper . test . assertSelectorHasText ( '#admin-realm-default-language-status' ,
'Default language changed!' ) ;
} ) ;
2016-08-04 17:32:41 +02:00
} ) ;
2016-11-02 21:51:56 +01:00
// Test authentication methods setting
2017-02-10 06:58:09 +01:00
casper . then ( function ( ) {
2016-12-03 01:12:52 +01:00
casper . click ( "li[data-section='auth-methods']" ) ;
2016-12-03 01:12:52 +01:00
casper . waitUntilVisible ( ".method_row[data-method='Email'] input[type='checkbox']" , function ( ) {
2017-02-10 06:58:09 +01:00
casper . click ( ".method_row[data-method='Email'] input[type='checkbox']" ) ;
casper . click ( 'form.admin-realm-form input.button' ) ;
} ) ;
2016-11-02 21:51:56 +01:00
} ) ;
// 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"]' ) ;
2016-12-03 01:12:52 +01:00
casper . waitUntilVisible ( ".method_row[data-method='Email'] input[type='checkbox']" , function ( ) {
2016-11-02 21:51:56 +01:00
// 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 ( ) ;
} ) ;