2019-07-12 02:03:55 +02:00
set _global ( 'Handlebars' , global . make _handlebars ( ) ) ;
2017-11-08 19:24:52 +01:00
zrequire ( 'templates' ) ;
2016-05-13 12:44:03 +02:00
2017-11-08 19:17:57 +01:00
set _global ( 'i18n' , global . stub _i18n ) ;
2019-04-26 15:14:53 +02:00
set _global ( 'page_params' , { } ) ;
2019-06-29 22:00:44 +02:00
zrequire ( 'settings_notifications' ) ;
2019-06-14 14:42:48 +02:00
zrequire ( 'stream_edit' ) ;
2020-02-04 21:50:55 +01:00
zrequire ( 'stream_data' ) ;
2013-11-27 22:05:33 +01:00
2018-05-20 16:35:54 +02:00
const { JSDOM } = require ( "jsdom" ) ;
const { window } = new JSDOM ( ) ;
2016-08-24 21:49:53 +02:00
global . $ = require ( 'jquery' ) ( window ) ;
2013-11-27 22:05:33 +01:00
2013-12-11 18:53:05 +01:00
// When writing these tests, the following command might be helpful:
2019-07-12 00:52:56 +02:00
// ./tools/get-handlebar-vars static/templates/*.hbs
2013-12-11 18:53:05 +01:00
function render ( template _name , args ) {
2019-07-09 21:24:00 +02:00
return require ( '../../static/templates/' + template _name + '.hbs' ) ( args ) ;
2013-12-11 18:53:05 +01:00
}
2018-05-15 12:40:07 +02:00
run _test ( 'handlebars_bug' , ( ) => {
2014-01-10 16:36:01 +01:00
// There was a bug in 1.0.9 where identically structured
// blocks get confused, so when foo is false, it still
// renders the foo-is-true block.
2019-11-02 00:06:25 +01:00
let s = '' ;
2014-01-10 16:36:01 +01:00
s += '{{#if foo}}' ;
s += '{{#if bar}}' ;
s += 'a' ;
s += '{{else}}' ;
s += 'b' ;
s += '{{/if}}' ;
s += '{{else}}' ;
s += '{{#if bar}}' ;
s += 'c' ;
s += '{{else}}' ;
s += 'd' ;
s += '{{/if}}' ;
s += '{{/if}}' ;
2019-11-02 00:06:25 +01:00
const template = global . Handlebars . compile ( s ) ;
const output = template ( { } ) ;
2014-01-10 16:36:01 +01:00
assert . equal ( output , 'd' ) ; // the buggy version would return 'b'
2018-05-15 12:40:07 +02:00
} ) ;
2014-01-10 16:36:01 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'actions_popover_content' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-03-28 00:28:57 +02:00
should _display _quote _and _reply : true ,
2016-12-03 03:08:47 +01:00
can _edit _message : true ,
can _mute _topic : true ,
2016-12-03 23:17:57 +01:00
narrowed : true ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '<div style="height: 250px">' ;
2013-12-11 18:53:05 +01:00
html += render ( 'actions_popover_content' , args ) ;
html += "</div>" ;
2019-11-02 00:06:25 +01:00
const link = $ ( html ) . find ( "a.respond_button" ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( link . text ( ) . trim ( ) , 'translated: Quote and reply' ) ;
2018-03-28 00:28:57 +02:00
2019-11-02 00:06:25 +01:00
const deletedArgs = {
2018-03-28 00:28:57 +02:00
should _display _edit _and _view _source : false ,
should _display _quote _and _reply : false ,
narrowed : true ,
} ;
2019-11-02 00:06:25 +01:00
let deletedHtml = '<div style="height: 250px">' ;
2018-03-28 00:28:57 +02:00
deletedHtml += render ( 'actions_popover_content' , deletedArgs ) ;
deletedHtml += "</div>" ;
2019-11-02 00:06:25 +01:00
const viewSourceLink = $ ( deletedHtml ) . find ( "a.popover_edit_message" ) ;
2018-03-28 00:28:57 +02:00
assert . equal ( viewSourceLink . length , 0 ) ;
2019-11-02 00:06:25 +01:00
const quoteLink = $ ( deletedHtml ) . find ( "a.respond_button" ) ;
2018-03-28 00:28:57 +02:00
assert . equal ( quoteLink . length , 0 ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_realm_domains_list' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = "<table>" ;
const args = {
2017-03-31 22:40:48 +02:00
realm _domain : {
2016-12-26 19:19:02 +01:00
domain : 'zulip.org' ,
2017-01-21 08:19:03 +01:00
allow _subdomains : true ,
2016-12-26 19:19:02 +01:00
} ,
} ;
2019-07-12 00:52:56 +02:00
html += render ( "settings/admin_realm_domains_list" , args ) ;
2016-12-26 19:19:02 +01:00
html += "</table>" ;
2019-11-02 00:06:25 +01:00
const button = $ ( html ) . find ( '.button' ) ;
const domain = $ ( html ) . find ( '.domain' ) ;
const row = button . closest ( 'tr' ) ;
const subdomains _checkbox = row . find ( '.allow-subdomains' ) ;
2016-12-26 19:19:02 +01:00
2017-11-08 19:17:57 +01:00
assert . equal ( button . text ( ) . trim ( ) , "translated: Remove" ) ;
2017-03-31 22:40:48 +02:00
assert ( button . hasClass ( "delete_realm_domain" ) ) ;
2016-12-26 19:19:02 +01:00
assert . equal ( domain . text ( ) , "zulip.org" ) ;
2017-01-21 08:19:03 +01:00
assert . equal ( subdomains _checkbox . prop ( 'checked' ) , true ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-12-26 19:19:02 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_realm_dropdown_stream_list' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = "<ul>" ;
const args = {
2017-06-10 07:03:53 +02:00
stream : {
name : "Italy" ,
subscriber _count : 9 ,
stream _id : 18 ,
} ,
} ;
2019-07-12 00:52:56 +02:00
html += render ( "settings/admin_realm_dropdown_stream_list" , args ) ;
2017-06-10 07:03:53 +02:00
html += "</ul>" ;
2019-11-02 00:06:25 +01:00
const link = $ ( html ) . find ( "a" ) ;
const list _item = $ ( html ) . find ( "li" ) ;
2017-06-10 07:03:53 +02:00
assert . equal ( link . text ( ) . trim ( ) , "Italy" ) ;
assert ( list _item . hasClass ( "stream_name" ) ) ;
assert . equal ( list _item . attr ( "data-stream-id" ) , "18" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-06-10 07:03:53 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_default_streams_list' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = '<table>' ;
const streams = [ 'devel' , 'trac' , 'zulip' ] ;
2017-04-14 23:08:22 +02:00
// When the logged in user is admin
2016-05-20 22:08:42 +02:00
_ . each ( streams , function ( stream ) {
2019-11-02 00:06:25 +01:00
const args = {
2018-05-07 03:30:13 +02:00
stream : { name : stream , invite _only : false } ,
can _modify : true ,
} ;
2016-05-20 22:08:42 +02:00
html += render ( 'admin_default_streams_list' , args ) ;
} ) ;
html += "</table>" ;
2019-11-02 00:06:25 +01:00
let span = $ ( html ) . find ( ".default_stream_name" ) . first ( ) ;
2016-05-20 22:08:42 +02:00
assert . equal ( span . text ( ) , "devel" ) ;
2017-04-14 23:08:22 +02:00
// When the logged in user is not admin
html = '<table>' ;
_ . each ( streams , function ( stream ) {
2019-11-02 00:06:25 +01:00
const args = {
2018-05-07 03:30:13 +02:00
stream : { name : stream , invite _only : false } ,
can _modify : false ,
} ;
2017-04-14 23:08:22 +02:00
html += render ( 'admin_default_streams_list' , args ) ;
} ) ;
html += "</table>" ;
2019-06-06 05:50:36 +02:00
span = $ ( html ) . find ( ".default_stream_name" ) . first ( ) ;
2017-04-14 23:08:22 +02:00
assert . equal ( span . text ( ) , "devel" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-05-20 22:08:42 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_emoji_list' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-07-30 04:52:29 +02:00
emoji : {
2016-12-03 03:08:47 +01:00
name : "MouseFace" ,
2018-08-05 22:40:29 +02:00
display _name : "MouseFace" ,
2016-12-03 23:17:57 +01:00
source _url : "http://emojipedia-us.s3.amazonaws.com/cache/46/7f/467fe69069c408e07517621f263ea9b5.png" ,
} ,
2016-07-30 04:52:29 +02:00
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2016-07-30 04:52:29 +02:00
html += '<tbody id="admin_emoji_table">' ;
html += render ( 'admin_emoji_list' , args ) ;
html += '</tbody>' ;
2019-11-02 00:06:25 +01:00
const emoji _name = $ ( html ) . find ( 'tr.emoji_row' ) . first ( ) . find ( 'span.emoji_name' ) ;
const emoji _url = $ ( html ) . find ( 'tr.emoji_row' ) . first ( ) . find ( 'span.emoji_image img' ) ;
2016-07-30 04:52:29 +02:00
assert . equal ( emoji _name . text ( ) , 'MouseFace' ) ;
assert . equal ( emoji _url . attr ( 'src' ) , 'http://emojipedia-us.s3.amazonaws.com/cache/46/7f/467fe69069c408e07517621f263ea9b5.png' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-07-30 04:52:29 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_profile_field_list' , ( ) => {
2017-12-14 05:51:45 +01:00
// When the logged in user is admin
2019-11-02 00:06:25 +01:00
let args = {
2017-12-14 05:51:45 +01:00
profile _field : {
name : "teams" ,
2018-05-06 11:40:31 +02:00
type : "Long text" ,
2017-12-14 05:51:45 +01:00
} ,
can _modify : true ,
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2017-12-14 05:51:45 +01:00
html += '<tbody id="admin_profile_fields_table">' ;
html += render ( 'admin_profile_field_list' , args ) ;
html += '</tbody>' ;
2019-11-02 00:06:25 +01:00
let field _name = $ ( html ) . find ( 'tr.profile-field-row' ) . first ( ) . find ( 'span.profile_field_name' ) ;
let field _type = $ ( html ) . find ( 'tr.profile-field-row' ) . first ( ) . find ( 'span.profile_field_type' ) ;
let td = $ ( html ) . find ( 'tr.profile-field-row' ) . first ( ) . find ( 'td' ) ;
2017-12-14 05:51:45 +01:00
assert . equal ( field _name . text ( ) , 'teams' ) ;
2018-05-06 11:40:31 +02:00
assert . equal ( field _type . text ( ) , 'Long text' ) ;
2018-03-31 09:23:57 +02:00
assert . equal ( td . length , 4 ) ;
2017-12-14 05:51:45 +01:00
// When the logged in user is not admin
args = {
profile _field : {
name : "teams" ,
2018-05-06 11:40:31 +02:00
type : "Long text" ,
2017-12-14 05:51:45 +01:00
} ,
can _modify : false ,
} ;
html = '' ;
html += '<tbody id="admin_profile_fields_table">' ;
html += render ( 'admin_profile_field_list' , args ) ;
html += '</tbody>' ;
2019-06-06 06:21:42 +02:00
field _name = $ ( html ) . find ( 'tr.profile-field-row' ) . first ( ) . find ( 'span.profile_field_name' ) ;
field _type = $ ( html ) . find ( 'tr.profile-field-row' ) . first ( ) . find ( 'span.profile_field_type' ) ;
td = $ ( html ) . find ( 'tr.profile-field-row' ) . first ( ) . find ( 'td' ) ;
2017-12-14 05:51:45 +01:00
assert . equal ( field _name . text ( ) , 'teams' ) ;
2018-05-06 11:40:31 +02:00
assert . equal ( field _type . text ( ) , 'Long text' ) ;
2018-03-31 09:23:57 +02:00
assert . equal ( td . length , 3 ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-12-14 05:51:45 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_filter_list' , ( ) => {
2017-04-14 23:56:33 +02:00
// When the logged in user is admin
2019-11-02 00:06:25 +01:00
let args = {
2016-02-13 19:17:15 +01:00
filter : {
2016-12-03 03:08:47 +01:00
pattern : "#(?P<id>[0-9]+)" ,
2016-12-03 23:17:57 +01:00
url _format _string : "https://trac.example.com/ticket/%(id)s" ,
} ,
2017-04-14 23:56:33 +02:00
can _modify : true ,
2016-02-13 19:17:15 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2016-02-13 19:17:15 +01:00
html += '<tbody id="admin_filters_table">' ;
html += render ( 'admin_filter_list' , args ) ;
html += '</tbody>' ;
2019-11-02 00:06:25 +01:00
let filter _pattern = $ ( html ) . find ( 'tr.filter_row' ) . first ( ) . find ( 'span.filter_pattern' ) ;
let filter _format = $ ( html ) . find ( 'tr.filter_row' ) . first ( ) . find ( 'span.filter_url_format_string' ) ;
2016-02-13 19:17:15 +01:00
assert . equal ( filter _pattern . text ( ) , '#(?P<id>[0-9]+)' ) ;
assert . equal ( filter _format . text ( ) , 'https://trac.example.com/ticket/%(id)s' ) ;
2017-04-14 23:56:33 +02:00
// When the logged in user is not admin
args = {
filter : {
pattern : "#(?P<id>[0-9]+)" ,
url _format _string : "https://trac.example.com/ticket/%(id)s" ,
} ,
can _modify : false ,
} ;
html = '' ;
html += '<tbody id="admin_filters_table">' ;
html += render ( 'admin_filter_list' , args ) ;
html += '</tbody>' ;
2019-06-06 06:21:42 +02:00
filter _pattern = $ ( html ) . find ( 'tr.filter_row' ) . first ( ) . find ( 'span.filter_pattern' ) ;
filter _format = $ ( html ) . find ( 'tr.filter_row' ) . first ( ) . find ( 'span.filter_url_format_string' ) ;
2017-04-14 23:56:33 +02:00
assert . equal ( filter _pattern . text ( ) , '#(?P<id>[0-9]+)' ) ;
assert . equal ( filter _format . text ( ) , 'https://trac.example.com/ticket/%(id)s' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-02-13 19:17:15 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_invites_list' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = '<table>' ;
const invites = [ 'alice' , 'bob' , 'carl' ] ;
let invite _id = 0 ;
2017-10-21 03:15:12 +02:00
_ . each ( invites , function ( invite ) {
2019-11-02 00:06:25 +01:00
const args = {
2017-10-21 03:15:12 +02:00
invite : {
email : invite + '@zulip.com' ,
ref : 'iago@zulip.com' ,
invited : "2017-01-01 01:01:01" ,
id : invite _id ,
2017-12-12 15:10:09 +01:00
invited _as _admin : true ,
2017-10-21 03:15:12 +02:00
} ,
} ;
html += render ( 'admin_invites_list' , args ) ;
invite _id += 1 ;
} ) ;
html += "</table>" ;
2019-11-02 00:06:25 +01:00
const buttons = $ ( html ) . find ( '.button' ) ;
2017-10-21 03:15:12 +02:00
2017-11-08 19:17:57 +01:00
assert . equal ( $ ( buttons [ 0 ] ) . text ( ) . trim ( ) , "translated: Revoke" ) ;
2017-10-21 03:15:12 +02:00
assert ( $ ( buttons [ 0 ] ) . hasClass ( "revoke" ) ) ;
assert . equal ( $ ( buttons [ 0 ] ) . attr ( "data-invite-id" ) , 0 ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( $ ( buttons [ 3 ] ) . text ( ) . trim ( ) , "translated: Resend" ) ;
2017-10-21 03:15:12 +02:00
assert ( $ ( buttons [ 3 ] ) . hasClass ( "resend" ) ) ;
assert . equal ( $ ( buttons [ 3 ] ) . attr ( "data-invite-id" ) , 1 ) ;
2019-11-02 00:06:25 +01:00
const span = $ ( html ) . find ( ".email" ) . first ( ) ;
2017-10-21 03:15:12 +02:00
assert . equal ( span . text ( ) , "alice@zulip.com" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-10-21 03:15:12 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_tab' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-12-03 23:17:57 +01:00
realm _name : 'Zulip' ,
2016-07-30 06:06:51 +02:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'admin_tab' , args ) ;
const admin _features = [ "admin_users_table" , "admin_bots_table" ,
"admin_deactivated_users_table" , "admin_invites_table" ] ;
2016-07-30 06:06:51 +02:00
_ . each ( admin _features , function ( admin _feature ) {
assert . notEqual ( $ ( html ) . find ( "#" + admin _feature ) . length , 0 ) ;
} ) ;
assert . equal ( $ ( html ) . find ( "input.admin-realm-name" ) . val ( ) , 'Zulip' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_user_group_list' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-11-17 04:31:37 +01:00
user _group : {
id : "9" ,
name : "uranohoshi" ,
description : "Students at Uranohoshi Academy" ,
} ,
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2017-11-17 04:31:37 +01:00
html += '<div id="user-groups">' ;
html += render ( 'admin_user_group_list' , args ) ;
html += '</div>' ;
2019-11-02 00:06:25 +01:00
const group _id = $ ( html ) . find ( '.user-group' ) . first ( ) . prop ( 'id' ) ;
const group _pills _id = $ ( html ) . find ( '.user-group' ) . first ( ) . find ( '.pill-container' ) . attr ( 'data-group-pills' ) ;
const group _name _display = $ ( html ) . find ( '.user-group' ) . first ( ) . find ( '.name' ) . text ( ) . trim ( ) . replace ( /\s+/g , ' ' ) ;
const group _description = $ ( html ) . find ( '.user-group' ) . first ( ) . find ( '.description' ) . text ( ) . trim ( ) . replace ( /\s+/g , ' ' ) ;
2017-11-17 04:31:37 +01:00
assert . equal ( group _id , '9' ) ;
2018-03-27 22:08:50 +02:00
assert . equal ( group _pills _id , '9' ) ;
2018-03-14 17:22:19 +01:00
assert . equal ( group _name _display , 'uranohoshi' ) ;
assert . equal ( group _description , 'Students at Uranohoshi Academy' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-11-17 04:31:37 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'admin_user_list' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = '<table>' ;
const users = [ 'alice' , 'bob' , 'carl' ] ;
2017-04-10 23:25:11 +02:00
// When the logged in user is admin
2013-12-11 18:53:05 +01:00
_ . each ( users , function ( user ) {
2019-11-02 00:06:25 +01:00
const args = {
2016-12-03 03:08:47 +01:00
user : {
is _active : true ,
is _active _human : true ,
email : user + '@zulip.com' ,
2016-12-03 23:17:57 +01:00
full _name : user ,
} ,
2017-04-10 23:25:11 +02:00
can _modify : true ,
2013-12-11 18:53:05 +01:00
} ;
html += render ( 'admin_user_list' , args ) ;
} ) ;
html += "</table>" ;
2014-01-16 03:59:05 +01:00
2019-11-02 00:06:25 +01:00
let buttons = $ ( html ) . find ( '.button' ) ;
2014-01-16 03:59:05 +01:00
2017-11-08 19:17:57 +01:00
assert . equal ( $ ( buttons [ 0 ] ) . text ( ) . trim ( ) , "translated: Deactivate" ) ;
2016-09-27 14:25:52 +02:00
assert ( $ ( buttons [ 0 ] ) . hasClass ( "deactivate" ) ) ;
2018-08-01 16:27:13 +02:00
assert . equal ( $ ( buttons [ 1 ] ) . attr ( 'title' ) . trim ( ) , "translated: Edit user" ) ;
assert ( $ ( buttons [ 1 ] ) . hasClass ( "open-user-form" ) ) ;
2014-01-16 03:59:05 +01:00
2017-04-10 23:25:11 +02:00
// When the logged in user is not admin
html = '<table>' ;
_ . each ( users , function ( user ) {
2019-11-02 00:06:25 +01:00
const args = {
2017-04-10 23:25:11 +02:00
user : {
is _active : true ,
is _active _human : true ,
email : user + '@zulip.com' ,
full _name : user ,
} ,
can _modify : false ,
} ;
html += render ( 'admin_user_list' , args ) ;
} ) ;
html += "</table>" ;
buttons = $ ( html ) . find ( '.button' ) ;
2018-07-14 12:43:04 +02:00
// No buttons should be availabe to non-admins
assert . equal ( $ ( buttons ) . length , 0 ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'alert_word_settings_item' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = '<ul id="alert-words">' ;
const words = [ 'lunch' , 'support' ] ;
let args ;
2013-12-11 18:53:05 +01:00
_ . each ( words , function ( word ) {
2017-06-07 21:36:43 +02:00
args = {
2016-12-03 23:17:57 +01:00
word : word ,
2013-12-11 18:53:05 +01:00
} ;
html += render ( 'alert_word_settings_item' , args ) ;
} ) ;
2017-06-07 21:36:43 +02:00
args = {
word : '' ,
editing : true ,
} ;
html += render ( 'alert_word_settings_item' , args ) ;
2013-12-11 18:53:05 +01:00
html += "</ul>" ;
2017-06-07 21:36:43 +02:00
2019-11-02 00:06:25 +01:00
const li = $ ( html ) . find ( "li.alert-word-item" ) . first ( ) ;
const value = li . find ( '.value' ) ;
let button = li . find ( 'button' ) ;
2018-12-07 22:14:28 +01:00
assert . equal ( li . attr ( 'data-word' ) , 'lunch' ) ;
2017-06-07 21:36:43 +02:00
assert . equal ( value . length , 1 ) ;
assert . equal ( value . text ( ) , 'lunch' ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( button . attr ( 'title' ) , 'translated: Delete alert word' ) ;
2018-12-07 22:14:28 +01:00
assert . equal ( button . attr ( 'data-word' ) , 'lunch' ) ;
2017-06-07 21:36:43 +02:00
2019-11-02 00:06:25 +01:00
const title = $ ( html ) . find ( '.new-alert-word-section-title' ) ;
const textbox = $ ( html ) . find ( '#create_alert_word_name' ) ;
2017-06-07 21:36:43 +02:00
button = $ ( html ) . find ( '#create_alert_word_button' ) ;
assert . equal ( title . length , 1 ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( title . text ( ) . trim ( ) , 'translated: Add a new alert word' ) ;
2017-06-07 21:36:43 +02:00
assert . equal ( textbox . length , 1 ) ;
assert . equal ( textbox . attr ( 'maxlength' ) , 100 ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( textbox . attr ( 'placeholder' ) , 'translated: Alert word' ) ;
2017-06-07 21:36:43 +02:00
assert . equal ( textbox . attr ( 'class' ) , 'required' ) ;
assert . equal ( button . length , 1 ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( button . text ( ) . trim ( ) , 'translated: Add alert word' ) ;
2017-06-07 21:36:43 +02:00
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'all_messages_sidebar_actions' , ( ) => {
2018-04-16 14:09:01 +02:00
render ( 'all_messages_sidebar_actions' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-02-15 20:38:06 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'announce_stream_docs' , ( ) => {
2018-04-16 14:09:01 +02:00
render ( 'announce_stream_docs' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'bankruptcy_modal' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-12-03 23:17:57 +01:00
unread _count : 99 ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'bankruptcy_modal' , args ) ;
const count = $ ( html ) . find ( "p b" ) ;
2013-12-11 18:53:05 +01:00
assert . equal ( count . text ( ) , 99 ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2019-06-29 06:20:19 +02:00
run _test ( 'settings/admin_auth_methods_list' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2019-04-06 08:43:34 +02:00
method : "Email" ,
enabled : false ,
2016-11-02 21:51:56 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2019-04-06 08:43:34 +02:00
html += '<tbody>' ;
2019-06-29 06:20:19 +02:00
html += render ( 'settings/admin_auth_methods_list' , args ) ;
2016-11-02 21:51:56 +01:00
html += '</tbody>' ;
2019-11-02 00:06:25 +01:00
const method = $ ( html ) . find ( 'tr.method_row' ) . first ( ) . find ( 'span.method' ) ;
2016-11-02 21:51:56 +01:00
assert . equal ( method . text ( ) , 'Email' ) ;
2019-07-13 05:36:02 +02:00
assert . equal ( method . is ( ":checked" ) , false ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-11-02 21:51:56 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'bookend' , ( ) => {
2016-07-30 05:42:39 +02:00
// Do subscribed/unsubscribed cases here.
2019-11-02 00:06:25 +01:00
let args = {
2016-07-30 05:42:39 +02:00
bookend _content : "subscribed to stream" ,
trailing : true ,
2016-12-03 23:17:57 +01:00
subscribed : true ,
2016-07-30 05:42:39 +02:00
} ;
2019-11-02 00:06:25 +01:00
let html ;
2016-07-30 05:42:39 +02:00
html = render ( 'bookend' , args ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( $ ( html ) . text ( ) . trim ( ) , "subscribed to stream\n \n \n translated: Unsubscribe" ) ;
2016-07-30 05:42:39 +02:00
args = {
bookend _content : "Not subscribed to stream" ,
trailing : true ,
2016-12-03 23:17:57 +01:00
subscribed : false ,
2016-07-30 05:42:39 +02:00
} ;
html = render ( 'bookend' , args ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( $ ( html ) . text ( ) . trim ( ) , 'Not subscribed to stream\n \n \n translated: Subscribe' ) ;
2016-07-30 05:42:39 +02:00
2018-06-02 09:45:07 +02:00
} ) ;
2016-07-30 05:42:39 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'bot_avatar_row' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = '' ;
const args = {
2016-12-03 03:08:47 +01:00
email : "hamlet@zulip.com" ,
api _key : "123456ABCD" ,
name : "Hamlet" ,
2016-12-03 23:17:57 +01:00
avatar _url : "/hamlet/avatar/url" ,
2013-12-11 18:53:05 +01:00
} ;
html += render ( 'bot_avatar_row' , args ) ;
2019-11-02 00:06:25 +01:00
const img = $ ( html ) . find ( "img" ) ;
2013-12-11 18:53:05 +01:00
assert . equal ( img . attr ( 'src' ) , '/hamlet/avatar/url' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'bot_owner_select' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-02-25 08:49:12 +01:00
users _list : [
{
email : "hamlet@zulip.com" ,
api _key : "123456ABCD" ,
full _name : "Hamlet" ,
avatar _url : "/hamlet/avatar/url" ,
} ,
] ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'bot_owner_select' , args ) ;
const option = $ ( html ) . find ( "option" ) . last ( ) ;
2017-02-25 08:49:12 +01:00
assert . equal ( option . val ( ) , "hamlet@zulip.com" ) ;
assert . equal ( option . text ( ) , "Hamlet" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-02-25 08:49:12 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'compose_invite_users' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2013-12-11 18:53:05 +01:00
email : 'hamlet@zulip.com' ,
2016-12-03 23:17:57 +01:00
name : 'Hamlet' ,
2018-08-13 00:46:29 +02:00
can _subscribe _other _users : true ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = render ( 'compose_invite_users' , args ) ;
let button = $ ( html ) . find ( "button" ) . first ( ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( button . text ( ) , "translated: Subscribe" ) ;
2018-08-13 00:46:29 +02:00
args . can _subscribe _other _users = false ;
2019-07-12 00:52:56 +02:00
html = render ( 'compose_invite_users' , args ) ;
2019-06-06 05:50:36 +02:00
button = $ ( html ) . find ( "button" ) . first ( ) ;
2018-08-13 00:46:29 +02:00
assert . equal ( button . length , 0 ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'compose_all_everyone' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-06-04 04:31:35 +02:00
count : '101' ,
2020-01-23 07:22:26 +01:00
mention : 'all' ,
2016-06-04 04:31:35 +02:00
} ;
2020-01-23 07:22:26 +01:00
let html = render ( 'compose_all_everyone' , args ) ;
2019-11-02 00:06:25 +01:00
const button = $ ( html ) . find ( "button" ) . first ( ) ;
2020-01-23 07:22:26 +01:00
// test for @all mention warning.
assert . equal ( button . text ( ) , "translated: Yes, send" ) ;
let error _msg = $ ( html ) . find ( 'span.compose-all-everyone-msg' ) . text ( ) . trim ( ) ;
assert . equal ( error _msg , "translated: Are you sure you want to mention all 101 people in this stream? This will send email and mobile push notifications to most of those 101 users. If you don't want to do that, please edit your message to remove the @all mention." ) ;
// test for @everyone warning.
args . mention = 'everyone' ;
html = render ( 'compose_all_everyone' , args ) ;
assert . equal ( button . text ( ) , "translated: Yes, send" ) ;
error _msg = $ ( html ) . find ( 'span.compose-all-everyone-msg' ) . text ( ) . trim ( ) ;
assert . equal ( error _msg , "translated: Are you sure you want to mention all 101 people in this stream? This will send email and mobile push notifications to most of those 101 users. If you don't want to do that, please edit your message to remove the @everyone mention." ) ;
// test for @stream warning.
args . mention = 'stream' ;
html = render ( 'compose_all_everyone' , args ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( button . text ( ) , "translated: Yes, send" ) ;
2020-01-23 07:22:26 +01:00
error _msg = $ ( html ) . find ( 'span.compose-all-everyone-msg' ) . text ( ) . trim ( ) ;
assert . equal ( error _msg , "translated: Are you sure you want to mention all 101 people in this stream? This will send email and mobile push notifications to most of those 101 users. If you don't want to do that, please edit your message to remove the @stream mention." ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-06-04 04:31:35 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'compose_announce' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-12-18 16:09:41 +01:00
count : '101' ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'compose_announce' , args ) ;
const button = $ ( html ) . find ( "button" ) . first ( ) ;
2017-12-18 16:09:41 +01:00
assert . equal ( button . text ( ) , "translated: Yes, send" ) ;
2019-11-02 00:06:25 +01:00
const error _msg = $ ( html ) . find ( 'span.compose-announce-msg' ) . text ( ) . trim ( ) ;
2019-11-13 14:48:21 +01:00
assert . equal ( error _msg , "translated: This stream is reserved for announcements. Are you sure you want to message all 101 people in this stream?" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-12-18 16:09:41 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'compose_not_subscribed' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = render ( 'compose_not_subscribed' , { should _display _sub _button : true } ) ;
let button = $ ( html ) . find ( "button" ) . first ( ) ;
2018-04-04 19:38:09 +02:00
assert . equal ( button . text ( ) , "translated: Subscribe" ) ;
2018-10-31 19:59:40 +01:00
html = render ( 'compose_not_subscribed' , { should _display _sub _button : false } ) ;
2019-06-06 05:50:36 +02:00
button = $ ( html ) . find ( "button" ) . first ( ) ;
2018-10-31 19:59:40 +01:00
assert . equal ( button . length , 0 ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-04-04 19:38:09 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'compose_notification' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-12-03 03:08:47 +01:00
note : "You sent a message to a muted topic." ,
link _text : "Narrow to here" ,
link _msg _id : "99" ,
2018-11-13 16:11:42 +01:00
link _class : "compose_notification_narrow_by_topic" ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '<div id="out-of-view-notification" class="notification-alert">' ;
2013-12-11 18:53:05 +01:00
html += render ( 'compose_notification' , args ) ;
html += '</div>' ;
2019-11-02 00:06:25 +01:00
const a = $ ( html ) . find ( "a.compose_notification_narrow_by_topic" ) ;
2013-12-11 18:53:05 +01:00
assert . equal ( a . text ( ) , "Narrow to here" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'compose_private_stream_alert' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-05-07 03:30:13 +02:00
stream _name : 'Denmark' ,
2017-10-14 15:18:21 +02:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'compose_private_stream_alert' , args ) ;
2017-11-27 17:34:47 +01:00
assert ( $ ( html ) . hasClass ( 'compose_private_stream_alert' ) ) ;
2019-11-02 00:06:25 +01:00
const actual _text = $ ( html ) . text ( ) ;
const expected _text = 'translated: Warning: Denmark is a private stream.' ;
2017-11-27 17:34:47 +01:00
assert ( actual _text . indexOf ( expected _text ) >= 1 ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-10-14 15:18:21 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'custom_user_profile_field' , ( ) => {
2019-11-02 00:06:25 +01:00
const field = { name : "GitHub user name" , id : 2 , hint : "Or link to profile" } ;
const args = { field : field , field _value : { value : "@GitHub" , rendered _value : "<p>@GitHub</p>" } , field _type : "text" } ;
const html = render ( 'settings/custom_user_profile_field' , args ) ;
2018-05-06 00:38:23 +02:00
assert . equal ( $ ( html ) . attr ( 'data-field-id' ) , 2 ) ;
2018-05-04 16:46:46 +02:00
assert . equal ( $ ( html ) . find ( '.custom_user_field_value' ) . val ( ) , "@GitHub" ) ;
2018-05-01 19:33:33 +02:00
assert . equal ( $ ( html ) . find ( '.field_hint' ) . text ( ) , "Or link to profile" ) ;
assert . equal ( $ ( html ) . find ( 'label' ) . text ( ) , "GitHub user name" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-02-26 20:08:23 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'deactivate_stream_modal' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-02-21 05:16:45 +01:00
stream _name : "Public stream" ,
2019-06-12 21:01:38 +02:00
stream _id : 1 ,
2018-02-21 05:16:45 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'settings/deactivation_stream_modal' , args ) ;
2018-02-21 05:16:45 +01:00
2019-11-02 00:06:25 +01:00
const modal _header = $ ( html ) . find ( "#deactivation_stream_modal_label" ) ;
2018-02-21 05:16:45 +01:00
assert . equal ( modal _header . text ( ) , "translated: Delete stream " + args . stream _name ) ;
2019-11-02 00:06:25 +01:00
const button = $ ( html ) . find ( "#do_deactivate_stream_button" ) ;
2018-02-21 05:16:45 +01:00
assert . equal ( button . text ( ) , "translated: Yes, delete this stream" ) ;
2019-06-12 21:01:38 +02:00
assert . equal ( button . data ( 'stream-id' ) , args . stream _id ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-02-21 05:16:45 +01:00
2019-06-29 06:20:19 +02:00
run _test ( 'settings/dev_env_email_access' , ( ) => {
render ( 'settings/dev_env_email_access' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-10-02 23:26:20 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'draft_table_body' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-02-22 02:34:05 +01:00
drafts : [
{
draft _id : '1' ,
is _stream : true ,
stream : 'all' ,
2019-06-18 20:58:40 +02:00
stream _color : '#FF0000' , // hsl(0, 100%, 50%)
2017-02-22 02:34:05 +01:00
topic : 'tests' ,
content : 'Public draft' ,
} ,
{
draft _id : '2' ,
is _stream : false ,
recipients : 'Jordan, Michael' ,
content : 'Private draft' ,
} ,
] ,
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2017-02-22 02:34:05 +01:00
html += '<div id="drafts_table">' ;
html += render ( 'draft_table_body' , args ) ;
html += '</div>' ;
2019-11-02 00:06:25 +01:00
const row _1 = $ ( html ) . find ( ".draft-row[data-draft-id='1']" ) ;
2017-02-22 02:34:05 +01:00
assert . equal ( row _1 . find ( ".stream_label" ) . text ( ) . trim ( ) , "all" ) ;
assert . equal ( row _1 . find ( ".stream_label" ) . css ( "background" ) , "rgb(255, 0, 0)" ) ;
assert . equal ( row _1 . find ( ".stream_topic" ) . text ( ) . trim ( ) , "tests" ) ;
assert ( ! row _1 . find ( ".message_row" ) . hasClass ( "private-message" ) ) ;
assert . equal ( row _1 . find ( ".message_content" ) . text ( ) . trim ( ) , "Public draft" ) ;
2019-11-02 00:06:25 +01:00
const row _2 = $ ( html ) . find ( ".draft-row[data-draft-id='2']" ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( row _2 . find ( ".stream_label" ) . text ( ) . trim ( ) , "translated: You and Jordan, Michael" ) ;
2017-02-22 02:34:05 +01:00
assert ( row _2 . find ( ".message_row" ) . hasClass ( "private-message" ) ) ;
assert . equal ( row _2 . find ( ".message_content" ) . text ( ) . trim ( ) , "Private draft" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-02-22 02:34:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'emoji_popover' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-07-19 00:28:56 +02:00
class : "emoji-info-popover" ,
} ;
2019-11-02 00:06:25 +01:00
let html = "<div>" ;
2017-09-17 20:55:41 +02:00
html += render ( 'emoji_popover' , args ) ;
html += "</div>" ;
2019-11-02 00:06:25 +01:00
const popover = $ ( html ) . find ( ".popover" ) ;
2017-09-17 20:55:41 +02:00
assert ( popover . hasClass ( "emoji-info-popover" ) ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-07-19 00:28:56 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'emoji_popover_content' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-04-28 22:26:22 +02:00
search : 'Search' ,
message _id : 1 ,
2017-07-19 00:28:56 +02:00
emoji _categories : [
{
name : 'Test' ,
emojis : [
{
has _reacted : false ,
is _realm _emoji : false ,
name : '100' ,
2018-07-20 18:38:56 +02:00
emoji _code : '100' ,
2017-07-19 00:28:56 +02:00
} ,
] ,
} ,
2017-09-17 20:55:41 +02:00
{
name : 'Test1' ,
emojis : [
{
has _reacted : false ,
is _realm _emoji : true ,
name : 'zulip' ,
url : 'zulip' ,
} ,
] ,
} ,
2017-07-19 00:28:56 +02:00
] ,
2017-04-28 22:26:22 +02:00
} ;
2019-11-02 00:06:25 +01:00
let html = '<div style="height: 250px">' ;
2017-04-28 22:26:22 +02:00
html += render ( 'emoji_popover_content' , args ) ;
html += "</div>" ;
// test to make sure the first emoji is present in the popover
2019-11-02 00:06:25 +01:00
const first _emoji = $ ( html ) . find ( ".emoji-100" ) ;
2017-09-29 22:16:36 +02:00
assert . equal ( first _emoji . length , 1 ) ;
2017-09-17 20:55:41 +02:00
2019-11-02 00:06:25 +01:00
const categories = $ ( html ) . find ( ".emoji-popover-tab-item" ) ;
2017-09-17 20:55:41 +02:00
assert . equal ( categories . length , 2 ) ;
2019-11-02 00:06:25 +01:00
const category _1 = $ ( html ) . find ( ".emoji-popover-tab-item[data-tab-name = 'Test']" ) ;
2017-09-17 20:55:41 +02:00
assert ( category _1 . hasClass ( "active" ) ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-04-28 22:26:22 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'emoji_popover_search_results' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-07-19 00:28:56 +02:00
message _id : 1 ,
search _results : [
{
has _reacted : false ,
is _realm _emoji : false ,
name : 'test-1' ,
2018-07-20 18:38:56 +02:00
emoji _code : 'test-1' ,
2017-07-19 00:28:56 +02:00
} ,
{
has _reacted : true ,
is _realm _emoji : false ,
name : 'test-2' ,
2018-07-20 18:38:56 +02:00
emoji _code : 'test-2' ,
2017-07-19 00:28:56 +02:00
} ,
] ,
} ;
2019-11-02 00:06:25 +01:00
let html = "<div>" ;
2017-07-19 00:28:56 +02:00
html += render ( "emoji_popover_search_results" , args ) ;
html += "</div>" ;
2019-11-02 00:06:25 +01:00
const used _emoji = $ ( html ) . find ( ".emoji-test-2" ) . parent ( ) ;
2017-07-19 00:28:56 +02:00
assert ( used _emoji . hasClass ( "reaction" ) ) ;
assert ( used _emoji . hasClass ( "reacted" ) ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-07-19 00:28:56 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'emoji_showcase' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-08-27 22:15:02 +02:00
emoji _dict : {
name : "thumbs_up" ,
is _realm _emoji : false ,
2018-07-20 18:38:56 +02:00
emoji _code : "1f44d" ,
2017-08-27 22:15:02 +02:00
has _reacted : false ,
} ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( "emoji_showcase" , args ) ;
const emoji _div = $ ( html ) . find ( ".emoji" ) ;
const canonical _name = $ ( html ) . find ( ".emoji-canonical-name" ) ;
2017-08-27 22:15:02 +02:00
assert . equal ( emoji _div . length , 1 ) ;
assert ( emoji _div . hasClass ( "emoji-1f44d" ) ) ;
assert . equal ( canonical _name . text ( ) , "thumbs_up" ) ;
assert . equal ( canonical _name . attr ( "title" ) , "thumbs_up" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-08-27 22:15:02 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'group_pms' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-12-03 03:08:47 +01:00
group _pms : [
2013-12-11 18:53:05 +01:00
{
2016-12-03 03:08:47 +01:00
fraction _present : 0.1 ,
emails : "alice@zulip.com,bob@zulip.com" ,
short _name : "Alice and Bob" ,
2016-12-03 23:17:57 +01:00
name : "Alice and Bob" ,
} ,
] ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'group_pms' , args ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
const a = $ ( html ) . find ( "a" ) . first ( ) ;
2013-12-11 18:53:05 +01:00
assert . equal ( a . text ( ) , 'Alice and Bob' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'hotspot_overlay' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-07-14 03:15:19 +02:00
title : 'Start a new conversation' ,
2017-08-30 02:15:32 +02:00
name : 'intro_compose' ,
2017-07-14 03:15:19 +02:00
description : 'Click the "New topic" button to start a new conversation.' ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'hotspot_overlay' , args ) ;
2017-07-14 03:15:19 +02:00
2017-08-30 02:15:32 +02:00
assert . equal ( $ ( html ) . attr ( 'id' ) , 'hotspot_intro_compose_overlay' ) ;
2017-07-14 03:15:19 +02:00
assert . equal ( $ ( html ) . find ( '.hotspot-title' ) . text ( ) , 'Start a new conversation' ) ;
assert . equal (
$ ( html ) . find ( '.hotspot-description' ) . text ( ) ,
'Click the "New topic" button to start a new conversation.'
) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-07-14 03:15:19 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'input_pill' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-03-31 13:22:29 +02:00
id : 22 ,
display _value : 'King Hamlet' ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'input_pill' , args ) ;
2018-03-31 13:22:29 +02:00
assert ( $ ( html ) . hasClass ( 'pill' ) ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-03-31 13:22:29 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'intro_reply_hotspot' , ( ) => {
2019-11-02 00:06:25 +01:00
const html = render ( 'intro_reply_hotspot' , { } ) ;
2018-05-15 23:21:12 +02:00
assert ( $ ( html ) . hasClass ( 'hotspot-message' ) ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-05-15 23:21:12 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'invite_subscription' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2013-12-11 18:53:05 +01:00
streams : [
{
2016-12-03 23:17:57 +01:00
name : "devel" ,
2013-12-11 18:53:05 +01:00
} ,
{
2016-12-03 23:17:57 +01:00
name : "social" ,
} ,
] ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'invite_subscription' , args ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
const input = $ ( html ) . find ( "label" ) . first ( ) ;
2020-01-27 07:52:59 +01:00
assert . equal ( input . text ( ) . trim ( ) , "#devel" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'single_message' , ( ) => {
2019-11-02 00:06:25 +01:00
const message = {
2014-03-14 16:28:54 +01:00
msg : {
2013-11-27 22:05:33 +01:00
include _recipient : true ,
display _recipient : 'devel' ,
is _stream : true ,
content : 'This is message one.' ,
last _edit _timestr : '11:00' ,
2016-12-03 23:17:57 +01:00
starred : true ,
2017-06-29 08:37:35 +02:00
starred _status : "Unstar" ,
2016-12-03 23:17:57 +01:00
} ,
2013-11-27 22:05:33 +01:00
} ;
2014-02-18 16:37:13 +01:00
2019-11-02 00:06:25 +01:00
let html = render ( 'single_message' , message ) ;
2013-12-09 20:15:33 +01:00
html = '<div class="message_table focused_table" id="zfilt">' + html + '</div>' ;
2013-11-27 22:05:33 +01:00
2019-11-02 00:06:25 +01:00
const first _message = $ ( html ) . find ( "div.messagebox" ) . first ( ) ;
2013-11-27 22:05:33 +01:00
2019-11-02 00:06:25 +01:00
const first _message _text = first _message . find ( ".message_content" ) . text ( ) . trim ( ) ;
2013-11-27 22:05:33 +01:00
assert . equal ( first _message _text , "This is message one." ) ;
2019-11-02 00:06:25 +01:00
const starred _title = first _message . find ( ".star" ) . attr ( "title" ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( starred _title , "translated: Unstar this message (*)" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'message_edit_form' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-12-03 03:08:47 +01:00
topic : "lunch" ,
content : "Let's go to lunch!" ,
2016-12-03 23:17:57 +01:00
is _stream : true ,
2016-07-30 06:07:53 +02:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'message_edit_form' , args ) ;
2016-07-30 06:07:53 +02:00
2019-11-02 00:06:25 +01:00
const textarea = $ ( html ) . find ( "textarea.message_edit_content" ) ;
2016-07-30 06:07:53 +02:00
assert . equal ( textarea . text ( ) , "Let's go to lunch!" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-07-30 06:07:53 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'message_group' , ( ) => {
2019-11-02 00:06:25 +01:00
const messages = [
2014-02-18 16:37:13 +01:00
{
2014-03-18 23:24:23 +01:00
msg : {
id : 1 ,
match _content : 'This is message one.' ,
starred : true ,
is _stream : true ,
2016-12-03 23:17:57 +01:00
content : 'This is message one.' ,
2014-03-18 23:24:23 +01:00
} ,
2014-02-18 16:37:13 +01:00
include _recipient : true ,
display _recipient : 'devel' ,
2016-12-03 23:17:57 +01:00
last _edit _timestr : '11:00' ,
2014-02-18 16:37:13 +01:00
} ,
{
2014-03-18 23:24:23 +01:00
msg : {
content : 'This is message two.' ,
2019-07-16 23:20:23 +02:00
match _content : 'This is message <span class="highlight">two</span>.\n<pre>code\nblock</pre>' ,
2014-03-18 23:24:23 +01:00
is _stream : true ,
unread : true ,
2016-12-03 23:17:57 +01:00
id : 2 ,
} ,
} ,
2014-02-18 16:37:13 +01:00
] ;
2019-11-02 00:06:25 +01:00
const groups = [
2014-02-18 16:37:13 +01:00
{
display _recipient : "support" ,
is _stream : true ,
message _ids : [ 1 , 2 ] ,
2014-03-17 19:38:35 +01:00
message _containers : messages ,
2019-02-08 20:11:21 +01:00
group _date _divider _html : '"<span class="timerender82">Jan 07</span>"' ,
2019-02-08 20:24:01 +01:00
show _group _date _divider : true ,
2018-11-15 16:59:41 +01:00
match _topic : '<span class="highlight">two</span> messages' ,
2016-12-03 23:17:57 +01:00
} ,
2014-02-18 16:37:13 +01:00
] ;
2017-01-05 01:03:14 +01:00
render ( 'loader' ) ;
2019-11-02 00:06:25 +01:00
const html = render ( 'message_group' , { message _groups : groups , use _match _properties : true } ) ;
2014-02-18 16:37:13 +01:00
2019-11-02 00:06:25 +01:00
const first _message _text = $ ( html ) . next ( '.recipient_row' ) . find ( 'div.messagebox' ) . first ( ) . find ( '.message_content' ) . text ( ) . trim ( ) ;
2014-02-18 16:37:13 +01:00
assert . equal ( first _message _text , "This is message one." ) ;
2019-11-02 00:06:25 +01:00
const last _message _html = $ ( html ) . next ( '.recipient_row' ) . find ( 'div.messagebox' ) . last ( ) . find ( '.message_content' ) . html ( ) . trim ( ) ;
2019-07-16 23:20:23 +02:00
assert . equal ( last _message _html , 'This is message <span class="highlight">two</span>.\n<pre>code\nblock</pre>' ) ;
2014-02-27 19:28:47 +01:00
2019-11-02 00:06:25 +01:00
const highlighted _topic _word = $ ( html ) . find ( 'a.narrows_by_topic .highlight' ) . text ( ) ;
2018-12-23 18:20:07 +01:00
assert . equal ( highlighted _topic _word , 'two' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2014-02-18 16:37:13 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'message_edit_history' , ( ) => {
2019-11-02 00:06:25 +01:00
const message = {
2017-02-20 02:37:58 +01:00
content : "Let's go to lunch!" ,
edit _history : [
{
2017-06-06 01:46:41 +02:00
body _to _render : "<p>Let's go to " +
"<span class='highlight_text_deleted'>lunch</span>" +
"<span class='highlight_text_inserted'>dinner</span>" +
"!</p>" ,
2017-02-20 02:37:58 +01:00
timestamp : 1468132659 ,
edited _by : 'Alice' ,
posted _or _edited : "Edited by" ,
} ,
] ,
} ;
2019-11-02 00:06:25 +01:00
const html = "<div>" + render ( 'message_edit_history' , {
2018-05-07 03:30:13 +02:00
edited _messages : message . edit _history ,
2019-02-14 01:36:12 +01:00
} ) + "</div>" ;
2019-11-02 00:06:25 +01:00
const edited _message = $ ( html ) . find ( "div.messagebox-content" ) ;
2017-02-20 02:37:58 +01:00
assert . equal ( edited _message . text ( ) . trim ( ) ,
2019-02-14 01:36:12 +01:00
"1468132659\n Let\'s go to lunchdinner!\n Edited by Alice" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-02-20 02:37:58 +01:00
2019-02-22 15:08:16 +01:00
run _test ( 'message_and_topic_edit_history' , ( ) => {
2019-11-02 00:06:25 +01:00
const message = {
2019-02-22 15:08:16 +01:00
content : "Let's go to lunch!" ,
edit _history : [
{
body _to _render : "<p>Let's go to " +
"<span class='highlight_text_deleted'>lunch</span>" +
"<span class='highlight_text_inserted'>dinner</span>" +
"!</p>" ,
new _topic : 'Lunch' ,
prev _topic : 'Dinner' ,
topic _edited : true ,
timestamp : 1468132659 ,
edited _by : 'Alice' ,
posted _or _edited : "Edited by" ,
} ,
] ,
} ;
2019-11-02 00:06:25 +01:00
const html = "<div>" + render ( 'message_edit_history' , {
2019-02-22 15:08:16 +01:00
edited _messages : message . edit _history ,
} ) + "</div>" ;
2019-11-02 00:06:25 +01:00
const edited _message = $ ( html ) . find ( "div.messagebox-content" ) ;
2019-02-22 15:08:16 +01:00
assert . equal ( edited _message . text ( ) . trim ( ) ,
"1468132659\n Topic: Lunch Dinner\n Let\'s go to lunchdinner!\n Edited by Alice" ) ;
} ) ;
run _test ( 'topic_edit_history' , ( ) => {
2019-11-02 00:06:25 +01:00
const message = {
2019-02-22 15:08:16 +01:00
content : "Let's go to lunch!" ,
edit _history : [
{
prev _topic : 'Dinner' ,
new _topic : 'Lunch' ,
topic _edited : true ,
timestamp : 1468132659 ,
edited _by : 'Alice' ,
posted _or _edited : "Topic edited by" ,
} ,
] ,
} ;
2019-11-02 00:06:25 +01:00
const html = "<div>" + render ( 'message_edit_history' , {
2019-02-22 15:08:16 +01:00
edited _messages : message . edit _history ,
} ) + "</div>" ;
2019-11-02 00:06:25 +01:00
const edited _message = $ ( html ) . find ( "div.messagebox-content" ) ;
2019-02-22 15:08:16 +01:00
assert . equal ( edited _message . text ( ) . trim ( ) ,
"1468132659\n Topic: Lunch Dinner\n Topic edited by Alice" ) ;
} ) ;
2018-06-02 09:45:07 +02:00
run _test ( 'message_reaction' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-10-31 22:33:28 +01:00
class : 'message_reaction' ,
2016-12-02 13:23:23 +01:00
emoji _name : 'smile' ,
2017-10-31 22:33:28 +01:00
emoji _code : '1f604' ,
local _id : 'unicode_emoji,smile,1f604' ,
2017-01-12 00:17:43 +01:00
message _id : '1' ,
2016-12-02 13:23:23 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2016-12-02 13:23:23 +01:00
html += '<div>' ;
html += render ( 'message_reaction' , args ) ;
html += '</div>' ;
2019-11-02 00:06:25 +01:00
const reaction = $ ( html ) . find ( ".message_reaction" ) ;
2017-10-31 22:33:28 +01:00
assert . equal ( reaction . data ( "reaction-id" ) , "unicode_emoji,smile,1f604" ) ;
assert ( reaction . find ( ".emoji" ) . hasClass ( "emoji-1f604" ) ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-12-02 13:23:23 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'more_topics' , ( ) => {
2019-11-02 00:06:25 +01:00
const html = render ( 'more_topics' ) ;
2017-09-21 20:44:31 +02:00
assert ( $ ( html ) . hasClass ( 'show-more-topics' ) ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-09-21 20:44:31 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'new_stream_users' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2013-12-11 18:53:05 +01:00
users : [
{
email : 'lear@zulip.com' ,
2016-12-03 23:17:57 +01:00
full _name : 'King Lear' ,
2013-12-11 18:53:05 +01:00
} ,
{
email : 'othello@zulip.com' ,
2016-12-03 23:17:57 +01:00
full _name : 'Othello the Moor' ,
} ,
] ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'new_stream_users' , args ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
const label = $ ( html ) . find ( "label" ) . first ( ) ;
2013-12-11 18:53:05 +01:00
assert . equal ( label . text ( ) . trim ( ) , 'King Lear (lear@zulip.com)' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'non_editable_user_group' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-04-05 23:22:49 +02:00
user _group : {
id : "9" ,
name : "uranohoshi" ,
description : "Students at Uranohoshi Academy" ,
} ,
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2018-04-05 23:22:49 +02:00
html += '<div id="user-groups">' ;
html += render ( 'non_editable_user_group' , args ) ;
html += '</div>' ;
2019-11-02 00:06:25 +01:00
const group _id = $ ( html ) . find ( '.user-group' ) . first ( ) . prop ( 'id' ) ;
const group _pills _id = $ ( html ) . find ( '.user-group' ) . first ( ) . find ( '.pill-container' ) . attr ( 'data-group-pills' ) ;
const group _name _display = $ ( html ) . find ( '.user-group' ) . first ( ) . find ( '.name' ) . text ( ) . trim ( ) . replace ( /\s+/g , ' ' ) ;
const group _description = $ ( html ) . find ( '.user-group' ) . first ( ) . find ( '.description' ) . text ( ) . trim ( ) . replace ( /\s+/g , ' ' ) ;
2018-04-05 23:22:49 +02:00
assert . equal ( group _id , '9' ) ;
2018-03-27 22:08:50 +02:00
assert . equal ( group _pills _id , '9' ) ;
2018-04-05 23:22:49 +02:00
assert . equal ( group _name _display , 'uranohoshi' ) ;
assert . equal ( group _description , 'Students at Uranohoshi Academy' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-04-05 23:22:49 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'notification' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-12-03 03:08:47 +01:00
content : "Hello" ,
gravatar _url : "/gravatar/url" ,
2016-12-03 23:17:57 +01:00
title : "You have a notification" ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'notification' , args ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
const title = $ ( html ) . find ( ".title" ) ;
2013-12-11 18:53:05 +01:00
assert . equal ( title . text ( ) . trim ( ) , 'You have a notification' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'reminder_popover_content' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-01-15 03:02:23 +01:00
message : {
is _stream : true ,
id : "420" ,
stream : "devel" ,
sender _full _name : "Iago" ,
} ,
can _edit _message : true ,
can _mute _topic : true ,
narrowed : true ,
} ;
2019-11-02 00:06:25 +01:00
let html = '<div style="height: 250px">' ;
2018-01-15 03:02:23 +01:00
html += render ( 'remind_me_popover_content' , args ) ;
html += "</div>" ;
2019-11-02 00:06:25 +01:00
const link = $ ( html ) . find ( "a.remind.custom" ) ;
2018-01-15 03:02:23 +01:00
assert . equal ( link . text ( ) . trim ( ) , 'translated: Select date and time' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-01-15 03:02:23 +01:00
2019-02-15 19:09:25 +01:00
run _test ( 'revoke_invite_modal' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2019-02-15 19:09:25 +01:00
is _multiuse : false ,
email : "iago@zulip.com" ,
} ;
2019-11-02 00:06:25 +01:00
let html = "<div>" ;
2019-07-12 00:52:56 +02:00
html += render ( 'settings/revoke_invite_modal' , args ) ;
2019-02-15 19:09:25 +01:00
html += "</div>" ;
assert . equal ( $ ( html ) . find ( "p strong" ) . text ( ) , "iago@zulip.com" ) ;
} ) ;
2018-06-02 09:45:07 +02:00
run _test ( 'settings_tab' , ( ) => {
2019-11-02 00:06:25 +01:00
const page _param _checkbox _options = {
2017-04-29 07:01:46 +02:00
enable _stream _desktop _notifications : true ,
2017-08-17 16:55:32 +02:00
enable _stream _push _notifications : true ,
2019-11-07 02:56:01 +01:00
enable _stream _audible _notifications : true ,
enable _desktop _notifications : true ,
enable _sounds : true ,
enable _offline _email _notifications : true ,
enable _offline _push _notifications : true ,
enable _online _push _notifications : true ,
2016-09-19 22:55:18 +02:00
enable _digest _emails : true ,
2019-03-31 09:38:41 +02:00
realm _digest _emails _enabled : true ,
2018-01-06 23:30:43 +01:00
realm _name _in _notifications : true ,
2018-08-30 22:45:59 +02:00
realm _push _notifications _enabled : true ,
2019-09-03 23:27:45 +02:00
wildcard _mentions _notify : true ,
2016-07-30 06:10:30 +02:00
} ;
2019-11-02 00:06:25 +01:00
const page _params = $ . extend ( page _param _checkbox _options , {
2017-04-27 00:26:49 +02:00
full _name : "Alyssa P. Hacker" , password _auth _enabled : true ,
2016-07-30 06:10:30 +02:00
avatar _url : "https://google.com" ,
} ) ;
2019-11-07 02:56:01 +01:00
const checkbox _ids = [
"enable_stream_desktop_notifications" ,
"enable_stream_push_notifications" ,
"enable_stream_audible_notifications" ,
"enable_desktop_notifications" ,
"enable_sounds" ,
"enable_offline_push_notifications" ,
"enable_online_push_notifications" ,
"enable_digest_emails" ,
"realm_name_in_notifications" ,
2019-09-03 23:27:45 +02:00
"wildcard_mentions_notify" ,
2019-11-07 02:56:01 +01:00
] ;
2016-07-30 06:10:30 +02:00
// Render with all booleans set to true.
2019-11-02 00:06:25 +01:00
let html = render ( 'settings_tab' , {
2019-06-12 19:36:48 +02:00
page _params : page _params ,
notification _settings : settings _notifications . all _notifications . settings ,
} ) ;
2016-07-30 06:10:30 +02:00
// All checkboxes should be checked.
_ . each ( checkbox _ids , function ( checkbox ) {
assert . equal ( $ ( html ) . find ( "#" + checkbox ) . is ( ":checked" ) , true ) ;
} ) ;
// Re-render with checkbox booleans set to false.
_ . each ( page _param _checkbox _options , function ( value , option ) {
page _params [ option ] = false ;
} ) ;
html = render ( 'settings_tab' , { page _params : page _params } ) ;
// All checkboxes should be unchecked.
_ . each ( checkbox _ids , function ( checkbox ) {
assert . equal ( $ ( html ) . find ( "#" + checkbox ) . is ( ":checked" ) , false ) ;
} ) ;
2017-07-21 08:19:37 +02:00
// Check if enable_desktop_notifications setting disables subsetting too.
2019-11-02 00:06:25 +01:00
const parent _elem = $ ( '#pm_content_in_desktop_notifications_label' ) . wrap ( "<div></div>" ) ;
2017-07-21 08:19:37 +02:00
$ ( '#enable_desktop_notifications' ) . prop ( 'checked' , false ) . triggerHandler ( 'change' ) ;
$ ( '#enable_desktop_notifications' ) . change ( function ( ) {
assert ( parent _elem . hasClass ( 'control-label-disabled' ) ) ;
assert . equal ( $ ( '#pm_content_in_desktop_notifications' ) . attr ( 'disabled' ) , 'disabled' ) ;
} ) ;
$ ( '#enable_desktop_notifications' ) . prop ( 'checked' , true ) . triggerHandler ( 'change' ) ;
$ ( '#enable_desktop_notifications' ) . change ( function ( ) {
assert ( ! parent _elem . hasClass ( 'control-label-disabled' ) ) ;
assert . equal ( $ ( '#pm_content_in_desktop_notifications' ) . attr ( 'disabled' ) , undefined ) ;
} ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-07-30 06:10:30 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'stream_member_list_entry' , ( ) => {
2019-11-02 00:06:25 +01:00
const everyone _items = [ "subscriber-name" , "subscriber-email" ] ;
const admin _items = [ "remove-subscriber-button" ] ;
2014-02-01 17:12:28 +01:00
// First, as non-admin.
2019-11-02 00:06:25 +01:00
let html = render ( 'stream_member_list_entry' ,
2014-02-01 17:12:28 +01:00
{ name : "King Hamlet" , email : "hamlet@zulip.com" } ) ;
_ . each ( everyone _items , function ( item ) {
assert . equal ( $ ( html ) . find ( "." + item ) . length , 1 ) ;
} ) ;
_ . each ( admin _items , function ( item ) {
assert . equal ( $ ( html ) . find ( "." + item ) . length , 0 ) ;
} ) ;
// Now, as admin.
html = render ( 'stream_member_list_entry' ,
{ name : "King Hamlet" , email : "hamlet@zulip.com" ,
displaying _for _admin : true } ) ;
_ . each ( everyone _items , function ( item ) {
assert . equal ( $ ( html ) . find ( "." + item ) . length , 1 ) ;
} ) ;
_ . each ( admin _items , function ( item ) {
assert . equal ( $ ( html ) . find ( "." + item ) . length , 1 ) ;
} ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2014-02-01 17:12:28 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'stream_sidebar_actions' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2013-12-11 18:53:05 +01:00
stream : {
color : 'red' ,
name : 'devel' ,
2019-05-15 08:54:25 +02:00
is _muted : false ,
2016-12-03 23:17:57 +01:00
id : 55 ,
} ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'stream_sidebar_actions' , args ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
const li = $ ( html ) . find ( "li" ) . first ( ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( li . text ( ) . trim ( ) , 'translated: Stream settings' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'stream_sidebar_row' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2013-12-11 18:53:05 +01:00
name : "devel" ,
color : "red" ,
dark _background : "maroon" ,
uri : "/devel/uri" ,
2016-12-03 23:17:57 +01:00
id : 999 ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '<ul id="stream_filters">' ;
2013-12-11 18:53:05 +01:00
html += render ( 'stream_sidebar_row' , args ) ;
html += '</ul>' ;
2019-11-02 00:06:25 +01:00
const swatch = $ ( html ) . find ( ".stream-privacy" ) ;
2017-04-17 22:19:47 +02:00
assert . equal ( swatch . attr ( 'id' ) , 'stream_sidebar_privacy_swatch_999' ) ;
// test to ensure that the hashtag element from stream_privacy exists.
assert . equal ( $ ( html ) . find ( ".stream-privacy" ) . children ( "*" ) . attr ( "class" ) , "hashtag" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'subscription_invites_warning_modal' , ( ) => {
2019-11-02 00:06:25 +01:00
const html = render ( 'subscription_invites_warning_modal' ) ;
2017-06-02 15:06:33 +02:00
2019-11-02 00:06:25 +01:00
const button = $ ( html ) . find ( ".close-invites-warning-modal" ) . last ( ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( button . text ( ) , 'translated: Go back' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'subscription_settings' , ( ) => {
2019-11-02 00:06:25 +01:00
const sub = {
2017-05-10 20:02:21 +02:00
name : 'devel' ,
subscribed : true ,
notifications : true ,
is _admin : true ,
render _subscribers : true ,
color : 'purple' ,
invite _only : true ,
2018-05-22 01:14:18 +02:00
can _change _stream _permissions : true ,
2017-05-10 20:02:21 +02:00
email _address : 'xxxxxxxxxxxxxxx@zulip.com' ,
stream _id : 888 ,
2019-05-15 08:54:25 +02:00
is _muted : false ,
2017-05-10 20:02:21 +02:00
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2019-04-26 15:14:53 +02:00
page _params . realm _push _notifications _enabled = false ;
2019-11-02 00:06:25 +01:00
const check _realm _setting = {
2019-04-26 15:14:53 +02:00
push _notifications : ! page _params . realm _push _notifications _enabled ,
} ;
2019-06-14 14:42:48 +02:00
html += render ( 'subscription_settings' , {
sub : sub ,
settings : stream _edit . stream _settings ( sub ) ,
2019-04-26 15:14:53 +02:00
realm _settings : check _realm _setting ,
2019-06-14 14:42:48 +02:00
} ) ;
2017-05-10 20:02:21 +02:00
2019-11-02 00:06:25 +01:00
const div = $ ( html ) . find ( ".subscription-type" ) ;
2018-06-08 22:05:07 +02:00
assert ( div . text ( ) . indexOf ( 'private stream' ) > 0 ) ;
2017-05-10 20:02:21 +02:00
2019-11-02 00:06:25 +01:00
const anchor = $ ( html ) . find ( ".change-stream-privacy" ) . first ( ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( anchor . text ( ) , "[translated: Change]" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-05-10 20:02:21 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'subscription_stream_privacy_modal' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-02-24 00:46:42 +01:00
stream _id : 999 ,
is _private : true ,
2019-01-15 22:20:52 +01:00
is _admin : true ,
2020-02-04 21:50:55 +01:00
stream _post _policy _values : stream _data . stream _post _policy _values ,
2017-02-24 00:46:42 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'subscription_stream_privacy_modal' , args ) ;
2017-02-24 00:46:42 +01:00
2019-11-02 00:06:25 +01:00
const other _options = $ ( html ) . find ( "input[name=privacy]" ) ;
2018-05-03 18:52:39 +02:00
assert . equal ( other _options [ 0 ] . value , 'public' ) ;
2018-05-30 23:16:28 +02:00
assert . equal ( other _options [ 1 ] . value , 'invite-only-public-history' ) ;
assert . equal ( other _options [ 2 ] . value , 'invite-only' ) ;
2017-02-24 00:46:42 +01:00
2020-02-04 21:50:55 +01:00
const stream _post _policy = $ ( html ) . find ( "input[name=stream-post-policy]" ) ;
assert . equal ( stream _post _policy [ 0 ] . value ,
stream _data . stream _post _policy _values . everyone . code ) ;
assert . equal ( stream _post _policy [ 1 ] . value ,
stream _data . stream _post _policy _values . admins . code ) ;
assert . equal ( stream _post _policy [ 2 ] . value ,
stream _data . stream _post _policy _values . non _new _members . code ) ;
2018-05-30 16:02:13 +02:00
2019-11-02 00:06:25 +01:00
const button = $ ( html ) . find ( "#change-stream-privacy-button" ) ;
2018-05-03 18:52:39 +02:00
assert ( button . hasClass ( "btn-danger" ) ) ;
2018-05-30 21:51:55 +02:00
assert . equal ( button . text ( ) . trim ( ) , "translated: Save changes" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-02-24 00:46:42 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'subscription_table_body' , ( ) => {
2018-07-24 14:27:32 +02:00
// We are mostly deprecating template tests,
// but we try to make sure rendering does not
// crash.
render ( 'subscription_table_body' , { } ) ;
} ) ;
run _test ( 'subscriptions' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2013-12-11 18:53:05 +01:00
subscriptions : [
{
name : 'devel' ,
subscribed : true ,
notifications : true ,
2014-01-03 15:31:19 +01:00
is _admin : true ,
2013-12-11 18:53:05 +01:00
render _subscribers : true ,
color : 'purple' ,
invite _only : true ,
email _address : 'xxxxxxxxxxxxxxx@zulip.com' ,
2017-02-24 00:46:42 +01:00
stream _id : 888 ,
2019-05-15 08:54:25 +02:00
is _muted : false ,
2013-12-11 18:53:05 +01:00
} ,
{
name : 'social' ,
color : 'green' ,
2017-02-24 00:46:42 +01:00
stream _id : 999 ,
2016-12-03 23:17:57 +01:00
} ,
] ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2018-07-24 14:27:32 +02:00
html += '<div>' ;
html += render ( 'subscriptions' , args ) ;
2013-12-11 18:53:05 +01:00
html += '</div>' ;
2019-11-02 00:06:25 +01:00
const span = $ ( html ) . find ( ".stream-name" ) . first ( ) ;
2013-12-11 18:53:05 +01:00
assert . equal ( span . text ( ) , 'devel' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'tab_bar' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2013-12-11 18:53:05 +01:00
tabs : [
{
cls : 'root' ,
title : 'Home' ,
hash : '#' ,
2016-12-03 23:17:57 +01:00
data : 'home' ,
2013-12-11 18:53:05 +01:00
} ,
{
cls : 'stream' ,
title : 'Devel' ,
hash : '/stream/uri' ,
2016-12-03 23:17:57 +01:00
data : 'devel' ,
} ,
] ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'tab_bar' , args ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
const a = $ ( html ) . find ( "li" ) . first ( ) ;
2013-12-11 18:53:05 +01:00
assert . equal ( a . text ( ) . trim ( ) , 'Home' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'topic_edit_form' , ( ) => {
2019-11-02 00:06:25 +01:00
const html = render ( 'topic_edit_form' ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
const button = $ ( html ) . find ( "button" ) . first ( ) ;
2018-07-04 02:36:22 +02:00
assert . equal ( button . find ( "i" ) . attr ( "class" ) , 'fa fa-check' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'topic_list_item' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-10-29 18:11:01 +02:00
is _muted : false ,
topic _name : 'lunch' ,
url : '/lunch/url' ,
2016-12-03 23:17:57 +01:00
unread : 5 ,
2016-10-29 18:11:01 +02:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'topic_list_item' , args ) ;
2016-10-29 18:11:01 +02:00
2017-08-17 01:43:37 +02:00
assert . equal ( $ ( html ) . attr ( 'data-topic-name' ) , 'lunch' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-10-29 18:11:01 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'topic_sidebar_actions' , ( ) => {
2019-11-02 00:06:25 +01:00
let args = {
2013-12-11 18:53:05 +01:00
stream _name : 'social' ,
topic _name : 'lunch' ,
2016-12-03 23:17:57 +01:00
can _mute _topic : true ,
2019-01-18 17:40:54 +01:00
is _admin : false ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = render ( 'topic_sidebar_actions' , args ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
const a = $ ( html ) . find ( "a.narrow_to_topic" ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( a . text ( ) . trim ( ) , 'translated: Narrow to topic lunch' ) ;
2013-12-11 18:53:05 +01:00
2019-11-02 00:06:25 +01:00
let delete _topic _option = $ ( html ) . find ( "a.sidebar-popover-delete-topic-messages" ) ;
2019-01-18 17:40:54 +01:00
assert . equal ( delete _topic _option . length , 0 ) ;
args = {
is _admin : true ,
} ;
html = render ( 'topic_sidebar_actions' , args ) ;
delete _topic _option = $ ( html ) . find ( "a.sidebar-popover-delete-topic-messages" ) ;
assert . equal ( delete _topic _option . length , 1 ) ;
} ) ;
run _test ( 'delete_topic_modal' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2019-01-18 17:40:54 +01:00
topic _name : 'lunch' ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'delete_topic_modal' , args ) ;
2019-01-18 17:40:54 +01:00
2019-11-02 00:06:25 +01:00
const modal _body = $ ( html ) . find ( '.modal-body' ) ;
2019-02-07 03:07:44 +01:00
assert ( modal _body . text ( ) . indexOf ( 'delete all messages in lunch?' ) > 0 ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'typeahead_list_item' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-06-12 19:15:57 +02:00
primary : 'primary-text' ,
secondary : 'secondary-text' ,
img _src : 'https://zulip.org' ,
2017-09-27 19:39:42 +02:00
is _emoji : true ,
2017-06-12 19:15:57 +02:00
has _image : true ,
has _secondary : true ,
} ;
2019-11-02 00:06:25 +01:00
const html = '<div>' + render ( 'typeahead_list_item' , args ) + '</div>' ;
2017-06-12 19:15:57 +02:00
assert . equal ( $ ( html ) . find ( '.emoji' ) . attr ( 'src' ) , 'https://zulip.org' ) ;
assert . equal ( $ ( html ) . find ( 'strong' ) . text ( ) . trim ( ) , 'primary-text' ) ;
assert . equal ( $ ( html ) . find ( 'small' ) . text ( ) . trim ( ) , 'secondary-text' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'typing_notifications' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-10-12 20:57:59 +02:00
users : [ {
full _name : 'Hamlet' ,
email : 'hamlet@zulip.com' ,
} ] ,
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2016-10-12 20:57:59 +02:00
html += '<ul>' ;
html += render ( 'typing_notifications' , args ) ;
html += '</ul>' ;
2019-11-02 00:06:25 +01:00
const li = $ ( html ) . find ( 'li' ) . first ( ) ;
2016-10-12 20:57:59 +02:00
assert . equal ( li . text ( ) , 'Hamlet is typing...' ) ;
2017-03-03 21:36:37 +01:00
2018-06-02 09:45:07 +02:00
} ) ;
2017-03-03 21:36:37 +01:00
2019-01-17 12:05:09 +01:00
run _test ( 'upload_space_stats' , ( ) => {
2019-11-02 00:06:25 +01:00
let args = {
2019-01-17 12:05:09 +01:00
show _upgrade _message : true ,
percent _used : 50 ,
upload _quota : "1 GB" ,
} ;
2019-11-02 00:06:25 +01:00
let html = render ( 'settings/upload_space_stats' , args ) ;
2019-01-17 12:05:09 +01:00
assert . equal ( $ ( html ) . text ( ) . trim ( ) , "translated: Organization using 50% of 1 GB.\n translated: Upgrade for more space." ) ;
args = {
show _upgrade _message : false ,
percent _used : 10 ,
upload _quota : "5 GB" ,
} ;
2019-07-12 00:52:56 +02:00
html = render ( 'settings/upload_space_stats' , args ) ;
2019-01-17 12:05:09 +01:00
assert . equal ( $ ( html ) . text ( ) . trim ( ) , "translated: Organization using 10% of 5 GB." ) ;
} ) ;
2018-06-02 09:45:07 +02:00
run _test ( 'user_group_info_popover' , ( ) => {
2019-11-02 00:06:25 +01:00
const html = render ( 'user_group_info_popover' ) ;
2018-02-14 05:21:46 +01:00
$ ( html ) . hasClass ( 'popover message-info-popover group-info-popover' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-02-14 05:21:46 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'user_group_info_popover_content' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-02-14 05:21:46 +01:00
group _name : 'groupName' ,
group _description : 'groupDescription' ,
members : [
{
full _name : 'Active Alice' ,
user _last _seen _time _status : 'time' ,
is _bot : false ,
} ,
{
full _name : 'Bot Bob' ,
user _last _seen _time _status : 'time' ,
is _bot : true ,
} ,
{
full _name : 'Inactive Imogen' ,
user _last _seen _time _status : 'time' ,
is _bot : false ,
} ,
] ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'user_group_info_popover_content' , args ) ;
2018-02-14 05:21:46 +01:00
2019-11-02 00:06:25 +01:00
const allUsers = $ ( html ) . find ( "li" ) ;
2018-02-14 05:21:46 +01:00
assert . equal ( $ ( allUsers [ 0 ] ) . text ( ) . trim ( ) , 'Active Alice' ) ;
assert . equal ( $ ( allUsers [ 1 ] ) . text ( ) . trim ( ) , 'Bot Bob' ) ;
assert . equal ( $ ( allUsers [ 2 ] ) . text ( ) . trim ( ) , 'Inactive Imogen' ) ;
assert . equal ( $ ( html ) . find ( '.group-name' ) . text ( ) . trim ( ) , 'groupName' ) ;
assert . equal ( $ ( html ) . find ( '.group-description' ) . text ( ) . trim ( ) , 'groupDescription' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-02-14 05:21:46 +01:00
2019-02-14 15:01:39 +01:00
run _test ( 'no_arrow_popover' , ( ) => {
2019-11-02 00:06:25 +01:00
const html = render ( 'no_arrow_popover' , { class : 'message-info-popover' } ) ;
2017-03-03 21:36:37 +01:00
$ ( html ) . hasClass ( 'popover message-info-popover' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-10-12 20:57:59 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'user_info_popover_content' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-03-04 13:26:46 +01:00
message : {
full _date _str : 'Monday' ,
full _time _str : '12:00' ,
user _full _name : 'Alice Smith' ,
user _email : 'alice@zulip.com' ,
} ,
sent _by _uri : '/sent_by/uri' ,
pm _with _uri : '/pm_with/uri' ,
2017-03-04 13:43:21 +01:00
private _message _class : 'compose_private_message' ,
2017-03-04 13:26:46 +01:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'user_info_popover_content' , args ) ;
2017-03-04 13:26:46 +01:00
2019-11-02 00:06:25 +01:00
const a = $ ( html ) . find ( "a.narrow_to_private_messages" ) ;
2017-11-08 19:17:57 +01:00
assert . equal ( a . text ( ) . trim ( ) , 'translated: View private messages' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-03-04 13:26:46 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'user_info_popover_title' , ( ) => {
2019-11-02 00:06:25 +01:00
let html = render ( 'user_info_popover_title' , { user _avatar : 'avatar/hamlet@zulip.com' } ) ;
2017-03-04 13:26:46 +01:00
html = '<div>' + html + '</div>' ;
2017-09-17 01:19:11 +02:00
assert . equal ( $ ( html ) . find ( '.popover-avatar' ) . css ( 'background-image' ) , "url(avatar/hamlet@zulip.com)" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-09-17 01:19:11 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'uploaded_files_list_popover' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2017-09-17 01:20:11 +02:00
attachment : {
name : "file_name.txt" ,
create _time : "Apr 12 04:18 AM" ,
messages : [
{
id : "1" ,
} ,
{
id : "2" ,
} ,
] ,
size : 1234 ,
path _id : "2/65/6wITdgsd63hdskjuFqEeEy7_r/file_name.txt" ,
} ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'uploaded_files_list' , args ) ;
2017-09-17 01:20:11 +02:00
assert . equal ( $ ( html ) . find ( '.ind-message' ) . attr ( "href" ) , "/#narrow/id/1" ) ;
assert . equal ( $ ( html ) . find ( '#download_attachment' ) . attr ( "href" ) ,
"/user_uploads/2/65/6wITdgsd63hdskjuFqEeEy7_r/file_name.txt" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2017-03-04 13:26:46 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'user_presence_rows' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2013-12-11 18:53:05 +01:00
users : [
{
2016-12-03 03:08:47 +01:00
type _desc : "Active" ,
type : "active" ,
num _unread : 0 ,
email : "lear@zulip.com" ,
2016-12-03 23:17:57 +01:00
name : "King Lear" ,
2013-12-11 18:53:05 +01:00
} ,
{
2016-12-03 03:08:47 +01:00
type _desc : "Away" ,
type : "away" ,
num _unread : 5 ,
email : "othello@zulip.com" ,
2016-12-03 23:17:57 +01:00
name : "Othello" ,
} ,
] ,
2013-12-11 18:53:05 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '' ;
2013-12-11 18:53:05 +01:00
html += '<ul class="filters">' ;
html += render ( 'user_presence_rows' , args ) ;
html += '</ul>' ;
2019-11-02 00:06:25 +01:00
const a = $ ( html ) . find ( "a" ) . first ( ) ;
2018-06-27 00:08:28 +02:00
assert . equal ( a . text ( ) . trim ( ) , 'King Lear' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2013-12-11 18:53:05 +01:00
2019-08-04 14:57:32 +02:00
run _test ( 'buddy_list_tooltip_content' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2019-11-20 23:39:10 +01:00
first _line : 'Iago' ,
second _line : 'out to lunch' ,
third _line : 'Active now' ,
2019-08-04 14:57:32 +02:00
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'buddy_list_tooltip_content' , args ) ;
const tooltip _content = $ ( html ) . find ( ".tooltip_inner_content" ) ;
2019-08-04 14:57:32 +02:00
assert . equal ( tooltip _content . text ( ) . trim ( ) , 'Iagoout to lunchActive now' ) ;
} ) ;
2018-06-02 09:45:07 +02:00
run _test ( 'user_profile_modal' , ( ) => {
2019-11-02 00:06:25 +01:00
let args = {
2018-04-23 20:41:35 +02:00
full _name : "Iago" ,
email : "iago@zulip.com" ,
profile _data : {
author : "Shakespeare" ,
book : "Othello" ,
} ,
2019-04-20 18:08:29 +02:00
show _email : true ,
2018-04-23 20:41:35 +02:00
} ;
2019-04-20 18:08:29 +02:00
let html = render ( 'user_profile_modal' , args ) ;
let div = $ ( html ) . find ( "#email .value" ) ;
2018-04-23 20:41:35 +02:00
assert . equal ( div . text ( ) . trim ( ) , 'iago@zulip.com' ) ;
2019-04-20 18:08:29 +02:00
args = {
full _name : "Hamlet" ,
email : "hamlet@zulip.com" ,
profile _data : {
author : "Hamlet" ,
book : "Othello" ,
} ,
show _email : false ,
} ;
html = render ( 'user_profile_modal' , args ) ;
div = $ ( html ) . find ( "#email .value" ) ;
assert . equal ( div . text ( ) . trim ( ) , '' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-04-23 20:41:35 +02:00
2018-06-02 09:45:07 +02:00
run _test ( 'muted_topic_ui_row' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2016-11-26 04:39:53 +01:00
stream : 'Verona' ,
2018-12-14 17:52:01 +01:00
stream _id : 99 ,
topic : 'pizza' ,
2016-11-26 04:39:53 +01:00
} ;
2019-11-02 00:06:25 +01:00
let html = '<table id="muted-topics-table">' ;
2016-11-26 04:39:53 +01:00
html += '<tbody>' ;
html += render ( 'muted_topic_ui_row' , args ) ;
html += '</tbody>' ;
html += '</table>' ;
2018-12-14 17:52:01 +01:00
assert . equal ( $ ( html ) . find ( "tr" ) . attr ( "data-stream-id" ) , 99 ) ;
assert . equal ( $ ( html ) . find ( "tr" ) . attr ( "data-topic" ) , "pizza" ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2016-11-26 04:39:53 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'embedded_bot_config_item' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-01-07 19:24:14 +01:00
botname : 'giphy' ,
key : 'api_key' ,
value : '12345678' ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'embedded_bot_config_item' , args ) ;
2018-01-07 19:24:14 +01:00
assert . equal ( $ ( html ) . attr ( 'name' ) , args . botname ) ;
2018-06-04 21:13:07 +02:00
assert . equal ( $ ( html ) . attr ( 'id' ) , args . botname + '_' + args . key ) ;
2018-01-07 19:24:14 +01:00
assert . equal ( $ ( html ) . find ( 'label' ) . text ( ) , args . key ) ;
assert . equal ( $ ( html ) . find ( 'input' ) . attr ( 'placeholder' ) , args . value ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-01-07 19:24:14 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'edit_bot' , ( ) => {
2018-02-07 10:34:52 +01:00
render ( 'edit_bot' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-02-07 10:34:52 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'edit_outgoing_webhook_service' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-02-07 15:14:18 +01:00
service : { base _url : "http://www.foo.bar" ,
interface : "1" } ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'settings/edit_outgoing_webhook_service' , args ) ;
2018-05-18 14:39:02 +02:00
assert . equal ( $ ( html ) . find ( '#edit_service_base_url' ) . val ( ) , args . service . base _url ) ;
assert . equal ( $ ( html ) . find ( '#edit_service_interface' ) . val ( ) , args . service . interface ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-02-07 15:14:18 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'edit_embedded_bot_service' , ( ) => {
2019-11-02 00:06:25 +01:00
const args = {
2018-02-01 13:57:24 +01:00
service : { service _name : "giphy" ,
config _data : { key : "abcd1234" } } ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'settings/edit_embedded_bot_service' , args ) ;
2018-02-01 13:57:24 +01:00
assert . equal ( $ ( html ) . find ( '#embedded_bot_key_edit' ) . attr ( 'name' ) , 'key' ) ;
assert . equal ( $ ( html ) . find ( '#embedded_bot_key_edit' ) . val ( ) , 'abcd1234' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2018-02-01 13:57:24 +01:00
2018-06-02 09:45:07 +02:00
run _test ( 'archive_message_group' , ( ) => {
2018-02-03 12:57:38 +01:00
// The messages list below doesn't represent the actual HTML which would be
// feed to these handlebar templates but since the actual one is a lot bigger
// to be included in a test case and really comes pre rendered from the backend
// we just kinda test out the template part which is rendered on frontend with
// some self made html for messages to insert into the handlebars.
2019-11-02 00:06:25 +01:00
const messages = [
2018-02-03 12:57:38 +01:00
'<p>This is message one.</p>' ,
'<p>This is message two.</p>' ,
] ;
2019-11-02 00:06:25 +01:00
const groups = [
2018-02-03 12:57:38 +01:00
{
display _recipient : "support" ,
message _containers : messages ,
2019-02-08 20:11:21 +01:00
group _date _divider _html : '"<span class="timerender82">Jan 07</span>"' ,
2019-02-08 20:24:01 +01:00
show _group _date _divider : true ,
2018-02-03 12:57:38 +01:00
} ,
] ;
2019-11-02 00:06:25 +01:00
const html = render ( 'archive_message_group' , { message _groups : groups } ) ;
2018-02-03 12:57:38 +01:00
2019-11-02 00:06:25 +01:00
const first _message _text = $ ( html ) . next ( '.recipient_row' ) . find ( 'p' ) . first ( ) . text ( ) . trim ( ) ;
2018-02-03 12:57:38 +01:00
assert . equal ( first _message _text , "This is message one." ) ;
2019-11-02 00:06:25 +01:00
const last _message _text = $ ( html ) . next ( '.recipient_row' ) . find ( 'p' ) . last ( ) . text ( ) . trim ( ) ;
2018-02-03 12:57:38 +01:00
assert . equal ( last _message _text , 'This is message two.' ) ;
2018-06-02 09:45:07 +02:00
} ) ;
2019-06-21 08:54:25 +02:00
run _test ( 'recipient_row' , ( ) => {
// Assert HTML escaping in topic links.
const data = {
is _stream : true ,
topic _links : [
'https://google.com' ,
'https://<script>alert("Hello")</script>' ,
] ,
} ;
2019-11-02 00:06:25 +01:00
const html = render ( 'recipient_row' , data ) ;
2019-06-21 08:54:25 +02:00
assert ( html . indexOf ( '<script>alert("Hello")</script>' ) === - 1 ) ;
assert ( html . indexOf ( '<script>alert("Hello")</script>' ) !== - 1 ) ;
} ) ;
2019-11-14 11:21:08 +01:00
run _test ( 'invitation_failed_error' , ( ) => {
let err _list = [ ] ;
err _list . push ( "hamlet@zulip.com: Account has been deactivated." ) ;
let data = {
error _message : "We weren't able to invite anyone." ,
error _list : err _list ,
is _invitee _deactivated : true ,
is _admin : true ,
} ;
let html = '<div>' ;
html += render ( 'invitation_failed_error' , data ) ;
html += '</div>' ;
let p = $ ( html ) . find ( 'p#invitation_error_message' ) ;
assert . equal ( p . text ( ) . trim ( ) , "We weren't able to invite anyone." ) ;
let li = $ ( html ) . find ( "li" ) . first ( ) ;
assert . equal ( li . text ( ) . trim ( ) , "hamlet@zulip.com: Account has been deactivated." ) ;
let p _admin = $ ( html ) . find ( "p#invitation_admin_message" ) ;
assert . equal ( p _admin . text ( ) . trim ( ) , 'translated: You can reactivate deactivated users from organization settings.' ) ;
err _list = [ ] ;
err _list . push ( "hamlet@zulip.com: Account has been deactivated." ) ;
data = {
error _message : "We weren't able to invite anyone." ,
error _list : err _list ,
is _invitee _deactivated : true ,
is _admin : false ,
} ;
html = '<div>' ;
html += render ( 'invitation_failed_error' , data ) ;
html += '</div>' ;
p = $ ( html ) . find ( "p#invitation_error_message" ) ;
assert . equal ( p . text ( ) . trim ( ) , "We weren't able to invite anyone." ) ;
li = $ ( html ) . find ( "li" ) . first ( ) ;
assert . equal ( li . text ( ) . trim ( ) , "hamlet@zulip.com: Account has been deactivated." ) ;
const msg = $ ( html ) . find ( "p#invitation_non_admin_message" ) ;
assert . equal ( msg . text ( ) . trim ( ) , 'translated: Organization administrators can reactivate deactivated users.' ) ;
p _admin = $ ( html ) . find ( "p#invitation_admin_message" ) ;
assert . equal ( p _admin . length , 0 ) ;
err _list = [ ] ;
err _list . push ( "othello@zulip.com: Already has an account." ) ;
data = {
error _message : "We weren't able to invite anyone." ,
error _list : err _list ,
is _invitee _deactivated : false ,
is _admin : false ,
} ;
html = '<div>' ;
html += render ( 'invitation_failed_error' , data ) ;
html += '</div>' ;
p = $ ( html ) . find ( "p#invitation_error_message" ) ;
assert . equal ( p . text ( ) . trim ( ) , "We weren't able to invite anyone." ) ;
li = $ ( html ) . find ( "li" ) . first ( ) ;
assert . equal ( li . text ( ) . trim ( ) , "othello@zulip.com: Already has an account." ) ;
p _admin = $ ( html ) . find ( "p#invitation_admin_message" ) ;
assert . equal ( p _admin . length , 0 ) ;
} ) ;