2020-10-16 09:02:12 +02:00
/*global mock, converse */
2021-02-08 11:27:42 +01:00
const { u , $msg } = converse . env ;
2020-10-16 09:02:12 +02:00
describe ( "An incoming chat Message" , function ( ) {
it ( "can have styling disabled via an \"unstyled\" element" ,
2021-01-29 11:08:28 +01:00
mock . initConverse ( [ 'chatBoxesFetched' ] , { } ,
2020-10-16 09:02:12 +02:00
async function ( done , _converse ) {
const include _nick = false ;
await mock . waitForRoster ( _converse , 'current' , 2 , include _nick ) ;
await mock . openControlBox ( _converse ) ;
const msg _text = '> _ >' ;
const sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@montague.lit' ;
const msg = $msg ( {
'from' : sender _jid ,
'id' : u . getUniqueId ( ) ,
'to' : _converse . connection . jid ,
'type' : 'chat' ,
'xmlns' : 'jabber:client'
} ) . c ( 'body' ) . t ( msg _text ) . up ( )
. c ( 'unstyled' , { 'xmlns' : 'urn:xmpp:styling:0' } ) . tree ( ) ;
await _converse . handleMessageStanza ( msg ) ;
const view = _converse . api . chatviews . get ( sender _jid ) ;
await u . waitUntil ( ( ) => view . model . messages . length ) ;
expect ( view . model . messages . models [ 0 ] . get ( 'is_unstyled' ) ) . toBe ( true ) ;
setTimeout ( ( ) => {
2020-12-08 12:54:14 +01:00
const msg _el = view . querySelector ( 'converse-chat-message-body' ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
done ( ) ;
} , 500 ) ;
} ) ) ;
it ( "can have styling disabled via the allow_message_styling setting" ,
2021-01-29 11:08:28 +01:00
mock . initConverse ( [ 'chatBoxesFetched' ] , { 'allow_message_styling' : false } ,
2020-10-16 09:02:12 +02:00
async function ( done , _converse ) {
const include _nick = false ;
await mock . waitForRoster ( _converse , 'current' , 2 , include _nick ) ;
await mock . openControlBox ( _converse ) ;
const msg _text = '> _ >' ;
const sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@montague.lit' ;
const msg = $msg ( {
'from' : sender _jid ,
'id' : u . getUniqueId ( ) ,
'to' : _converse . connection . jid ,
'type' : 'chat' ,
'xmlns' : 'jabber:client'
} ) . c ( 'body' ) . t ( msg _text ) . tree ( ) ;
await _converse . handleMessageStanza ( msg ) ;
const view = _converse . api . chatviews . get ( sender _jid ) ;
await u . waitUntil ( ( ) => view . model . messages . length ) ;
expect ( view . model . messages . models [ 0 ] . get ( 'is_unstyled' ) ) . toBe ( false ) ;
setTimeout ( ( ) => {
2020-12-08 12:54:14 +01:00
const msg _el = view . querySelector ( 'converse-chat-message-body' ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
done ( ) ;
} , 500 ) ;
} ) ) ;
it ( "can be styled with span XEP-0393 message styling hints" ,
2021-01-29 11:08:28 +01:00
mock . initConverse ( [ 'chatBoxesFetched' ] , { } ,
2020-10-16 09:02:12 +02:00
async function ( done , _converse ) {
let msg _text , msg , msg _el ;
await mock . waitForRoster ( _converse , 'current' , 1 ) ;
const contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@montague.lit' ;
await mock . openChatBoxFor ( _converse , contact _jid ) ;
const view = _converse . api . chatviews . get ( contact _jid ) ;
msg _text = "This *message _contains_* styling hints! \`Here's *some* code\`" ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length ) ;
2020-12-08 12:54:14 +01:00
msg _el = view . querySelector ( 'converse-chat-message-body' ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'This <span class="styling-directive">*</span>' +
'<b>message <span class="styling-directive">_</span><i>contains</i><span class="styling-directive">_</span></b>' +
'<span class="styling-directive">*</span>' +
' styling hints! ' +
'<span class="styling-directive">`</span><code>Here\'s *some* code</code><span class="styling-directive">`</span>'
) ;
msg _text = "Here's a ~strikethrough section~" ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
2021-02-08 11:27:42 +01:00
await _converse . handleMessageStanza ( msg ) ;
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 2 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'Here\'s a <span class="styling-directive">~</span><del>strikethrough section</del><span class="styling-directive">~</span>' ) ;
// Span directives containing hyperlinks
msg _text = "~Check out this site: https://conversejs.org~"
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 3 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'<span class="styling-directive">~</span>' +
'<del>Check out this site: <a target="_blank" rel="noopener" href="https://conversejs.org/">https://conversejs.org</a></del>' +
'<span class="styling-directive">~</span>' ) ;
// Images inside directives aren't shown inline
const base _url = 'https://conversejs.org' ;
msg _text = ` * ${ base _url } /logo/conversejs-filled.svg* ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 4 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'<span class="styling-directive">*</span>' +
'<b><a target="_blank" rel="noopener" href="https://conversejs.org/logo/conversejs-filled.svg">https://conversejs.org/logo/conversejs-filled.svg</a></b>' +
'<span class="styling-directive">*</span>' ) ;
// Emojis inside directives
msg _text = ` ~ Hello! :poop: ~ ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 5 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'<span class="styling-directive">~</span><del> Hello! <span title=":poop:">💩</span> </del><span class="styling-directive">~</span>' ) ;
// Span directives don't cross lines
msg _text = "This *is not a styling hint \n * _But this is_!" ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 6 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'This *is not a styling hint \n' +
' * <span class="styling-directive">_</span><i>But this is</i><span class="styling-directive">_</span>!' ) ;
msg _text = ` (There are three blocks in this body marked by parens,) \n (but there is no *formatting) \n (as spans* may not escape blocks.) \n ~strikethrough~ ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 7 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'(There are three blocks in this body marked by parens,)\n' +
' (but there is no *formatting)\n' +
' (as spans* may not escape blocks.)\n' +
' <span class="styling-directive">~</span><del>strikethrough</del><span class="styling-directive">~</span>' ) ;
// Some edge-case (unspecified) spans
msg _text = ` __ hello world _ ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 8 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'_<span class="styling-directive">_</span><i> hello world </i><span class="styling-directive">_</span>' ) ;
// Directives which are parts of words aren't matched
msg _text = ` Go to ~https://conversejs.org~now _please_ ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 9 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'Go to ~https://conversejs.org~now <span class="styling-directive">_</span><i>please</i><span class="styling-directive">_</span>' ) ;
msg _text = ` Go to _https://converse_js.org_ _please_ ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 10 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'Go to <span class="styling-directive">_</span>' +
'<i><a target="_blank" rel="noopener" href="https://converse_js.org/">https://converse_js.org</a></i>' +
'<span class="styling-directive">_</span> <span class="styling-directive">_</span><i>please</i><span class="styling-directive">_</span>' ) ;
done ( ) ;
} ) ) ;
it ( "can be styled with block XEP-0393 message styling hints" ,
2021-01-29 11:08:28 +01:00
mock . initConverse ( [ 'chatBoxesFetched' ] , { } ,
2020-10-16 09:02:12 +02:00
async function ( done , _converse ) {
let msg _text , msg , msg _el ;
await mock . waitForRoster ( _converse , 'current' , 1 ) ;
const contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@montague.lit' ;
await mock . openChatBoxFor ( _converse , contact _jid ) ;
const view = _converse . api . chatviews . get ( contact _jid ) ;
msg _text = ` Here's a code block: \n \` \` \` \n Inside the code-block, <code>hello</code> we don't enable *styling hints* like ~these~ \n \` \` \` ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'Here\'s a code block: \n' +
'<div class="styling-directive">```</div><code class="block">Inside the code-block, <code>hello</code> we don\'t enable *styling hints* like ~these~\n' +
'</code><div class="styling-directive">```</div>'
) ;
msg _text = "```\nignored\n(println \"Hello, world!\")\n```\nThis should show up as monospace, preformatted text ^" ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 2 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'<div class="styling-directive">```</div>' +
'<code class="block">ignored\n(println "Hello, world!")\n</code>' +
'<div class="styling-directive">```</div>\n' +
'This should show up as monospace, preformatted text ^' ) ;
msg _text = "```ignored\n (println \"Hello, world!\")\n ```\n\n This should not show up as monospace, *preformatted* text ^" ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 3 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'```ignored\n (println "Hello, world!")\n ```\n\n' +
' This should not show up as monospace, ' +
'<span class="styling-directive">*</span><b>preformatted</b><span class="styling-directive">*</span> text ^' ) ;
done ( ) ;
} ) ) ;
it ( "can be styled with quote XEP-0393 message styling hints" ,
2021-01-29 11:08:28 +01:00
mock . initConverse ( [ 'chatBoxesFetched' ] , { } ,
2020-10-16 09:02:12 +02:00
async function ( done , _converse ) {
let msg _text , msg , msg _el ;
await mock . waitForRoster ( _converse , 'current' , 1 ) ;
const contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@montague.lit' ;
await mock . openChatBoxFor ( _converse , contact _jid ) ;
const view = _converse . api . chatviews . get ( contact _jid ) ;
msg _text = ` > This is quoted text \n >This is also quoted \n This is not quoted ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 1 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
2020-12-09 15:11:54 +01:00
'<blockquote>This is quoted text\nThis is also quoted</blockquote>\nThis is not quoted' ) ;
2020-10-16 09:02:12 +02:00
msg _text = ` > This is *quoted* text \n >This is \` also _quoted_ \` \n This is not quoted ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 2 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
2020-12-09 15:11:54 +01:00
'<blockquote>This is <span class="styling-directive">*</span><b>quoted</b><span class="styling-directive">*</span> text\n' +
2020-12-01 10:21:21 +01:00
'This is <span class="styling-directive">`</span><code>also _quoted_</code><span class="styling-directive">`</span></blockquote>\n' +
2020-10-16 09:02:12 +02:00
'This is not quoted' ) ;
2020-12-09 15:11:54 +01:00
msg _text = ` > > This is doubly quoted text ` ;
2020-10-16 09:02:12 +02:00
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 3 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
2020-12-09 15:11:54 +01:00
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) === "<blockquote><blockquote>This is doubly quoted text</blockquote></blockquote>" ) ;
2020-12-09 14:19:31 +01:00
msg _text = ` >> This is doubly quoted text ` ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 4 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-12-09 14:19:31 +01:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
2020-12-09 15:11:54 +01:00
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) === "<blockquote><blockquote>This is doubly quoted text</blockquote></blockquote>" ) ;
2020-10-16 09:02:12 +02:00
msg _text = ">```\n>ignored\n> <span></span> (println \"Hello, world!\")\n>```\n> This should show up as monospace, preformatted text ^" ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 5 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'<blockquote>' +
'<div class="styling-directive">```</div>' +
'<code class="block">ignored\n <span></span> (println "Hello, world!")\n' +
'</code><div class="styling-directive">```</div>\n' +
' This should show up as monospace, preformatted text ^' +
'</blockquote>' ) ;
msg _text = '> ```\n> (println "Hello, world!")\n\nThe entire blockquote is a preformatted text block, but this line is plaintext!' ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 6 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
2020-12-09 15:11:54 +01:00
'<blockquote>```\n (println "Hello, world!")</blockquote>\n\n' +
2020-10-16 09:02:12 +02:00
'The entire blockquote is a preformatted text block, but this line is plaintext!' ) ;
2020-11-27 10:58:38 +01:00
msg _text = '> Also, icons.js is loaded from /dist, instead of dist.\nhttps://conversejs.org/docs/html/configuration.html#assets-path'
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 7 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-11-27 10:58:38 +01:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
2020-12-09 15:11:54 +01:00
'<blockquote>Also, icons.js is loaded from /dist, instead of dist.</blockquote>\n' +
2020-11-27 10:58:38 +01:00
'<a target="_blank" rel="noopener" href="https://conversejs.org/docs/html/configuration.html#assets-path">https://conversejs.org/docs/html/configuration.html#assets-path</a>' ) ;
msg _text = '> Where is it located?\ngeo:37.786971,-122.399677' ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 8 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-11-27 10:58:38 +01:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
2020-12-09 15:11:54 +01:00
'<blockquote>Where is it located?</blockquote>\n' +
2020-11-27 10:58:38 +01:00
'<a target="_blank" rel="noopener" ' +
2020-12-09 14:19:31 +01:00
'href="https://www.openstreetmap.org/?mlat=37.786971&mlon=-122.399677#map=18/37.786971/-122.399677">https://www.openstreetmap.org/?mlat=37.786971&mlon=-122.399677#map=18/37.786971/-122.399677</a>' ) ;
2020-11-27 10:58:38 +01:00
msg _text = '> What do you think of it?\n :poop:' ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 9 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-11-27 10:58:38 +01:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
2020-12-09 15:11:54 +01:00
'<blockquote>What do you think of it?</blockquote>\n <span title=":poop:">💩</span>' ) ;
2020-12-01 10:21:21 +01:00
msg _text = '> What do you think of it?\n~hello~' ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 10 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-12-01 10:21:21 +01:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
2020-12-09 15:11:54 +01:00
'<blockquote>What do you think of it?</blockquote>\n<span class="styling-directive">~</span><del>hello</del><span class="styling-directive">~</span>' ) ;
2020-12-09 14:19:31 +01:00
msg _text = 'hello world > this is not a quote' ;
msg = mock . createChatMessage ( _converse , contact _jid , msg _text )
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 11 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-12-09 14:19:31 +01:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) === 'hello world > this is not a quote' ) ;
2020-12-09 15:58:09 +01:00
msg _text = '> What do you think of it romeo?\n Did you see this romeo?' ;
msg = $msg ( {
from : contact _jid ,
to : _converse . connection . jid ,
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( msg _text ) . up ( )
. c ( 'reference' , {
'xmlns' : 'urn:xmpp:reference:0' ,
'begin' : '26' ,
'end' : '31' ,
'type' : 'mention' ,
'uri' : _converse . bare _jid
} )
. c ( 'reference' , {
'xmlns' : 'urn:xmpp:reference:0' ,
'begin' : '51' ,
'end' : '56' ,
'type' : 'mention' ,
'uri' : _converse . bare _jid
} ) . nodeTree ;
await _converse . handleMessageStanza ( msg ) ;
2021-02-08 11:27:42 +01:00
await u . waitUntil ( ( ) => view . querySelectorAll ( '.chat-msg__text' ) . length === 12 ) ;
2020-12-08 12:54:14 +01:00
msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-12-09 15:58:09 +01:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
` <blockquote>What do you think of it <span class="mention">romeo</span>?</blockquote> \n Did you see this <span class="mention">romeo</span>? ` ) ;
2020-10-16 09:02:12 +02:00
done ( ) ;
} ) ) ;
} ) ;
describe ( "A outgoing groupchat Message" , function ( ) {
it ( "can be styled with span XEP-0393 message styling hints that contain mentions" ,
2021-01-29 11:08:28 +01:00
mock . initConverse ( [ 'chatBoxesFetched' ] , { } ,
2020-10-16 09:02:12 +02:00
async function ( done , _converse ) {
const muc _jid = 'lounge@montague.lit' ;
await mock . openAndEnterChatRoom ( _converse , muc _jid , 'romeo' ) ;
const view = _converse . api . chatviews . get ( muc _jid ) ;
const msg _text = "This *message mentions romeo*" ;
const msg = $msg ( {
from : 'lounge@montague.lit/gibson' ,
id : u . getUniqueId ( ) ,
to : 'romeo@montague.lit' ,
type : 'groupchat'
} ) . c ( 'body' ) . t ( msg _text ) . up ( )
. c ( 'reference' , { 'xmlns' : 'urn:xmpp:reference:0' , 'begin' : '23' , 'end' : '29' , 'type' : 'mention' , 'uri' : 'xmpp:romeo@montague.lit' } ) . nodeTree ;
await view . model . handleMessageStanza ( msg ) ;
2020-12-08 12:54:14 +01:00
const message = await u . waitUntil ( ( ) => view . querySelector ( '.chat-msg__text' ) ) ;
2020-10-16 09:02:12 +02:00
expect ( message . classList . length ) . toEqual ( 1 ) ;
2020-12-08 12:54:14 +01:00
const msg _el = Array . from ( view . querySelectorAll ( 'converse-chat-message-body' ) ) . pop ( ) ;
2020-10-16 09:02:12 +02:00
expect ( msg _el . innerText ) . toBe ( msg _text ) ;
await u . waitUntil ( ( ) => msg _el . innerHTML . replace ( /<!---->/g , '' ) ===
'This <span class="styling-directive">*</span><b>message mentions <span class="mention mention--self badge badge-info">romeo</span></b><span class="styling-directive">*</span>' ) ;
done ( ) ;
} ) ) ;
} ) ;