2013-11-02 12:37:38 +01:00
( function ( root , factory ) {
define ( [
2016-03-28 12:49:52 +02:00
"utils" ,
2017-02-14 15:08:39 +01:00
"converse-core" ,
2013-11-02 12:37:38 +01:00
"mock" ,
2017-04-05 11:01:31 +02:00
"test-utils"
2016-03-28 12:49:52 +02:00
] , factory ) ;
2016-12-20 10:30:20 +01:00
} ( this , function ( utils , converse , mock , test _utils ) {
2016-06-23 08:55:25 +02:00
"use strict" ;
2016-12-20 10:30:20 +01:00
var _ = converse . env . _ ;
var $ = converse . env . jQuery ;
var $msg = converse . env . $msg ;
var Strophe = converse . env . Strophe ;
var moment = converse . env . moment ;
2015-02-01 16:15:34 +01:00
2016-11-03 11:01:09 +01:00
return describe ( "Chatboxes" , function ( ) {
2015-10-07 10:57:11 +02:00
describe ( "A Chatbox" , function ( ) {
2014-01-19 06:02:18 +01:00
2017-02-15 22:03:02 +01:00
it ( "supports the /me command" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openControlBox ( ) ;
test _utils . openContactsPanel ( _converse ) ;
expect ( _converse . chatboxes . length ) . toEqual ( 1 ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var message = '/me is tired' ;
var msg = $msg ( {
from : sender _jid ,
to : _converse . connection . jid ,
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( message ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ;
_converse . chatboxes . onMessage ( msg ) ;
var view = _converse . chatboxviews . get ( sender _jid ) ;
expect ( _ . includes ( view . $el . find ( '.chat-msg-author' ) . text ( ) , '**Max Frankfurter' ) ) . toBeTruthy ( ) ;
expect ( view . $el . find ( '.chat-msg-content' ) . text ( ) ) . toBe ( ' is tired' ) ;
message = '/me is as well' ;
test _utils . sendMessage ( view , message ) ;
expect ( _ . includes ( view . $el . find ( '.chat-msg-author:last' ) . text ( ) , '**Max Mustermann' ) ) . toBeTruthy ( ) ;
expect ( view . $el . find ( '.chat-msg-content:last' ) . text ( ) ) . toBe ( ' is as well' ) ;
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "is created when you click on a roster item" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-11-03 11:01:09 +01:00
2015-10-25 18:49:35 +01:00
var i , $el , jid , chatboxview ;
2013-11-03 10:38:48 +01:00
// openControlBox was called earlier, so the controlbox is
2013-11-02 12:37:38 +01:00
// visible, but no other chat boxes have been created.
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxes . length ) . toEqual ( 1 ) ;
spyOn ( _converse . chatboxviews , 'trimChats' ) ;
2014-06-01 16:26:51 +02:00
expect ( $ ( "#conversejs .chatbox" ) . length ) . toBe ( 1 ) ; // Controlbox is open
2013-11-02 12:37:38 +01:00
2016-12-20 10:30:20 +01:00
var online _contacts = _converse . rosterview . $el . find ( 'dt.roster-group' ) . siblings ( 'dd.current-xmpp-contact' ) . find ( 'a.open-chat' ) ;
2013-11-02 12:37:38 +01:00
for ( i = 0 ; i < online _contacts . length ; i ++ ) {
$el = $ ( online _contacts [ i ] ) ;
2014-06-30 20:26:45 +02:00
jid = $el . text ( ) . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2013-11-02 12:37:38 +01:00
$el . click ( ) ;
2016-12-20 10:30:20 +01:00
chatboxview = _converse . chatboxviews . get ( jid ) ;
expect ( _converse . chatboxes . length ) . toEqual ( i + 2 ) ;
expect ( _converse . chatboxviews . trimChats ) . toHaveBeenCalled ( ) ;
2014-06-01 16:26:51 +02:00
// Check that new chat boxes are created to the left of the
// controlbox (but to the right of all existing chat boxes)
expect ( $ ( "#conversejs .chatbox" ) . length ) . toBe ( i + 2 ) ;
expect ( $ ( "#conversejs .chatbox" ) [ 1 ] . id ) . toBe ( chatboxview . model . get ( 'box_id' ) ) ;
2013-11-02 12:37:38 +01:00
}
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "can be trimmed to conserve space" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2013-11-02 12:37:38 +01:00
2015-10-25 18:49:35 +01:00
var i , $el , jid , chatbox , chatboxview , trimmedview ;
2014-06-01 17:57:03 +02:00
// openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created.
2016-12-20 10:30:20 +01:00
var trimmed _chatboxes = _converse . minimized _chats ;
expect ( _converse . chatboxes . length ) . toEqual ( 1 ) ;
spyOn ( _converse . chatboxviews , 'trimChats' ) ;
2017-04-05 11:01:31 +02:00
spyOn ( trimmed _chatboxes , 'addChat' ) . and . callThrough ( ) ;
spyOn ( trimmed _chatboxes , 'removeChat' ) . and . callThrough ( ) ;
2014-06-01 17:57:03 +02:00
expect ( $ ( "#conversejs .chatbox" ) . length ) . toBe ( 1 ) ; // Controlbox is open
2017-04-05 11:01:31 +02:00
_converse . rosterview . update ( ) ; // XXX: Hack to make sure $roster element is attaced.
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
2014-10-27 23:06:11 +01:00
// Test that they can be maximized again
2016-12-20 10:30:20 +01:00
var online _contacts = _converse . rosterview . $el . find ( 'dt.roster-group' ) . siblings ( 'dd.current-xmpp-contact' ) . find ( 'a.open-chat' ) ;
2014-10-27 23:06:11 +01:00
for ( i = 0 ; i < online _contacts . length ; i ++ ) {
$el = $ ( online _contacts [ i ] ) ;
2017-04-21 12:11:33 +02:00
jid = _ . trim ( $el . text ( ) ) . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2014-10-27 23:06:11 +01:00
$el . click ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxviews . trimChats ) . toHaveBeenCalled ( ) ;
2014-10-27 23:06:11 +01:00
2016-12-20 10:30:20 +01:00
chatboxview = _converse . chatboxviews . get ( jid ) ;
2017-04-05 11:01:31 +02:00
spyOn ( chatboxview , 'minimize' ) . and . callThrough ( ) ;
2014-10-27 23:06:11 +01:00
chatboxview . model . set ( { 'minimized' : true } ) ;
expect ( trimmed _chatboxes . addChat ) . toHaveBeenCalled ( ) ;
2016-03-09 12:16:15 +01:00
expect ( chatboxview . minimize ) . toHaveBeenCalled ( ) ;
2014-10-27 23:06:11 +01:00
}
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
return _converse . chatboxviews . keys ( ) . length > 1 ;
} , 500 )
} ) . then ( function ( ) {
2016-12-20 10:30:20 +01:00
var key = _converse . chatboxviews . keys ( ) [ 1 ] ;
2014-06-01 18:16:32 +02:00
trimmedview = trimmed _chatboxes . get ( key ) ;
2014-06-16 00:03:34 +02:00
chatbox = trimmedview . model ;
2017-04-05 11:01:31 +02:00
spyOn ( chatbox , 'maximize' ) . and . callThrough ( ) ;
spyOn ( trimmedview , 'restore' ) . and . callThrough ( ) ;
2014-06-16 00:03:34 +02:00
trimmedview . delegateEvents ( ) ;
2014-06-01 18:16:32 +02:00
trimmedview . $ ( "a.restore-chat" ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2014-06-16 00:03:34 +02:00
expect ( trimmedview . restore ) . toHaveBeenCalled ( ) ;
expect ( chatbox . maximize ) . toHaveBeenCalled ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxviews . trimChats ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-11-03 11:01:09 +01:00
} ) ;
} ) ) ;
2017-04-23 15:38:48 +02:00
it ( "can be opened in minimized mode initially" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var chat = _converse . api . chats . open ( sender _jid , {
minimized : true
} ) ;
var chatBoxView = _converse . chatboxviews . get ( sender _jid ) ;
expect ( chatBoxView . $el . is ( ':visible' ) ) . toBeFalsy ( ) ;
var minimized _chat = _converse . minimized _chats . get ( sender _jid ) ;
expect ( minimized _chat ) . toBeTruthy ( ) ;
expect ( minimized _chat . $el . is ( ':visible' ) ) . toBeTruthy ( ) ;
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "is focused if its already open and you click on its corresponding roster item" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2014-06-01 17:57:03 +02:00
2014-06-30 20:26:45 +02:00
var contact _jid = mock . cur _names [ 2 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2015-10-25 18:49:35 +01:00
var $el , jid , chatboxview , chatbox ;
2014-04-24 19:39:03 +02:00
// openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created.
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxes . length ) . toEqual ( 1 ) ;
chatbox = test _utils . openChatBoxFor ( _converse , contact _jid ) ;
chatboxview = _converse . chatboxviews . get ( contact _jid ) ;
2014-04-24 19:39:03 +02:00
spyOn ( chatboxview , 'focus' ) ;
2014-10-27 23:06:11 +01:00
// Test that they can be trimmed
2017-04-05 11:01:31 +02:00
_converse . rosterview . update ( ) ; // XXX: Hack to make sure $roster element is attaced.
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
2016-12-20 10:30:20 +01:00
$el = _converse . rosterview . $el . find ( 'a.open-chat:contains("' + chatbox . get ( 'fullname' ) + '")' ) ;
2014-10-27 23:06:11 +01:00
jid = $el . text ( ) . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
$el . click ( ) ;
2017-04-05 11:01:31 +02:00
setTimeout ( function ( ) {
expect ( _converse . chatboxes . length ) . toEqual ( 2 ) ;
expect ( chatboxview . focus ) . toHaveBeenCalled ( ) ;
done ( ) ;
} , 500 ) ;
2016-02-15 15:55:34 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "can be saved to, and retrieved from, browserStorage" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2014-04-24 19:39:03 +02:00
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
spyOn ( _converse . chatboxviews , 'trimChats' ) ;
2017-04-05 11:01:31 +02:00
test _utils . openControlBox ( ) ;
test _utils . openChatBoxes ( _converse , 6 ) ;
expect ( _converse . chatboxviews . trimChats ) . toHaveBeenCalled ( ) ;
// We instantiate a new ChatBoxes collection, which by default
// will be empty.
var newchatboxes = new _converse . ChatBoxes ( ) ;
expect ( newchatboxes . length ) . toEqual ( 0 ) ;
// The chatboxes will then be fetched from browserStorage inside the
// onConnected method
newchatboxes . onConnected ( ) ;
expect ( newchatboxes . length ) . toEqual ( 7 ) ;
// Check that the chatboxes items retrieved from browserStorage
// have the same attributes values as the original ones.
var attrs = [ 'id' , 'box_id' , 'visible' ] ;
var new _attrs , old _attrs ;
for ( var i = 0 ; i < attrs . length ; i ++ ) {
new _attrs = _ . map ( _ . map ( newchatboxes . models , 'attributes' ) , attrs [ i ] ) ;
old _attrs = _ . map ( _ . map ( _converse . chatboxes . models , 'attributes' ) , attrs [ i ] ) ;
expect ( _ . isEqual ( new _attrs , old _attrs ) ) . toEqual ( true ) ;
}
_converse . rosterview . render ( ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "can be closed by clicking a DOM element with class 'close-chatbox-button'" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
var chatbox = test _utils . openChatBoxes ( _converse , 1 ) [ 0 ] ,
controlview = _converse . chatboxviews . get ( 'controlbox' ) , // The controlbox is currently open
chatview = _converse . chatboxviews . get ( chatbox . get ( 'jid' ) ) ;
spyOn ( chatview , 'close' ) . and . callThrough ( ) ;
spyOn ( controlview , 'close' ) . and . callThrough ( ) ;
spyOn ( _converse , 'emit' ) ;
2016-11-03 11:01:09 +01:00
2017-04-05 11:01:31 +02:00
// We need to rebind all events otherwise our spy won't be called
controlview . delegateEvents ( ) ;
chatview . delegateEvents ( ) ;
2014-02-28 03:04:52 +01:00
2014-03-04 12:22:49 +01:00
controlview . $el . find ( '.close-chatbox-button' ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2014-05-27 18:34:22 +02:00
expect ( controlview . close ) . toHaveBeenCalled ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'chatBoxClosed' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
expect ( _converse . emit . calls . count ( ) , 1 ) ;
2014-03-04 12:22:49 +01:00
chatview . $el . find ( '.close-chatbox-button' ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2014-05-27 18:34:22 +02:00
expect ( chatview . close ) . toHaveBeenCalled ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'chatBoxClosed' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
expect ( _converse . emit . calls . count ( ) , 2 ) ;
done ( ) ;
2014-02-28 03:04:52 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "can be minimized by clicking a DOM element with class 'toggle-chatbox-button'" , mock . initConverseWithAsync ( function ( done , _converse ) {
var chatview ;
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
var chatbox = test _utils . openChatBoxes ( _converse , 1 ) [ 0 ] ,
trimmed _chatboxes = _converse . minimized _chats ,
trimmedview ;
chatview = _converse . chatboxviews . get ( chatbox . get ( 'jid' ) ) ;
spyOn ( chatview , 'minimize' ) . and . callThrough ( ) ;
spyOn ( _converse , 'emit' ) ;
// We need to rebind all events otherwise our spy won't be called
chatview . delegateEvents ( ) ;
2013-11-02 12:37:38 +01:00
2014-03-04 19:16:39 +01:00
chatview . $el . find ( '.toggle-chatbox-button' ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2014-06-02 05:13:53 +02:00
expect ( chatview . minimize ) . toHaveBeenCalled ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'chatBoxMinimized' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
expect ( _converse . emit . calls . count ( ) , 2 ) ;
2014-06-01 20:09:09 +02:00
expect ( chatview . $el . is ( ':visible' ) ) . toBeFalsy ( ) ;
2014-03-04 19:16:39 +01:00
expect ( chatview . model . get ( 'minimized' ) ) . toBeTruthy ( ) ;
chatview . $el . find ( '.toggle-chatbox-button' ) . click ( ) ;
2014-06-01 20:09:09 +02:00
trimmedview = trimmed _chatboxes . get ( chatview . model . get ( 'id' ) ) ;
2017-04-05 11:01:31 +02:00
spyOn ( trimmedview , 'restore' ) . and . callThrough ( ) ;
2014-06-16 00:03:34 +02:00
trimmedview . delegateEvents ( ) ;
2014-06-01 20:09:09 +02:00
trimmedview . $ ( "a.restore-chat" ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2014-06-16 00:03:34 +02:00
expect ( trimmedview . restore ) . toHaveBeenCalled ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'chatBoxMaximized' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
return chatview . $el . find ( '.chat-body' ) . is ( ':visible' ) ;
} , 500 )
} ) . then ( function ( ) {
2014-03-04 19:16:39 +01:00
expect ( chatview . $el . find ( '.toggle-chatbox-button' ) . hasClass ( 'icon-minus' ) ) . toBeTruthy ( ) ;
expect ( chatview . $el . find ( '.toggle-chatbox-button' ) . hasClass ( 'icon-plus' ) ) . toBeFalsy ( ) ;
expect ( chatview . model . get ( 'minimized' ) ) . toBeFalsy ( ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2014-03-04 19:16:39 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "will be removed from browserStorage when closed" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
spyOn ( _converse , 'emit' ) ;
spyOn ( _converse . chatboxviews , 'trimChats' ) ;
_converse . chatboxes . browserStorage . _clear ( ) ;
2014-03-04 19:16:39 +01:00
2014-08-08 22:06:01 +02:00
test _utils . closeControlBox ( ) ;
2017-04-05 11:01:31 +02:00
2016-12-20 10:30:20 +01:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'chatBoxClosed' , jasmine . any ( Object ) ) ;
expect ( _converse . chatboxes . length ) . toEqual ( 1 ) ;
expect ( _converse . chatboxes . pluck ( 'id' ) ) . toEqual ( [ 'controlbox' ] ) ;
test _utils . openChatBoxes ( _converse , 6 ) ;
expect ( _converse . chatboxviews . trimChats ) . toHaveBeenCalled ( ) ;
expect ( _converse . chatboxes . length ) . toEqual ( 7 ) ;
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'chatBoxOpened' , jasmine . any ( Object ) ) ;
test _utils . closeAllChatBoxes ( _converse ) ;
2017-04-05 11:01:31 +02:00
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxes . length ) . toEqual ( 1 ) ;
expect ( _converse . chatboxes . pluck ( 'id' ) ) . toEqual ( [ 'controlbox' ] ) ;
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'chatBoxClosed' , jasmine . any ( Object ) ) ;
var newchatboxes = new _converse . ChatBoxes ( ) ;
2014-02-28 03:04:52 +01:00
expect ( newchatboxes . length ) . toEqual ( 0 ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxes . pluck ( 'id' ) ) . toEqual ( [ 'controlbox' ] ) ;
2014-06-30 19:21:16 +02:00
// onConnected will fetch chatboxes in browserStorage, but
2014-02-28 03:04:52 +01:00
// because there aren't any open chatboxes, there won't be any
2014-06-30 19:21:16 +02:00
// in browserStorage either. XXX except for the controlbox
2014-02-28 03:04:52 +01:00
newchatboxes . onConnected ( ) ;
2014-04-18 17:42:11 +02:00
expect ( newchatboxes . length ) . toEqual ( 1 ) ;
expect ( newchatboxes . models [ 0 ] . id ) . toBe ( "controlbox" ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-11-03 11:01:09 +01:00
} ) ;
} ) ) ;
2013-11-02 12:37:38 +01:00
2015-10-07 10:57:11 +02:00
describe ( "A chat toolbar" , function ( ) {
2016-11-03 11:01:09 +01:00
2016-12-20 10:30:20 +01:00
it ( "can be found on each chat box" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-11-03 11:01:09 +01:00
2014-06-30 20:26:45 +02:00
var contact _jid = mock . cur _names [ 2 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var chatbox = _converse . chatboxes . get ( contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2013-11-03 21:28:44 +01:00
expect ( chatbox ) . toBeDefined ( ) ;
expect ( view ) . toBeDefined ( ) ;
var $toolbar = view . $el . find ( 'ul.chat-toolbar' ) ;
expect ( $toolbar . length ) . toBe ( 1 ) ;
2013-12-18 03:52:16 +01:00
expect ( $toolbar . children ( 'li' ) . length ) . toBe ( 3 ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "contains a button for inserting emoticons" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2013-11-03 21:28:44 +01:00
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
var contact _jid = mock . cur _names [ 2 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ,
view , $toolbar , $textarea ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
view = _converse . chatboxviews . get ( contact _jid ) ;
2016-02-15 15:55:34 +01:00
$toolbar = view . $el . find ( 'ul.chat-toolbar' ) ;
$textarea = view . $el . find ( 'textarea.chat-textarea' ) ;
expect ( $toolbar . children ( 'li.toggle-smiley' ) . length ) . toBe ( 1 ) ;
// Register spies
2017-04-05 11:01:31 +02:00
spyOn ( view , 'toggleEmoticonMenu' ) . and . callThrough ( ) ;
spyOn ( view , 'insertEmoticon' ) . and . callThrough ( ) ;
2016-02-15 15:55:34 +01:00
view . delegateEvents ( ) ; // We need to rebind all events otherwise our spy won't be called
2013-11-03 21:28:44 +01:00
$toolbar . children ( 'li.toggle-smiley' ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2013-11-03 21:28:44 +01:00
expect ( view . toggleEmoticonMenu ) . toHaveBeenCalled ( ) ;
var $menu = view . $el . find ( '.toggle-smiley ul' ) ;
var $items = $menu . children ( 'li' ) ;
expect ( $menu . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( $items . length ) . toBe ( 13 ) ;
expect ( $ ( $items [ 0 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( ':)' ) ;
expect ( $ ( $items [ 1 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( ';)' ) ;
expect ( $ ( $items [ 2 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( ':D' ) ;
expect ( $ ( $items [ 3 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( ':P' ) ;
expect ( $ ( $items [ 4 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( '8)' ) ;
expect ( $ ( $items [ 5 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( '>:)' ) ;
expect ( $ ( $items [ 6 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( ':S' ) ;
expect ( $ ( $items [ 7 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( ':\\' ) ;
expect ( $ ( $items [ 8 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( '>:(' ) ;
expect ( $ ( $items [ 9 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( ':(' ) ;
expect ( $ ( $items [ 10 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( ':O' ) ;
expect ( $ ( $items [ 11 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( '(^.^)b' ) ;
expect ( $ ( $items [ 12 ] ) . children ( 'a' ) . data ( 'emoticon' ) ) . toBe ( '<3' ) ;
2014-04-18 17:42:11 +02:00
$items . first ( ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2013-11-03 21:28:44 +01:00
expect ( view . insertEmoticon ) . toHaveBeenCalled ( ) ;
expect ( $textarea . val ( ) ) . toBe ( ':) ' ) ;
expect ( view . $el . find ( '.toggle-smiley ul' ) . is ( ':visible' ) ) . toBeFalsy ( ) ;
$toolbar . children ( 'li.toggle-smiley' ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2013-11-03 21:28:44 +01:00
expect ( view . toggleEmoticonMenu ) . toHaveBeenCalled ( ) ;
expect ( view . $el . find ( '.toggle-smiley ul' ) . is ( ':visible' ) ) . toBeTruthy ( ) ;
view . $el . find ( '.toggle-smiley ul' ) . children ( 'li' ) . last ( ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2013-11-03 21:28:44 +01:00
expect ( view . insertEmoticon ) . toHaveBeenCalled ( ) ;
expect ( view . $el . find ( '.toggle-smiley ul' ) . is ( ':visible' ) ) . toBeFalsy ( ) ;
expect ( $textarea . val ( ) ) . toBe ( ':) <3 ' ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2013-11-03 21:28:44 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "contains a button for starting an encrypted chat session" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2013-11-03 21:28:44 +01:00
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
// TODO: More tests can be added here...
var contact _jid = mock . cur _names [ 2 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
var $toolbar = view . $el . find ( 'ul.chat-toolbar' ) ;
expect ( $toolbar . children ( 'li.toggle-otr' ) . length ) . toBe ( 1 ) ;
// Register spies
spyOn ( view , 'toggleOTRMenu' ) . and . callThrough ( ) ;
view . delegateEvents ( ) ; // We need to rebind all events otherwise our spy won't be called
2013-11-03 21:28:44 +01:00
$toolbar . children ( 'li.toggle-otr' ) . click ( ) ;
2017-04-05 11:01:31 +02:00
2013-11-03 21:28:44 +01:00
expect ( view . toggleOTRMenu ) . toHaveBeenCalled ( ) ;
var $menu = view . $el . find ( '.toggle-otr ul' ) ;
expect ( $menu . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( $menu . children ( 'li' ) . length ) . toBe ( 2 ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2013-11-03 21:28:44 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "can contain a button for starting a call" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2013-12-18 03:52:16 +01:00
2014-04-24 19:14:37 +02:00
var view , callButton , $toolbar ;
2014-06-30 20:26:45 +02:00
var contact _jid = mock . cur _names [ 2 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
2014-04-24 19:14:37 +02:00
// First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons"
2016-12-20 10:30:20 +01:00
_converse . visible _toolbar _buttons . call = false ;
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
view = _converse . chatboxviews . get ( contact _jid ) ;
2014-04-24 19:14:37 +02:00
$toolbar = view . $el . find ( 'ul.chat-toolbar' ) ;
callButton = $toolbar . find ( '.toggle-call' ) ;
expect ( callButton . length ) . toBe ( 0 ) ;
2014-05-27 18:34:22 +02:00
view . close ( ) ;
2014-04-24 19:14:37 +02:00
// Now check that it's shown if enabled and that it emits
2014-07-14 23:29:08 +02:00
// callButtonClicked
2016-12-20 10:30:20 +01:00
_converse . visible _toolbar _buttons . call = true ; // enable the button
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
view = _converse . chatboxviews . get ( contact _jid ) ;
2014-04-24 19:14:37 +02:00
$toolbar = view . $el . find ( 'ul.chat-toolbar' ) ;
callButton = $toolbar . find ( '.toggle-call' ) ;
2013-12-18 03:52:16 +01:00
expect ( callButton . length ) . toBe ( 1 ) ;
2014-04-24 19:14:37 +02:00
callButton . click ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'callButtonClicked' , jasmine . any ( Object ) ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "can contain a button for clearing messages" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2013-12-18 03:52:16 +01:00
2014-04-24 19:14:37 +02:00
var view , clearButton , $toolbar ;
2014-06-30 20:26:45 +02:00
var contact _jid = mock . cur _names [ 2 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2014-04-24 19:14:37 +02:00
// First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons"
2016-12-20 10:30:20 +01:00
_converse . visible _toolbar _buttons . clear = false ;
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
view = _converse . chatboxviews . get ( contact _jid ) ;
view = _converse . chatboxviews . get ( contact _jid ) ;
2014-04-24 19:14:37 +02:00
$toolbar = view . $el . find ( 'ul.chat-toolbar' ) ;
clearButton = $toolbar . find ( '.toggle-clear' ) ;
expect ( clearButton . length ) . toBe ( 0 ) ;
2014-05-27 18:34:22 +02:00
view . close ( ) ;
2014-04-24 19:14:37 +02:00
// Now check that it's shown if enabled and that it calls
// clearMessages
2016-12-20 10:30:20 +01:00
_converse . visible _toolbar _buttons . clear = true ; // enable the button
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
view = _converse . chatboxviews . get ( contact _jid ) ;
2014-04-24 19:14:37 +02:00
$toolbar = view . $el . find ( 'ul.chat-toolbar' ) ;
clearButton = $toolbar . find ( '.toggle-clear' ) ;
expect ( clearButton . length ) . toBe ( 1 ) ;
spyOn ( view , 'clearMessages' ) ;
view . delegateEvents ( ) ; // We need to rebind all events otherwise our spy won't be called
clearButton . click ( ) ;
expect ( view . clearMessages ) . toHaveBeenCalled ( ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
} ) ;
2013-11-03 21:28:44 +01:00
2015-10-07 10:57:11 +02:00
describe ( "A Chat Message" , function ( ) {
2014-03-05 00:23:45 +01:00
2016-05-28 08:35:16 +02:00
describe ( "when received from someone else" , function ( ) {
2017-04-05 11:01:31 +02:00
it ( "can be received which will open a chatbox and be displayed inside it" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
spyOn ( _converse , 'emit' ) ;
var message = 'This is a received message' ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msg = $msg ( {
from : sender _jid ,
to : _converse . connection . jid ,
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( message ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ;
2016-11-03 11:01:09 +01:00
2017-04-05 11:01:31 +02:00
// We don't already have an open chatbox for this user
expect ( _converse . chatboxes . get ( sender _jid ) ) . not . toBeDefined ( ) ;
2016-05-28 10:55:03 +02:00
// onMessage is a handler for received XMPP messages
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
2016-05-28 10:55:03 +02:00
// Check that the chatbox and its view now exist
2016-12-20 10:30:20 +01:00
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
2016-05-28 10:55:03 +02:00
expect ( chatbox ) . toBeDefined ( ) ;
expect ( chatboxview ) . toBeDefined ( ) ;
// Check that the message was received and check the message parameters
expect ( chatbox . messages . length ) . toEqual ( 1 ) ;
var msg _obj = chatbox . messages . models [ 0 ] ;
expect ( msg _obj . get ( 'message' ) ) . toEqual ( message ) ;
expect ( msg _obj . get ( 'fullname' ) ) . toEqual ( mock . cur _names [ 0 ] ) ;
expect ( msg _obj . get ( 'sender' ) ) . toEqual ( 'them' ) ;
expect ( msg _obj . get ( 'delayed' ) ) . toEqual ( false ) ;
// Now check that the message appears inside the chatbox in the DOM
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
var msg _txt = $chat _content . find ( '.chat-message' ) . find ( '.chat-msg-content' ) . text ( ) ;
expect ( msg _txt ) . toEqual ( message ) ;
var sender _txt = $chat _content . find ( 'span.chat-msg-them' ) . text ( ) ;
expect ( sender _txt . match ( /^[0-9][0-9]:[0-9][0-9] / ) ) . toBeTruthy ( ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-11-03 11:01:09 +01:00
} ) ;
} ) ) ;
2016-05-28 10:55:03 +02:00
2017-02-01 10:14:36 +01:00
describe ( "who is not on the roster" , function ( ) {
2017-04-21 12:11:33 +02:00
it ( "will open a chatbox and be displayed inside it if allow_non_roster_messaging is true" , mock . initConverse ( function ( _converse ) {
_converse . allow _non _roster _messaging = false ;
2017-02-01 10:14:36 +01:00
2017-04-21 12:11:33 +02:00
spyOn ( _converse , 'emit' ) ;
2017-02-01 10:14:36 +01:00
var message = 'This is a received message from someone not on the roster' ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msg = $msg ( {
from : sender _jid ,
2017-04-21 12:11:33 +02:00
to : _converse . connection . jid ,
2017-02-01 10:14:36 +01:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( message ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ;
// We don't already have an open chatbox for this user
2017-04-21 12:11:33 +02:00
expect ( _converse . chatboxes . get ( sender _jid ) ) . not . toBeDefined ( ) ;
2017-02-01 10:14:36 +01:00
2017-04-05 11:01:31 +02:00
// onMessage is a handler for received XMPP messages
2017-04-21 12:11:33 +02:00
_converse . chatboxes . onMessage ( msg ) ;
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
2017-04-21 12:11:33 +02:00
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
2017-04-05 11:01:31 +02:00
expect ( chatbox ) . not . toBeDefined ( ) ;
// onMessage is a handler for received XMPP messages
2017-04-21 12:11:33 +02:00
_converse . allow _non _roster _messaging = true ;
_converse . chatboxes . onMessage ( msg ) ;
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
// Check that the chatbox and its view now exist
2017-04-21 12:11:33 +02:00
chatbox = _converse . chatboxes . get ( sender _jid ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
2017-04-05 11:01:31 +02:00
expect ( chatbox ) . toBeDefined ( ) ;
expect ( chatboxview ) . toBeDefined ( ) ;
// Check that the message was received and check the message parameters
expect ( chatbox . messages . length ) . toEqual ( 1 ) ;
var msg _obj = chatbox . messages . models [ 0 ] ;
expect ( msg _obj . get ( 'message' ) ) . toEqual ( message ) ;
expect ( msg _obj . get ( 'fullname' ) ) . toEqual ( sender _jid ) ;
expect ( msg _obj . get ( 'sender' ) ) . toEqual ( 'them' ) ;
expect ( msg _obj . get ( 'delayed' ) ) . toEqual ( false ) ;
// Now check that the message appears inside the chatbox in the DOM
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
var msg _txt = $chat _content . find ( '.chat-message' ) . find ( '.chat-msg-content' ) . text ( ) ;
expect ( msg _txt ) . toEqual ( message ) ;
var sender _txt = $chat _content . find ( 'span.chat-msg-them' ) . text ( ) ;
expect ( sender _txt . match ( /^[0-9][0-9]:[0-9][0-9] / ) ) . toBeTruthy ( ) ;
2017-02-01 10:14:36 +01:00
} ) ) ;
} ) ;
2016-06-23 08:55:25 +02:00
describe ( "and for which then an error message is received from the server" , function ( ) {
2016-11-03 11:01:09 +01:00
2016-12-20 10:30:20 +01:00
it ( "will have the error message displayed after itself" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-11-03 11:01:09 +01:00
2016-06-23 08:55:25 +02:00
// TODO: what could still be done for error
// messages... if the <error> element has type
// "cancel", then we know the messages wasn't sent,
// and can give the user a nicer indication of
// that.
2016-12-20 10:30:20 +01:00
/ * < m e s s a g e f r o m = " s c o t t y @ e n t e r p r i s e . c o m / _ c o n v e r s e . j s - 8 4 8 4 3 5 2 6 "
2016-06-23 08:55:25 +02:00
* to = "kirk@enterprise.com.com"
* type = "chat"
* id = "82bc02ce-9651-4336-baf0-fa04762ed8d2"
* xmlns = "jabber:client" >
* < body > yo < / b o d y >
* < active xmlns = "http://jabber.org/protocol/chatstates" / >
* < / m e s s a g e >
* /
var sender _jid = mock . cur _names [ 5 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
var fullname = _converse . xmppstatus . get ( 'fullname' ) ;
fullname = _ . isEmpty ( fullname ) ? _converse . bare _jid : fullname ;
_converse . api . chats . open ( sender _jid ) ;
2016-06-23 08:55:25 +02:00
var msg _text = 'This message will not be sent, due to an error' ;
2016-12-20 10:30:20 +01:00
var view = _converse . chatboxviews . get ( sender _jid ) ;
2016-06-23 08:55:25 +02:00
var message = view . model . messages . create ( {
'msgid' : '82bc02ce-9651-4336-baf0-fa04762ed8d2' ,
'fullname' : fullname ,
'sender' : 'me' ,
'time' : moment ( ) . format ( ) ,
'message' : msg _text
} ) ;
view . sendMessage ( message ) ;
var $chat _content = view . $el . find ( '.chat-content' ) ;
var msg _txt = $chat _content . find ( '.chat-message:last' ) . find ( '.chat-msg-content' ) . text ( ) ;
expect ( msg _txt ) . toEqual ( msg _text ) ;
// We send another message, for which an error will
// not be received, to test that errors appear
// after the relevant message.
msg _text = 'This message will be sent, and not receive an error' ;
message = view . model . messages . create ( {
'msgid' : '6fcdeee3-000f-4ce8-a17e-9ce28f0ae104' ,
'fullname' : fullname ,
'sender' : 'me' ,
'time' : moment ( ) . format ( ) ,
'message' : msg _text
} ) ;
view . sendMessage ( message ) ;
msg _txt = $chat _content . find ( '.chat-message:last' ) . find ( '.chat-msg-content' ) . text ( ) ;
expect ( msg _txt ) . toEqual ( msg _text ) ;
/ * < m e s s a g e x m l n s = " j a b b e r : c l i e n t "
2016-12-20 10:30:20 +01:00
* to = "scotty@enterprise.com/_converse.js-84843526"
2016-06-23 08:55:25 +02:00
* type = "error"
* id = "82bc02ce-9651-4336-baf0-fa04762ed8d2"
* from = "kirk@enterprise.com.com" >
* < error type = "cancel" >
* < remote - server - not - found xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" / >
* < text xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" > Server - to - server connection failed : Connecting failed : connection timeout < / t e x t >
* < / e r r o r >
* < / m e s s a g e >
* /
var error _txt = 'Server-to-server connection failed: Connecting failed: connection timeout' ;
var stanza = $msg ( {
2016-12-20 10:30:20 +01:00
'to' : _converse . connection . jid ,
2016-06-23 08:55:25 +02:00
'type' : 'error' ,
'id' : '82bc02ce-9651-4336-baf0-fa04762ed8d2' ,
'from' : sender _jid
} )
. c ( 'error' , { 'type' : 'cancel' } )
. c ( 'remote-server-not-found' , { 'xmlns' : "urn:ietf:params:xml:ns:xmpp-stanzas" } ) . up ( )
. c ( 'text' , { 'xmlns' : "urn:ietf:params:xml:ns:xmpp-stanzas" } )
. t ( 'Server-to-server connection failed: Connecting failed: connection timeout' ) ;
2016-12-20 10:30:20 +01:00
_converse . connection . _dataRecv ( test _utils . createRequest ( stanza ) ) ;
2016-06-23 08:55:25 +02:00
expect ( $chat _content . find ( '.chat-error' ) . text ( ) ) . toEqual ( error _txt ) ;
/ * I n c o m i n g e r r o r m e s s a g e s t h a t a r e n o t t i e d t o a
* certain show message ( via the msgid attribute ) ,
* are not shown at all . The reason for this is
* that we may get error messages for chat state
* notifications as well .
* /
stanza = $msg ( {
2016-12-20 10:30:20 +01:00
'to' : _converse . connection . jid ,
2016-06-23 08:55:25 +02:00
'type' : 'error' ,
'id' : 'some-other-unused-id' ,
'from' : sender _jid
} )
. c ( 'error' , { 'type' : 'cancel' } )
. c ( 'remote-server-not-found' , { 'xmlns' : "urn:ietf:params:xml:ns:xmpp-stanzas" } ) . up ( )
. c ( 'text' , { 'xmlns' : "urn:ietf:params:xml:ns:xmpp-stanzas" } )
. t ( 'Server-to-server connection failed: Connecting failed: connection timeout' ) ;
2016-12-20 10:30:20 +01:00
_converse . connection . _dataRecv ( test _utils . createRequest ( stanza ) ) ;
2016-06-23 08:55:25 +02:00
expect ( $chat _content . find ( '.chat-error' ) . length ) . toEqual ( 1 ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-06-23 08:55:25 +02:00
} ) ;
2017-04-05 11:01:31 +02:00
it ( "will cause the chat area to be scrolled down only if it was at the bottom already" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-11-03 11:01:09 +01:00
2016-05-28 10:55:03 +02:00
var message = 'This message is received while the chat area is scrolled up' ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
2017-04-05 11:01:31 +02:00
spyOn ( chatboxview , 'scrollDown' ) . and . callThrough ( ) ;
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
/ * C r e a t e e n o u g h m e s s a g e s s o t h a t t h e r e ' s a
* scrollbar .
* /
for ( var i = 0 ; i < 20 ; i ++ ) {
_converse . chatboxes . onMessage ( $msg ( {
from : sender _jid ,
to : _converse . connection . jid ,
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( 'Message: ' + i ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ) ;
}
test _utils . waitUntil ( function ( ) {
return chatboxview . $content . scrollTop ( ) ;
} , 300 )
. then ( function ( ) {
return test _utils . waitUntil ( function ( ) {
return ! chatboxview . model . get ( 'auto_scrolled' ) ;
} , 300 )
} ) . then ( function ( ) {
2016-05-28 10:55:03 +02:00
chatboxview . $content . scrollTop ( 0 ) ;
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
return chatboxview . model . get ( 'scrolled' ) ;
} , 900 )
} ) . then ( function ( ) {
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( $msg ( {
2016-05-28 10:55:03 +02:00
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2016-05-28 10:55:03 +02:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( message ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ) ;
2017-04-05 11:01:31 +02:00
2016-05-28 10:55:03 +02:00
// Now check that the message appears inside the chatbox in the DOM
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
var msg _txt = $chat _content . find ( '.chat-message:last' ) . find ( '.chat-msg-content' ) . text ( ) ;
expect ( msg _txt ) . toEqual ( message ) ;
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
return chatboxview . $ ( '.new-msgs-indicator' ) . is ( ':visible' ) ;
} , 300 )
} ) . then ( function ( ) {
expect ( chatboxview . model . get ( 'scrolled' ) ) . toBe ( true ) ;
2016-05-28 10:55:03 +02:00
expect ( chatboxview . $content . scrollTop ( ) ) . toBe ( 0 ) ;
expect ( chatboxview . $ ( '.new-msgs-indicator' ) . is ( ':visible' ) ) . toBeTruthy ( ) ;
// Scroll down again
chatboxview . $content . scrollTop ( chatboxview . $content [ 0 ] . scrollHeight ) ;
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
return ! chatboxview . $ ( '.new-msgs-indicator' ) . is ( ':visible' ) ;
} , 300 )
} ) . then ( done ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "is ignored if it's intended for a different resource and filter_by_resource is set to true" ,
mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-05-28 10:55:03 +02:00
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
// Send a message from a different resource
var message , sender _jid , msg ;
spyOn ( _converse , 'log' ) ;
spyOn ( _converse . chatboxes , 'getChatBox' ) . and . callThrough ( ) ;
2016-12-20 10:30:20 +01:00
_converse . filter _by _resource = true ;
2016-05-28 10:55:03 +02:00
sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
msg = $msg ( {
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . bare _jid + "/some-other-resource" ,
2016-05-28 10:55:03 +02:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( "This message will not be shown" ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2017-04-05 11:01:31 +02:00
2016-12-20 10:30:20 +01:00
expect ( _converse . log ) . toHaveBeenCalledWith (
2016-05-28 10:55:03 +02:00
"onMessage: Ignoring incoming message intended for a different resource: dummy@localhost/some-other-resource" , "info" ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxes . getChatBox ) . not . toHaveBeenCalled ( ) ;
_converse . filter _by _resource = false ;
2017-04-05 11:01:31 +02:00
2016-05-28 10:55:03 +02:00
message = "This message sent to a different resource will be shown" ;
msg = $msg ( {
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . bare _jid + "/some-other-resource" ,
2016-05-28 10:55:03 +02:00
type : 'chat' ,
id : '134234623462346'
} ) . c ( 'body' ) . t ( message ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2017-04-05 11:01:31 +02:00
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxes . getChatBox ) . toHaveBeenCalled ( ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
2016-05-28 10:55:03 +02:00
var $chat _content = chatboxview . $el . find ( '.chat-content:last' ) ;
var msg _txt = $chat _content . find ( '.chat-message' ) . find ( '.chat-msg-content' ) . text ( ) ;
expect ( msg _txt ) . toEqual ( message ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-05-28 10:55:03 +02:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-05-28 08:35:16 +02:00
} ) ;
2016-12-20 10:30:20 +01:00
it ( "is ignored if it's a malformed headline message" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-11-03 11:01:09 +01:00
2016-03-28 12:49:52 +02:00
/ * I d e a l l y w e w o u l d n ' t h a v e t o f i l t e r o u t h e a d l i n e
* messages , but Prosody gives them the wrong 'type' : (
* /
2016-12-20 10:30:20 +01:00
sinon . spy ( _converse , 'log' ) ;
sinon . spy ( _converse . chatboxes , 'getChatBox' ) ;
2016-03-28 12:49:52 +02:00
sinon . spy ( utils , 'isHeadlineMessage' ) ;
var msg = $msg ( {
from : 'localhost' ,
2016-12-20 10:30:20 +01:00
to : _converse . bare _jid ,
2016-03-28 12:49:52 +02:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( "This headline message will not be shown" ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
expect ( _converse . log . calledWith (
2016-03-28 12:49:52 +02:00
"onMessage: Ignoring incoming headline message sent with type 'chat' from JID: localhost" ,
"info"
) ) . toBeTruthy ( ) ;
expect ( utils . isHeadlineMessage . called ) . toBeTruthy ( ) ;
expect ( utils . isHeadlineMessage . returned ( true ) ) . toBeTruthy ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . chatboxes . getChatBox . called ) . toBeFalsy ( ) ;
2016-03-28 12:49:52 +02:00
// Remove sinon spies
2016-12-20 10:30:20 +01:00
_converse . log . restore ( ) ;
_converse . chatboxes . getChatBox . restore ( ) ;
2016-03-28 12:49:52 +02:00
utils . isHeadlineMessage . restore ( ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "can be a carbon message, as defined in XEP-0280" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2015-07-02 11:23:52 +02:00
2015-07-03 11:36:30 +02:00
// Send a message from a different resource
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'log' ) ;
2015-07-03 11:36:30 +02:00
var msgtext = 'This is a carbon message' ;
var sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msg = $msg ( {
2017-01-31 23:18:26 +01:00
'from' : sender _jid ,
2015-07-03 11:36:30 +02:00
'id' : ( new Date ( ) ) . getTime ( ) ,
2016-12-20 10:30:20 +01:00
'to' : _converse . connection . jid ,
2015-07-03 11:36:30 +02:00
'type' : 'chat' ,
'xmlns' : 'jabber:client'
} ) . c ( 'received' , { 'xmlns' : 'urn:xmpp:carbons:2' } )
. c ( 'forwarded' , { 'xmlns' : 'urn:xmpp:forward:0' } )
. c ( 'message' , {
'xmlns' : 'jabber:client' ,
'from' : sender _jid ,
2016-12-20 10:30:20 +01:00
'to' : _converse . bare _jid + '/another-resource' ,
2015-07-03 11:36:30 +02:00
'type' : 'chat'
} ) . c ( 'body' ) . t ( msgtext ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2015-07-03 11:36:30 +02:00
// Check that the chatbox and its view now exist
2016-12-20 10:30:20 +01:00
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
2015-07-03 11:36:30 +02:00
expect ( chatbox ) . toBeDefined ( ) ;
expect ( chatboxview ) . toBeDefined ( ) ;
// Check that the message was received and check the message parameters
expect ( chatbox . messages . length ) . toEqual ( 1 ) ;
var msg _obj = chatbox . messages . models [ 0 ] ;
expect ( msg _obj . get ( 'message' ) ) . toEqual ( msgtext ) ;
2016-03-23 23:27:25 +01:00
expect ( msg _obj . get ( 'fullname' ) ) . toEqual ( mock . cur _names [ 1 ] ) ;
2015-07-03 11:36:30 +02:00
expect ( msg _obj . get ( 'sender' ) ) . toEqual ( 'them' ) ;
expect ( msg _obj . get ( 'delayed' ) ) . toEqual ( false ) ;
// Now check that the message appears inside the chatbox in the DOM
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
2015-10-28 09:52:19 +01:00
var msg _txt = $chat _content . find ( '.chat-message' ) . find ( '.chat-msg-content' ) . text ( ) ;
2015-07-03 11:36:30 +02:00
expect ( msg _txt ) . toEqual ( msgtext ) ;
2015-10-28 09:52:19 +01:00
var sender _txt = $chat _content . find ( 'span.chat-msg-them' ) . text ( ) ;
2015-07-03 11:36:30 +02:00
expect ( sender _txt . match ( /^[0-9][0-9]:[0-9][0-9] / ) ) . toBeTruthy ( ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "can be a carbon message that this user sent from a different client, as defined in XEP-0280" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2015-07-03 11:36:30 +02:00
2015-07-03 11:55:13 +02:00
// Send a message from a different resource
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'log' ) ;
2015-07-03 11:55:13 +02:00
var msgtext = 'This is a sent carbon message' ;
var recipient _jid = mock . cur _names [ 5 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msg = $msg ( {
2016-12-20 10:30:20 +01:00
'from' : _converse . bare _jid ,
2015-07-03 11:55:13 +02:00
'id' : ( new Date ( ) ) . getTime ( ) ,
2016-12-20 10:30:20 +01:00
'to' : _converse . connection . jid ,
2015-07-03 11:55:13 +02:00
'type' : 'chat' ,
'xmlns' : 'jabber:client'
} ) . c ( 'sent' , { 'xmlns' : 'urn:xmpp:carbons:2' } )
. c ( 'forwarded' , { 'xmlns' : 'urn:xmpp:forward:0' } )
. c ( 'message' , {
'xmlns' : 'jabber:client' ,
2016-12-20 10:30:20 +01:00
'from' : _converse . bare _jid + '/another-resource' ,
2015-07-03 11:55:13 +02:00
'to' : recipient _jid ,
'type' : 'chat'
} ) . c ( 'body' ) . t ( msgtext ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2015-07-03 11:55:13 +02:00
// Check that the chatbox and its view now exist
2016-12-20 10:30:20 +01:00
var chatbox = _converse . chatboxes . get ( recipient _jid ) ;
var chatboxview = _converse . chatboxviews . get ( recipient _jid ) ;
2015-07-03 11:55:13 +02:00
expect ( chatbox ) . toBeDefined ( ) ;
expect ( chatboxview ) . toBeDefined ( ) ;
// Check that the message was received and check the message parameters
expect ( chatbox . messages . length ) . toEqual ( 1 ) ;
var msg _obj = chatbox . messages . models [ 0 ] ;
expect ( msg _obj . get ( 'message' ) ) . toEqual ( msgtext ) ;
2017-03-09 12:38:54 +01:00
expect ( msg _obj . get ( 'fullname' ) ) . toEqual ( _converse . xmppstatus . get ( 'fullname' ) ) ;
2015-07-03 11:55:13 +02:00
expect ( msg _obj . get ( 'sender' ) ) . toEqual ( 'me' ) ;
expect ( msg _obj . get ( 'delayed' ) ) . toEqual ( false ) ;
// Now check that the message appears inside the chatbox in the DOM
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
2015-10-28 09:52:19 +01:00
var msg _txt = $chat _content . find ( '.chat-message' ) . find ( '.chat-msg-content' ) . text ( ) ;
2015-07-03 11:55:13 +02:00
expect ( msg _txt ) . toEqual ( msgtext ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-21 12:11:33 +02:00
it ( "will be discarded if it's a malicious message meant to look like a carbon copy" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2017-01-31 23:18:26 +01:00
test _utils . openControlBox ( ) ;
2017-04-21 12:11:33 +02:00
test _utils . openContactsPanel ( _converse ) ;
2017-01-31 23:18:26 +01:00
/ * < m e s s a g e f r o m = " m a l l o r y @ e v i l . e x a m p l e " t o = " b @ x m p p . e x a m p l e " >
* < received xmlns = 'urn:xmpp:carbons:2' >
* < forwarded xmlns = 'urn:xmpp:forward:0' >
* < message from = "alice@xmpp.example" to = "bob@xmpp.example/client1" >
* < body > Please come to Creepy Valley tonight , alone ! < / b o d y >
* < / m e s s a g e >
* < / f o r w a r d e d >
* < / r e c e i v e d >
* < / m e s s a g e >
* /
2017-04-21 12:11:33 +02:00
spyOn ( _converse , 'log' ) ;
2017-01-31 23:18:26 +01:00
var msgtext = 'Please come to Creepy Valley tonight, alone!' ;
var sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var impersonated _jid = mock . cur _names [ 2 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msg = $msg ( {
'from' : sender _jid ,
'id' : ( new Date ( ) ) . getTime ( ) ,
2017-04-21 12:11:33 +02:00
'to' : _converse . connection . jid ,
2017-01-31 23:18:26 +01:00
'type' : 'chat' ,
'xmlns' : 'jabber:client'
} ) . c ( 'received' , { 'xmlns' : 'urn:xmpp:carbons:2' } )
. c ( 'forwarded' , { 'xmlns' : 'urn:xmpp:forward:0' } )
. c ( 'message' , {
'xmlns' : 'jabber:client' ,
'from' : impersonated _jid ,
2017-04-21 12:11:33 +02:00
'to' : _converse . connection . jid ,
2017-01-31 23:18:26 +01:00
'type' : 'chat'
} ) . c ( 'body' ) . t ( msgtext ) . tree ( ) ;
2017-04-21 12:11:33 +02:00
_converse . chatboxes . onMessage ( msg ) ;
2017-01-31 23:18:26 +01:00
// Check that chatbox for impersonated user is not created.
2017-04-21 12:11:33 +02:00
var chatbox = _converse . chatboxes . get ( impersonated _jid ) ;
2017-01-31 23:18:26 +01:00
expect ( chatbox ) . not . toBeDefined ( ) ;
// Check that the chatbox for the malicous user is not created
2017-04-21 12:11:33 +02:00
chatbox = _converse . chatboxes . get ( sender _jid ) ;
2017-01-31 23:18:26 +01:00
expect ( chatbox ) . not . toBeDefined ( ) ;
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "received for a minimized chat box will increment a counter on its header" ,
mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
var contact _name = mock . cur _names [ 0 ] ;
var contact _jid = contact _name . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
spyOn ( _converse , 'emit' ) . and . callThrough ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var chatview = _converse . chatboxviews . get ( contact _jid ) ;
2016-11-22 17:42:58 +01:00
expect ( chatview . $el . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( chatview . model . get ( 'minimized' ) ) . toBeFalsy ( ) ;
chatview . $el . find ( '.toggle-chatbox-button' ) . click ( ) ;
expect ( chatview . model . get ( 'minimized' ) ) . toBeTruthy ( ) ;
var message = 'This message is sent to a minimized chatbox' ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msg = $msg ( {
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2014-03-09 12:10:57 +01:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
2016-11-22 17:42:58 +01:00
} ) . c ( 'body' ) . t ( message ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2016-12-20 10:30:20 +01:00
var trimmed _chatboxes = _converse . minimized _chats ;
2016-11-22 17:42:58 +01:00
var trimmedview = trimmed _chatboxes . get ( contact _jid ) ;
var $count = trimmedview . $el . find ( '.chat-head-message-count' ) ;
expect ( chatview . $el . is ( ':visible' ) ) . toBeFalsy ( ) ;
expect ( trimmedview . model . get ( 'minimized' ) ) . toBeTruthy ( ) ;
expect ( $count . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( $count . html ( ) ) . toBe ( '1' ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage (
2016-11-22 17:42:58 +01:00
$msg ( {
from : mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2016-11-22 17:42:58 +01:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( 'This message is also sent to a minimized chatbox' ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( )
) ;
expect ( chatview . $el . is ( ':visible' ) ) . toBeFalsy ( ) ;
expect ( trimmedview . model . get ( 'minimized' ) ) . toBeTruthy ( ) ;
$count = trimmedview . $el . find ( '.chat-head-message-count' ) ;
expect ( $count . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( $count . html ( ) ) . toBe ( '2' ) ;
trimmedview . $el . find ( '.restore-chat' ) . click ( ) ;
expect ( trimmed _chatboxes . keys ( ) . length ) . toBe ( 0 ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-11-22 17:42:58 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "will indicate when it has a time difference of more than a day between it and its predecessor" ,
mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
spyOn ( _converse , 'emit' ) ;
var contact _name = mock . cur _names [ 1 ] ;
var contact _jid = contact _name . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
test _utils . clearChatBoxMessages ( _converse , contact _jid ) ;
var one _day _ago = moment ( ) ;
one _day _ago . subtract ( 'days' , 1 ) ;
var message = 'This is a day old message' ;
var chatbox = _converse . chatboxes . get ( contact _jid ) ;
var chatboxview = _converse . chatboxviews . get ( contact _jid ) ;
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
var msg _obj ;
var msg _txt ;
var sender _txt ;
2015-01-09 09:02:35 +01:00
2017-04-05 11:01:31 +02:00
var msg = $msg ( {
from : contact _jid ,
to : _converse . connection . jid ,
type : 'chat' ,
id : one _day _ago . unix ( )
} ) . c ( 'body' ) . t ( message ) . up ( )
. c ( 'delay' , { xmlns : 'urn:xmpp:delay' , from : 'localhost' , stamp : one _day _ago . format ( ) } )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ;
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
expect ( chatbox . messages . length ) . toEqual ( 1 ) ;
msg _obj = chatbox . messages . models [ 0 ] ;
expect ( msg _obj . get ( 'message' ) ) . toEqual ( message ) ;
expect ( msg _obj . get ( 'fullname' ) ) . toEqual ( contact _name ) ;
expect ( msg _obj . get ( 'sender' ) ) . toEqual ( 'them' ) ;
expect ( msg _obj . get ( 'delayed' ) ) . toEqual ( true ) ;
msg _txt = $chat _content . find ( '.chat-message' ) . find ( '.chat-msg-content' ) . text ( ) ;
expect ( msg _txt ) . toEqual ( message ) ;
sender _txt = $chat _content . find ( 'span.chat-msg-them' ) . text ( ) ;
expect ( sender _txt . match ( /^[0-9][0-9]:[0-9][0-9] / ) ) . toBeTruthy ( ) ;
var $time = $chat _content . find ( 'time' ) ;
expect ( $time . length ) . toEqual ( 1 ) ;
expect ( $time . attr ( 'class' ) ) . toEqual ( 'chat-info chat-date' ) ;
expect ( $time . data ( 'isodate' ) ) . toEqual ( moment ( one _day _ago . startOf ( 'day' ) ) . format ( ) ) ;
expect ( $time . text ( ) ) . toEqual ( moment ( one _day _ago . startOf ( 'day' ) ) . format ( "dddd MMM Do YYYY" ) ) ;
message = 'This is a current message' ;
msg = $msg ( {
from : contact _jid ,
to : _converse . connection . jid ,
type : 'chat' ,
id : new Date ( ) . getTime ( )
} ) . c ( 'body' ) . t ( message ) . up ( )
. c ( 'active' , { 'xmlns' : 'http://jabber.org/protocol/chatstates' } ) . tree ( ) ;
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
// Check that there is a <time> element, with the required
// props.
$time = $chat _content . find ( 'time' ) ;
expect ( $time . length ) . toEqual ( 2 ) ; // There are now two time elements
$time = $chat _content . find ( 'time:last' ) ; // We check the last one
var message _date = new Date ( ) ;
expect ( $time . attr ( 'class' ) ) . toEqual ( 'chat-info chat-date' ) ;
expect ( $time . data ( 'isodate' ) ) . toEqual ( moment ( message _date ) . startOf ( 'day' ) . format ( ) ) ;
expect ( $time . text ( ) ) . toEqual ( moment ( message _date ) . startOf ( 'day' ) . format ( "dddd MMM Do YYYY" ) ) ;
// Normal checks for the 2nd message
expect ( chatbox . messages . length ) . toEqual ( 2 ) ;
msg _obj = chatbox . messages . models [ 1 ] ;
expect ( msg _obj . get ( 'message' ) ) . toEqual ( message ) ;
expect ( msg _obj . get ( 'fullname' ) ) . toEqual ( contact _name ) ;
expect ( msg _obj . get ( 'sender' ) ) . toEqual ( 'them' ) ;
expect ( msg _obj . get ( 'delayed' ) ) . toEqual ( false ) ;
msg _txt = $chat _content . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) . text ( ) ;
expect ( msg _txt ) . toEqual ( message ) ;
sender _txt = $chat _content . find ( 'span.chat-msg-them' ) . last ( ) . text ( ) ;
expect ( sender _txt . match ( /^[0-9][0-9]:[0-9][0-9] / ) ) . toBeTruthy ( ) ;
done ( ) ;
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "can be sent from a chatbox, and will appear inside it" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2013-11-03 12:24:18 +01:00
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
2014-06-30 20:26:45 +02:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'chatBoxFocused' , jasmine . any ( Object ) ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2015-04-02 02:01:53 +02:00
var message = 'This message is sent from this chatbox' ;
2017-04-05 11:01:31 +02:00
spyOn ( view , 'sendMessage' ) . and . callThrough ( ) ;
2015-04-02 02:01:53 +02:00
test _utils . sendMessage ( view , message ) ;
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
expect ( view . model . messages . length , 2 ) ;
2017-04-05 11:01:31 +02:00
expect ( _converse . emit . calls . mostRecent ( ) . args , [ 'messageSend' , message ] ) ;
2015-10-28 09:52:19 +01:00
expect ( view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) . text ( ) ) . toEqual ( message ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "is sanitized to prevent Javascript injection attacks" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2013-12-18 03:15:27 +01:00
2014-06-30 20:26:45 +02:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2014-03-05 03:29:10 +01:00
var message = '<p>This message contains <em>some</em> <b>markup</b></p>' ;
2017-04-05 11:01:31 +02:00
spyOn ( view , 'sendMessage' ) . and . callThrough ( ) ;
2014-08-08 22:06:01 +02:00
test _utils . sendMessage ( view , message ) ;
2013-12-18 03:15:27 +01:00
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
2015-10-28 09:52:19 +01:00
var msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
2014-03-05 03:29:10 +01:00
expect ( msg . text ( ) ) . toEqual ( message ) ;
expect ( msg . html ( ) ) . toEqual ( '<p>This message contains <em>some</em> <b>markup</b></p>' ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "should display emoticons correctly" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2014-03-05 03:29:10 +01:00
2014-06-30 20:26:45 +02:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2014-05-19 16:06:11 +02:00
var messages = [ ':)' , ';)' , ':D' , ':P' , '8)' , '>:)' , ':S' , ':\\' , '>:(' , ':(' , ':O' , '(^.^)b' , '<3' ] ;
2014-05-19 16:12:55 +02:00
var emoticons = [
'<span class="emoticon icon-smiley"></span>' , '<span class="emoticon icon-wink"></span>' ,
'<span class="emoticon icon-grin"></span>' , '<span class="emoticon icon-tongue"></span>' ,
'<span class="emoticon icon-cool"></span>' , '<span class="emoticon icon-evil"></span>' ,
'<span class="emoticon icon-confused"></span>' , '<span class="emoticon icon-wondering"></span>' ,
'<span class="emoticon icon-angry"></span>' , '<span class="emoticon icon-sad"></span>' ,
'<span class="emoticon icon-shocked"></span>' , '<span class="emoticon icon-thumbs-up"></span>' ,
'<span class="emoticon icon-heart"></span>'
] ;
2017-04-05 11:01:31 +02:00
spyOn ( view , 'sendMessage' ) . and . callThrough ( ) ;
2014-05-19 16:06:11 +02:00
for ( var i = 0 ; i < messages . length ; i ++ ) {
2014-05-19 16:12:55 +02:00
var message = messages [ i ] ;
2014-08-08 22:06:01 +02:00
test _utils . sendMessage ( view , message ) ;
2014-05-19 16:12:55 +02:00
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
2015-10-28 09:52:19 +01:00
var msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
2014-05-19 16:12:55 +02:00
expect ( msg . html ( ) ) . toEqual ( emoticons [ i ] ) ;
2014-05-19 16:06:11 +02:00
}
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "can contain hyperlinks, which will be clickable" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2014-03-05 03:29:10 +01:00
2016-05-28 13:13:49 +02:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2016-05-28 13:13:49 +02:00
var message = 'This message contains a hyperlink: www.opkode.com' ;
2017-04-05 11:01:31 +02:00
spyOn ( view , 'sendMessage' ) . and . callThrough ( ) ;
test _utils . sendMessage ( view , message ) ;
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
var msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
expect ( msg . text ( ) ) . toEqual ( message ) ;
expect ( msg . html ( ) ) . toEqual ( 'This message contains a hyperlink: <a target="_blank" rel="noopener" href="http://www.opkode.com">www.opkode.com</a>' ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "will have properly escaped URLs" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-05-28 13:13:49 +02:00
var message , msg ;
2014-06-30 20:26:45 +02:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2017-04-05 11:01:31 +02:00
spyOn ( view , 'sendMessage' ) . and . callThrough ( ) ;
message = "http://www.opkode.com/'onmouseover='alert(1)'whatever" ;
test _utils . sendMessage ( view , message ) ;
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
expect ( msg . text ( ) ) . toEqual ( message ) ;
expect ( msg . html ( ) ) . toEqual ( '<a target="_blank" rel="noopener" href="http://www.opkode.com/%27onmouseover=%27alert%281%29%27whatever">http://www.opkode.com/\'onmouseover=\'alert(1)\'whatever</a>' ) ;
2014-03-05 03:29:10 +01:00
2017-04-05 11:01:31 +02:00
message = 'http://www.opkode.com/"onmouseover="alert(1)"whatever' ;
test _utils . sendMessage ( view , message ) ;
2014-03-05 03:29:10 +01:00
2017-04-05 11:01:31 +02:00
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
expect ( msg . text ( ) ) . toEqual ( message ) ;
expect ( msg . html ( ) ) . toEqual ( '<a target="_blank" rel="noopener" href="http://www.opkode.com/%22onmouseover=%22alert%281%29%22whatever">http://www.opkode.com/"onmouseover="alert(1)"whatever</a>' ) ;
2014-03-09 04:51:21 +01:00
2017-04-05 11:01:31 +02:00
message = "https://en.wikipedia.org/wiki/Ender's_Game" ;
test _utils . sendMessage ( view , message ) ;
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
expect ( msg . text ( ) ) . toEqual ( message ) ;
expect ( msg . html ( ) ) . toEqual ( '<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">https://en.wikipedia.org/wiki/Ender\'s_Game</a>' ) ;
message = "https://en.wikipedia.org/wiki/Ender%27s_Game" ;
test _utils . sendMessage ( view , message ) ;
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
expect ( msg . text ( ) ) . toEqual ( message ) ;
expect ( msg . html ( ) ) . toEqual ( '<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">https://en.wikipedia.org/wiki/Ender%27s_Game</a>' ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "will render images from their URLs" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-05-28 13:13:49 +02:00
if ( /PhantomJS/ . test ( window . navigator . userAgent ) ) {
// Doesn't work when running tests in PhantomJS, since
// the page is loaded via file:///
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-05-28 13:13:49 +02:00
return ;
}
2017-04-04 16:04:44 +02:00
test _utils . createContacts ( _converse , 'current' ) ;
var base _url = document . URL . split ( window . location . pathname ) [ 0 ] ;
var message = base _url + "/logo/conversejs.svg" ;
2016-05-28 13:13:49 +02:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2017-04-05 11:01:31 +02:00
spyOn ( view , 'sendMessage' ) . and . callThrough ( ) ;
test _utils . sendMessage ( view , message ) ;
test _utils . waitUntil ( function ( ) {
return view . $el . find ( '.chat-content' ) . find ( '.chat-message img' ) . length ;
2017-04-19 14:41:42 +02:00
} , 500 ) . then ( function ( ) {
2016-05-28 13:13:49 +02:00
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
var msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
expect ( msg . html ( ) ) . toEqual ( '<img src="' + message + '" class="chat-image">' ) ;
2017-04-04 16:04:44 +02:00
message += "?param1=val1¶m2=val2" ;
2017-04-04 16:05:50 +02:00
test _utils . sendMessage ( view , message ) ;
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
return view . $el . find ( '.chat-content' ) . find ( '.chat-message img' ) . length === 2 ;
2017-04-19 14:41:42 +02:00
} , 500 )
2017-04-05 11:01:31 +02:00
} ) . then ( function ( ) {
2017-04-04 16:05:50 +02:00
expect ( view . sendMessage ) . toHaveBeenCalled ( ) ;
var msg = view . $el . find ( '.chat-content' ) . find ( '.chat-message' ) . last ( ) . find ( '.chat-msg-content' ) ;
2017-04-04 16:04:44 +02:00
expect ( msg . html ( ) ) . toEqual ( '<img src="' + message . replace ( /&/g , '&' ) + '" class="chat-image">' ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2017-04-04 16:05:50 +02:00
} ) ;
} ) ) ;
2017-03-12 11:32:38 +01:00
it ( "will render the message time as configured" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
_converse . time _format = 'hh:mm' ;
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
var message = 'This message is sent from this chatbox' ;
test _utils . sendMessage ( view , message ) ;
var chatbox = _converse . chatboxes . get ( contact _jid ) ;
expect ( chatbox . messages . models . length , 1 ) ;
var msg _object = chatbox . messages . models [ 0 ] ;
var msg _time _author = view . $el . find ( '.chat-content' ) . find ( '.chat-message' )
. last ( ) . find ( '.chat-msg-author.chat-msg-me' ) . text ( ) ;
var msg _time _rendered = msg _time _author . split ( " " , 1 ) ;
var msg _time = moment ( msg _object . get ( 'time' ) ) . format ( _converse . time _format ) ;
expect ( msg _time _rendered [ 0 ] ) . toBe ( msg _time ) ;
} ) ) ;
2016-11-03 11:01:09 +01:00
} ) ;
2015-01-01 21:25:12 +01:00
2015-10-07 10:57:11 +02:00
describe ( "A Chat Status Notification" , function ( ) {
2016-11-03 11:01:09 +01:00
2016-12-20 10:30:20 +01:00
it ( "does not open automatically if a chat state notification is received" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2015-01-01 21:25:12 +01:00
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
2015-04-02 02:01:53 +02:00
var sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
// <composing> state
var msg = $msg ( {
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2015-04-02 02:01:53 +02:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
2016-08-12 22:38:39 +02:00
} ) . c ( 'composing' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2015-04-02 02:01:53 +02:00
2015-10-07 10:57:11 +02:00
describe ( "An active notification" , function ( ) {
2016-11-03 11:01:09 +01:00
2017-04-05 11:01:31 +02:00
it ( "is sent when the user opens a chat box" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 ) . then ( function ( ) {
2016-12-20 10:30:20 +01:00
spyOn ( _converse . connection , 'send' ) ;
2016-02-15 15:55:34 +01:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2016-02-15 15:55:34 +01:00
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'active' ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . connection . send ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
var $stanza = $ ( _converse . connection . send . calls . argsFor ( 0 ) [ 0 ] . tree ( ) ) ;
2016-02-15 15:55:34 +01:00
expect ( $stanza . attr ( 'to' ) ) . toBe ( contact _jid ) ;
2016-05-30 18:53:31 +02:00
expect ( $stanza . children ( ) . length ) . toBe ( 3 ) ;
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'active' ) ;
expect ( $stanza . children ( ) . get ( 1 ) . tagName ) . toBe ( 'no-store' ) ;
expect ( $stanza . children ( ) . get ( 2 ) . tagName ) . toBe ( 'no-permanent-store' ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-02-15 15:55:34 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "is sent when the user maximizes a minimized a chat box" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2015-01-09 09:02:35 +01:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-11-22 17:42:58 +01:00
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 ) . then ( function ( ) {
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2016-11-22 17:42:58 +01:00
view . model . minimize ( ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'inactive' ) ;
2016-12-20 10:30:20 +01:00
spyOn ( _converse . connection , 'send' ) ;
2016-11-22 17:42:58 +01:00
view . model . maximize ( ) ;
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
return view . model . get ( 'chat_state' ) === 'active' ;
} , 300 )
} ) . then ( function ( ) {
2016-12-20 10:30:20 +01:00
expect ( _converse . connection . send ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
var $stanza = $ ( _converse . connection . send . calls . argsFor ( 0 ) [ 0 ] . tree ( ) ) ;
2016-11-22 17:42:58 +01:00
expect ( $stanza . attr ( 'to' ) ) . toBe ( contact _jid ) ;
expect ( $stanza . children ( ) . length ) . toBe ( 3 ) ;
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'active' ) ;
expect ( $stanza . children ( ) . get ( 1 ) . tagName ) . toBe ( 'no-store' ) ;
expect ( $stanza . children ( ) . get ( 2 ) . tagName ) . toBe ( 'no-permanent-store' ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-11-22 17:42:58 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
} ) ;
2015-01-09 09:02:35 +01:00
2015-10-07 10:57:11 +02:00
describe ( "A composing notification" , function ( ) {
2016-11-03 11:01:09 +01:00
2017-04-05 11:01:31 +02:00
it ( "is sent as soon as the user starts typing a message which is not a command" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
2016-02-15 15:55:34 +01:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2016-02-15 15:55:34 +01:00
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'active' ) ;
2016-12-20 10:30:20 +01:00
spyOn ( _converse . connection , 'send' ) ;
2017-04-05 11:01:31 +02:00
spyOn ( _converse , 'emit' ) ;
2016-02-15 15:55:34 +01:00
view . keyPressed ( {
target : view . $el . find ( 'textarea.chat-textarea' ) ,
keyCode : 1
} ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'composing' ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . connection . send ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
var $stanza = $ ( _converse . connection . send . calls . argsFor ( 0 ) [ 0 ] . tree ( ) ) ;
2016-02-15 15:55:34 +01:00
expect ( $stanza . attr ( 'to' ) ) . toBe ( contact _jid ) ;
2016-05-30 18:53:31 +02:00
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'composing' ) ;
expect ( $stanza . children ( ) . get ( 1 ) . tagName ) . toBe ( 'no-store' ) ;
expect ( $stanza . children ( ) . get ( 2 ) . tagName ) . toBe ( 'no-permanent-store' ) ;
2015-01-09 09:02:35 +01:00
2016-02-15 15:55:34 +01:00
// The notification is not sent again
view . keyPressed ( {
target : view . $el . find ( 'textarea.chat-textarea' ) ,
keyCode : 1
} ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'composing' ) ;
2017-04-05 11:01:31 +02:00
expect ( _converse . emit . calls . count ( ) , 1 ) ;
done ( ) ;
2015-01-01 21:25:12 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "will be shown if received" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2015-01-09 09:02:35 +01:00
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
2015-01-09 09:02:35 +01:00
var sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
// <composing> state
var msg = $msg ( {
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2015-01-09 09:02:35 +01:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . c ( 'composing' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2016-12-20 10:30:20 +01:00
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
2015-01-09 09:02:35 +01:00
expect ( chatboxview ) . toBeDefined ( ) ;
// Check that the notification appears inside the chatbox in the DOM
var $events = chatboxview . $el . find ( '.chat-event' ) ;
2016-03-23 23:27:25 +01:00
expect ( $events . text ( ) ) . toEqual ( mock . cur _names [ 1 ] + ' is typing' ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-03-16 16:28:59 +01:00
it ( "can be a composing carbon message that this user sent from a different client" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
// Send a message from a different resource
spyOn ( _converse , 'log' ) ;
var recipient _jid = mock . cur _names [ 5 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , recipient _jid ) ;
var msg = $msg ( {
'from' : _converse . bare _jid ,
'id' : ( new Date ( ) ) . getTime ( ) ,
'to' : _converse . connection . jid ,
'type' : 'chat' ,
'xmlns' : 'jabber:client'
} ) . c ( 'sent' , { 'xmlns' : 'urn:xmpp:carbons:2' } )
. c ( 'forwarded' , { 'xmlns' : 'urn:xmpp:forward:0' } )
. c ( 'message' , {
'xmlns' : 'jabber:client' ,
'from' : _converse . bare _jid + '/another-resource' ,
'to' : recipient _jid ,
'type' : 'chat'
} ) . c ( 'composing' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
_converse . chatboxes . onMessage ( msg ) ;
// Check that the chatbox and its view now exist
var chatbox = _converse . chatboxes . get ( recipient _jid ) ;
var chatboxview = _converse . chatboxviews . get ( recipient _jid ) ;
// Check that the message was received and check the message parameters
expect ( chatbox . messages . length ) . toEqual ( 1 ) ;
var msg _obj = chatbox . messages . models [ 0 ] ;
expect ( msg _obj . get ( 'fullname' ) ) . toEqual ( _converse . xmppstatus . get ( 'fullname' ) ) ;
expect ( msg _obj . get ( 'sender' ) ) . toEqual ( 'me' ) ;
expect ( msg _obj . get ( 'delayed' ) ) . toEqual ( false ) ;
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
var status _text = $chat _content . find ( '.chat-info.chat-event' ) . text ( ) ;
expect ( status _text ) . toBe ( 'Typing from another device' ) ;
} ) ) ;
2016-11-03 11:01:09 +01:00
} ) ;
2015-01-01 21:25:12 +01:00
2015-10-07 10:57:11 +02:00
describe ( "A paused notification" , function ( ) {
2016-11-03 11:01:09 +01:00
2017-04-05 11:01:31 +02:00
it ( "is sent if the user has stopped typing since 30 seconds" , mock . initConverseWithAsync ( function ( done , _converse ) {
var view , contact _jid ;
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
_converse . TIMEOUTS . PAUSED = 200 ; // Make the timeout shorter so that we can test
2016-11-03 11:01:09 +01:00
2016-02-15 15:55:34 +01:00
contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
view = _converse . chatboxviews . get ( contact _jid ) ;
spyOn ( _converse . connection , 'send' ) ;
2017-04-05 11:01:31 +02:00
spyOn ( view , 'setChatState' ) . and . callThrough ( ) ;
2015-01-01 21:25:12 +01:00
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'active' ) ;
view . keyPressed ( {
target : view . $el . find ( 'textarea.chat-textarea' ) ,
keyCode : 1
} ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'composing' ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . connection . send ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
var $stanza = $ ( _converse . connection . send . calls . argsFor ( 0 ) [ 0 ] . tree ( ) ) ;
2016-05-30 18:53:31 +02:00
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'composing' ) ;
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
return view . model . get ( 'chat_state' ) === 'paused' ;
} , 500 )
} ) . then ( function ( ) {
2016-12-20 10:30:20 +01:00
expect ( _converse . connection . send ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
var $stanza = $ ( _converse . connection . send . calls . argsFor ( 1 ) [ 0 ] . tree ( ) ) ;
2015-01-01 21:25:12 +01:00
expect ( $stanza . attr ( 'to' ) ) . toBe ( contact _jid ) ;
2016-05-30 18:53:31 +02:00
expect ( $stanza . children ( ) . length ) . toBe ( 3 ) ;
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'paused' ) ;
expect ( $stanza . children ( ) . get ( 1 ) . tagName ) . toBe ( 'no-store' ) ;
expect ( $stanza . children ( ) . get ( 2 ) . tagName ) . toBe ( 'no-permanent-store' ) ;
2015-04-04 11:25:50 +02:00
// Test #359. A paused notification should not be sent
// out if the user simply types longer than the
// timeout.
view . keyPressed ( {
target : view . $el . find ( 'textarea.chat-textarea' ) ,
keyCode : 1
} ) ;
expect ( view . setChatState ) . toHaveBeenCalled ( ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'composing' ) ;
2017-04-05 11:01:31 +02:00
2015-04-04 11:25:50 +02:00
view . keyPressed ( {
target : view . $el . find ( 'textarea.chat-textarea' ) ,
keyCode : 1
} ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'composing' ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2015-01-01 21:25:12 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "will be shown if received" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 )
. then ( function ( ) {
// TODO: only show paused state if the previous state was composing
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
spyOn ( _converse , 'emit' ) ;
var sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
// <paused> state
var msg = $msg ( {
from : sender _jid ,
to : _converse . connection . jid ,
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . c ( 'paused' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2017-04-05 11:01:31 +02:00
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
var $events = chatboxview . $el . find ( '.chat-event' ) ;
expect ( $events . text ( ) ) . toEqual ( mock . cur _names [ 1 ] + ' has stopped typing' ) ;
done ( ) ;
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-03-16 16:28:59 +01:00
it ( "can be a paused carbon message that this user sent from a different client" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
// Send a message from a different resource
spyOn ( _converse , 'log' ) ;
var recipient _jid = mock . cur _names [ 5 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , recipient _jid ) ;
var msg = $msg ( {
'from' : _converse . bare _jid ,
'id' : ( new Date ( ) ) . getTime ( ) ,
'to' : _converse . connection . jid ,
'type' : 'chat' ,
'xmlns' : 'jabber:client'
} ) . c ( 'sent' , { 'xmlns' : 'urn:xmpp:carbons:2' } )
. c ( 'forwarded' , { 'xmlns' : 'urn:xmpp:forward:0' } )
. c ( 'message' , {
'xmlns' : 'jabber:client' ,
'from' : _converse . bare _jid + '/another-resource' ,
'to' : recipient _jid ,
'type' : 'chat'
} ) . c ( 'paused' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
_converse . chatboxes . onMessage ( msg ) ;
// Check that the chatbox and its view now exist
var chatbox = _converse . chatboxes . get ( recipient _jid ) ;
var chatboxview = _converse . chatboxviews . get ( recipient _jid ) ;
// Check that the message was received and check the message parameters
expect ( chatbox . messages . length ) . toEqual ( 1 ) ;
var msg _obj = chatbox . messages . models [ 0 ] ;
expect ( msg _obj . get ( 'fullname' ) ) . toEqual ( _converse . xmppstatus . get ( 'fullname' ) ) ;
expect ( msg _obj . get ( 'sender' ) ) . toEqual ( 'me' ) ;
expect ( msg _obj . get ( 'delayed' ) ) . toEqual ( false ) ;
var $chat _content = chatboxview . $el . find ( '.chat-content' ) ;
var status _text = $chat _content . find ( '.chat-info.chat-event' ) . text ( ) ;
expect ( status _text ) . toBe ( 'Stopped typing on the other device' ) ;
} ) ) ;
2016-11-03 11:01:09 +01:00
} ) ;
2015-01-01 21:25:12 +01:00
2015-10-07 10:57:11 +02:00
describe ( "An inactive notifciation" , function ( ) {
2016-11-03 11:01:09 +01:00
2017-04-05 11:01:31 +02:00
it ( "is sent if the user has stopped typing since 2 minutes" , mock . initConverseWithAsync ( function ( done , _converse ) {
var view , contact _jid ;
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 ) . then ( function ( ) {
// Make the timeouts shorter so that we can test
_converse . TIMEOUTS . PAUSED = 200 ;
_converse . TIMEOUTS . INACTIVE = 200 ;
contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
view = _converse . chatboxviews . get ( contact _jid ) ;
2015-01-01 21:25:12 +01:00
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'active' ) ;
view . keyPressed ( {
target : view . $el . find ( 'textarea.chat-textarea' ) ,
keyCode : 1
} ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'composing' ) ;
2016-12-20 10:30:20 +01:00
spyOn ( _converse . connection , 'send' ) ;
2017-04-05 11:01:31 +02:00
return test _utils . waitUntil ( function ( ) {
if ( view . model . get ( 'chat_state' ) === 'paused' ) {
return true ;
}
return false ;
} , 250 )
} ) . then ( function ( ) {
return test _utils . waitUntil ( function ( ) {
return view . model . get ( 'chat_state' ) === 'inactive' ;
} , 250 )
} ) . then ( function ( ) {
2016-12-20 10:30:20 +01:00
expect ( _converse . connection . send ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
var $stanza = $ ( _converse . connection . send . calls . first ( ) . args [ 0 ] . tree ( ) ) ;
2015-01-01 21:25:12 +01:00
expect ( $stanza . attr ( 'to' ) ) . toBe ( contact _jid ) ;
2016-05-30 18:53:31 +02:00
expect ( $stanza . children ( ) . length ) . toBe ( 3 ) ;
2017-04-05 11:01:31 +02:00
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'paused' ) ;
2016-05-30 18:53:31 +02:00
expect ( $stanza . children ( ) . get ( 1 ) . tagName ) . toBe ( 'no-store' ) ;
expect ( $stanza . children ( ) . get ( 2 ) . tagName ) . toBe ( 'no-permanent-store' ) ;
2017-04-05 11:01:31 +02:00
$stanza = $ ( _converse . connection . send . calls . mostRecent ( ) . args [ 0 ] . tree ( ) ) ;
expect ( $stanza . attr ( 'to' ) ) . toBe ( contact _jid ) ;
expect ( $stanza . children ( ) . length ) . toBe ( 3 ) ;
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'inactive' ) ;
expect ( $stanza . children ( ) . get ( 1 ) . tagName ) . toBe ( 'no-store' ) ;
expect ( $stanza . children ( ) . get ( 2 ) . tagName ) . toBe ( 'no-permanent-store' ) ;
done ( ) ;
2015-01-01 21:25:12 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "is sent when the user a minimizes a chat box" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2015-01-09 09:02:35 +01:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
spyOn ( _converse . connection , 'send' ) ;
2015-01-09 09:02:35 +01:00
view . minimize ( ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'inactive' ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . connection . send ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
var $stanza = $ ( _converse . connection . send . calls . argsFor ( 0 ) [ 0 ] . tree ( ) ) ;
2015-01-09 09:02:35 +01:00
expect ( $stanza . attr ( 'to' ) ) . toBe ( contact _jid ) ;
2016-05-30 18:53:31 +02:00
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'inactive' ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-04-05 11:01:31 +02:00
it ( "is sent if the user closes a chat box" , mock . initConverseWithAsync ( function ( done , _converse ) {
2016-12-20 10:30:20 +01:00
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2017-04-05 11:01:31 +02:00
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 300 ) . then ( function ( ) {
2016-02-15 15:55:34 +01:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2016-02-15 15:55:34 +01:00
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'active' ) ;
2016-12-20 10:30:20 +01:00
spyOn ( _converse . connection , 'send' ) ;
2016-02-15 15:55:34 +01:00
view . close ( ) ;
expect ( view . model . get ( 'chat_state' ) ) . toBe ( 'inactive' ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . connection . send ) . toHaveBeenCalled ( ) ;
2017-04-05 11:01:31 +02:00
var $stanza = $ ( _converse . connection . send . calls . argsFor ( 0 ) [ 0 ] . tree ( ) ) ;
2016-02-15 15:55:34 +01:00
expect ( $stanza . attr ( 'to' ) ) . toBe ( contact _jid ) ;
2016-05-30 18:53:31 +02:00
expect ( $stanza . children ( ) . length ) . toBe ( 3 ) ;
expect ( $stanza . children ( ) . get ( 0 ) . tagName ) . toBe ( 'inactive' ) ;
expect ( $stanza . children ( ) . get ( 1 ) . tagName ) . toBe ( 'no-store' ) ;
expect ( $stanza . children ( ) . get ( 2 ) . tagName ) . toBe ( 'no-permanent-store' ) ;
2017-04-05 11:01:31 +02:00
done ( ) ;
2016-02-15 15:55:34 +01:00
} ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "will clear any other chat status notifications if its received" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2015-01-01 21:25:12 +01:00
2015-01-09 09:02:35 +01:00
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
2015-01-09 10:48:36 +01:00
var sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var view = _converse . chatboxviews . get ( sender _jid ) ;
2015-01-09 10:48:36 +01:00
expect ( view . $el . find ( '.chat-event' ) . length ) . toBe ( 0 ) ;
2017-01-26 15:49:02 +01:00
view . showStatusNotification ( sender _jid + ' is typing' ) ;
2015-01-09 10:48:36 +01:00
expect ( view . $el . find ( '.chat-event' ) . length ) . toBe ( 1 ) ;
2015-10-25 18:49:35 +01:00
var msg = $msg ( {
2015-01-09 10:48:36 +01:00
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2015-01-09 10:48:36 +01:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . c ( 'inactive' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2015-01-09 10:48:36 +01:00
expect ( view . $el . find ( '.chat-event' ) . length ) . toBe ( 0 ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2015-01-09 10:48:36 +01:00
2016-11-03 11:01:09 +01:00
} ) ;
2015-01-09 10:48:36 +01:00
2015-10-07 10:57:11 +02:00
describe ( "A gone notifciation" , function ( ) {
2016-11-03 11:01:09 +01:00
2016-12-20 10:30:20 +01:00
it ( "will be shown if received" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-11-03 11:01:09 +01:00
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
2015-01-09 09:02:35 +01:00
var sender _jid = mock . cur _names [ 1 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
// <paused> state
2015-10-25 18:49:35 +01:00
var msg = $msg ( {
2015-01-09 09:02:35 +01:00
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2015-01-09 09:02:35 +01:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . c ( 'gone' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2016-12-20 10:30:20 +01:00
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
2015-10-25 18:49:35 +01:00
var $events = chatboxview . $el . find ( '.chat-event' ) ;
2016-03-23 23:27:25 +01:00
expect ( $events . text ( ) ) . toEqual ( mock . cur _names [ 1 ] + ' has gone away' ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
} ) ;
} ) ;
} ) ;
2013-11-02 12:37:38 +01:00
2015-10-07 10:57:11 +02:00
describe ( "Special Messages" , function ( ) {
2014-03-05 03:29:10 +01:00
2016-12-20 10:30:20 +01:00
it ( "'/clear' can be used to clear messages in a conversation" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-11-03 11:01:09 +01:00
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
2013-11-02 12:37:38 +01:00
var contact _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
2016-12-20 10:30:20 +01:00
test _utils . openChatBoxFor ( _converse , contact _jid ) ;
var view = _converse . chatboxviews . get ( contact _jid ) ;
2013-11-02 12:37:38 +01:00
var message = 'This message is another sent from this chatbox' ;
// Lets make sure there is at least one message already
// (e.g for when this test is run on its own).
2014-08-08 22:06:01 +02:00
test _utils . sendMessage ( view , message ) ;
2013-11-03 21:28:44 +01:00
expect ( view . model . messages . length > 0 ) . toBeTruthy ( ) ;
2014-06-30 19:21:16 +02:00
expect ( view . model . messages . browserStorage . records . length > 0 ) . toBeTruthy ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'messageSend' , message ) ;
2013-11-02 12:37:38 +01:00
message = '/clear' ;
2017-04-05 11:01:31 +02:00
spyOn ( view , 'onMessageSubmitted' ) . and . callThrough ( ) ;
spyOn ( view , 'clearMessages' ) . and . callThrough ( ) ;
spyOn ( window , 'confirm' ) . and . callFake ( function ( ) {
2014-04-24 19:14:37 +02:00
return true ;
} ) ;
2014-08-08 22:06:01 +02:00
test _utils . sendMessage ( view , message ) ;
2015-07-04 10:10:21 +02:00
expect ( view . onMessageSubmitted ) . toHaveBeenCalled ( ) ;
2014-04-24 19:14:37 +02:00
expect ( view . clearMessages ) . toHaveBeenCalled ( ) ;
expect ( window . confirm ) . toHaveBeenCalled ( ) ;
expect ( view . model . messages . length , 0 ) ; // The messages must be removed from the chatbox
2014-06-30 19:21:16 +02:00
expect ( view . model . messages . browserStorage . records . length , 0 ) ; // And also from browserStorage
2017-04-05 11:01:31 +02:00
expect ( _converse . emit . calls . count ( ) , 1 ) ;
expect ( _converse . emit . calls . mostRecent ( ) . args , [ 'messageSend' , message ] ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
} ) ;
2013-11-02 12:37:38 +01:00
2015-10-07 10:57:11 +02:00
describe ( "A Message Counter" , function ( ) {
2013-11-02 12:37:38 +01:00
2016-12-20 10:30:20 +01:00
it ( "is incremented when the message is received and the window is not focused" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2016-11-03 11:01:09 +01:00
2016-12-20 10:30:20 +01:00
spyOn ( _converse , 'emit' ) ;
expect ( _converse . msg _counter ) . toBe ( 0 ) ;
2017-04-05 11:01:31 +02:00
spyOn ( _converse , 'incrementMsgCounter' ) . and . callThrough ( ) ;
2017-05-03 09:06:28 +02:00
spyOn ( _converse , 'clearMsgCounter' ) . and . callThrough ( ) ;
2016-12-20 10:30:20 +01:00
var previous _state = _converse . windowState ;
2013-11-02 12:37:38 +01:00
var message = 'This message will increment the message counter' ;
2015-10-25 18:49:35 +01:00
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ,
2013-11-02 12:37:38 +01:00
msg = $msg ( {
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2013-11-02 12:37:38 +01:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( message ) . up ( )
2017-05-03 09:06:28 +02:00
. c ( 'active' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . windowState = 'hidden' ;
_converse . chatboxes . onMessage ( msg ) ;
expect ( _converse . incrementMsgCounter ) . toHaveBeenCalled ( ) ;
2017-05-03 09:06:28 +02:00
expect ( _converse . clearMsgCounter ) . not . toHaveBeenCalled ( ) ;
2016-12-20 10:30:20 +01:00
expect ( _converse . msg _counter ) . toBe ( 1 ) ;
2017-04-21 12:11:33 +02:00
expect ( _converse . emit ) . toHaveBeenCalledWith ( 'message' , jasmine . any ( Object ) ) ;
2016-12-20 10:30:20 +01:00
_converse . windowSate = previous _state ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "is cleared when the window is focused" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
_converse . windowState = 'hidden' ;
2017-04-05 11:01:31 +02:00
spyOn ( _converse , 'clearMsgCounter' ) . and . callThrough ( ) ;
_converse . saveWindowState ( null , 'focus' ) ;
_converse . saveWindowState ( null , 'blur' ) ;
expect ( _converse . clearMsgCounter ) . toHaveBeenCalled ( ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2016-12-20 10:30:20 +01:00
it ( "is not incremented when the message is received and the window is focused" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
2016-11-03 11:01:09 +01:00
test _utils . openControlBox ( ) ;
2016-12-20 10:30:20 +01:00
test _utils . openContactsPanel ( _converse ) ;
2013-11-02 12:37:38 +01:00
2016-12-20 10:30:20 +01:00
expect ( _converse . msg _counter ) . toBe ( 0 ) ;
2017-04-05 11:01:31 +02:00
spyOn ( _converse , 'incrementMsgCounter' ) . and . callThrough ( ) ;
2016-12-20 10:30:20 +01:00
_converse . saveWindowState ( null , 'focus' ) ;
2013-11-02 12:37:38 +01:00
var message = 'This message will not increment the message counter' ;
2015-10-25 18:49:35 +01:00
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ,
2013-11-02 12:37:38 +01:00
msg = $msg ( {
from : sender _jid ,
2016-12-20 10:30:20 +01:00
to : _converse . connection . jid ,
2013-11-02 12:37:38 +01:00
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} ) . c ( 'body' ) . t ( message ) . up ( )
2017-05-03 09:06:28 +02:00
. c ( 'active' , { 'xmlns' : Strophe . NS . CHATSTATES } ) . tree ( ) ;
2016-12-20 10:30:20 +01:00
_converse . chatboxes . onMessage ( msg ) ;
expect ( _converse . incrementMsgCounter ) . not . toHaveBeenCalled ( ) ;
expect ( _converse . msg _counter ) . toBe ( 0 ) ;
2016-11-03 11:01:09 +01:00
} ) ) ;
2017-05-01 13:05:58 +02:00
it ( "is incremented from zero when chatbox was closed after viewing previously received messages and the window is not focused now" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
// initial state
expect ( _converse . msg _counter ) . toBe ( 0 ) ;
var message = 'This message will always increment the message counter from zero' ,
sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ,
msgFactory = function ( ) {
return $msg ( {
from : sender _jid ,
to : _converse . connection . jid ,
type : 'chat' ,
id : ( new Date ( ) ) . getTime ( )
} )
. c ( 'body' ) . t ( message ) . up ( )
2017-05-03 09:06:28 +02:00
. c ( 'active' , { 'xmlns' : Strophe . NS . CHATSTATES } )
2017-05-01 13:05:58 +02:00
. tree ( ) ;
} ;
// leave converse-chat page
_converse . windowState = 'hidden' ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( _converse . msg _counter ) . toBe ( 1 ) ;
// come back to converse-chat page
_converse . saveWindowState ( null , 'focus' ) ;
var view = _converse . chatboxviews . get ( sender _jid ) ;
expect ( view . $el . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( _converse . msg _counter ) . toBe ( 0 ) ;
// close chatbox and leave converse-chat page again
view . close ( ) ;
_converse . windowState = 'hidden' ;
// check that msg_counter is incremented from zero again
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
view = _converse . chatboxviews . get ( sender _jid ) ;
expect ( view . $el . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( _converse . msg _counter ) . toBe ( 1 ) ;
} ) ) ;
2016-11-03 11:01:09 +01:00
} ) ;
2017-05-03 09:06:28 +02:00
describe ( "A ChatBox's Unread Message Count" , function ( ) {
it ( "is incremented when the message is received and ChatBoxView is scrolled up" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ,
msg = test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread' ) ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
chatbox . save ( 'scrolled' , true ) ;
_converse . chatboxes . onMessage ( msg ) ;
expect ( chatbox . get ( 'num_unread' ) ) . toBe ( 1 ) ;
} ) ) ;
it ( "is not incremented when the message is received and ChatBoxView is scrolled down" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ,
msg = test _utils . createChatMessage ( _converse , sender _jid , 'This message will be read' ) ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
_converse . chatboxes . onMessage ( msg ) ;
expect ( chatbox . get ( 'num_unread' ) ) . toBe ( 0 ) ;
} ) ) ;
it ( "is incremeted when message is received, chatbox is scrolled down and the window is not focused" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread' ) ;
} ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
_converse . windowState = 'hidden' ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( chatbox . get ( 'num_unread' ) ) . toBe ( 1 ) ;
} ) ) ;
it ( "is incremeted when message is received, chatbox is scrolled up and the window is not focused" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread' ) ;
} ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
chatbox . save ( 'scrolled' , true ) ;
_converse . windowState = 'hidden' ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( chatbox . get ( 'num_unread' ) ) . toBe ( 1 ) ;
} ) ) ;
it ( "is cleared when ChatBoxView was scrolled down and the window become focused" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread' ) ;
} ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
_converse . windowState = 'hidden' ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( chatbox . get ( 'num_unread' ) ) . toBe ( 1 ) ;
_converse . saveWindowState ( null , 'focus' ) ;
expect ( chatbox . get ( 'num_unread' ) ) . toBe ( 0 ) ;
} ) ) ;
it ( "is not cleared when ChatBoxView was scrolled up and the windows become focused" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread' ) ;
} ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
chatbox . save ( 'scrolled' , true ) ;
_converse . windowState = 'hidden' ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( chatbox . get ( 'num_unread' ) ) . toBe ( 1 ) ;
_converse . saveWindowState ( null , 'focus' ) ;
expect ( chatbox . get ( 'num_unread' ) ) . toBe ( 1 ) ;
} ) ) ;
} ) ;
describe ( "A RosterView's Unread Message Count" , function ( ) {
it ( "is updated when message is received and chatbox is scrolled up" , mock . initConverseWithAsync ( function ( done , _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 500 )
. then ( function ( ) {
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
chatbox . save ( 'scrolled' , true ) ;
var msg = test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread' ) ;
_converse . chatboxes . onMessage ( msg ) ;
var msgIndicatorSelector = 'a.open-chat:contains("' + chatbox . get ( 'fullname' ) + '") .msgs-indicactor' ,
$msgIndicator = $ ( _converse . rosterview . $el . find ( msgIndicatorSelector ) ) ;
expect ( $msgIndicator . text ( ) ) . toBe ( '1' ) ;
msg = test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread too' ) ;
_converse . chatboxes . onMessage ( msg ) ;
$msgIndicator = $ ( _converse . rosterview . $el . find ( msgIndicatorSelector ) ) ;
expect ( $msgIndicator . text ( ) ) . toBe ( '2' ) ;
done ( ) ;
} ) ;
} ) ) ;
it ( "is updated when message is received and chatbox is minimized" , mock . initConverseWithAsync ( function ( done , _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 500 )
. then ( function ( ) {
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
chatboxview . minimize ( ) ;
var msg = test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread' ) ;
_converse . chatboxes . onMessage ( msg ) ;
var msgIndicatorSelector = 'a.open-chat:contains("' + chatbox . get ( 'fullname' ) + '") .msgs-indicactor' ,
$msgIndicator = $ ( _converse . rosterview . $el . find ( msgIndicatorSelector ) ) ;
expect ( $msgIndicator . text ( ) ) . toBe ( '1' ) ;
msg = test _utils . createChatMessage ( _converse , sender _jid , 'This message will be unread too' ) ;
_converse . chatboxes . onMessage ( msg ) ;
$msgIndicator = $ ( _converse . rosterview . $el . find ( msgIndicatorSelector ) ) ;
expect ( $msgIndicator . text ( ) ) . toBe ( '2' ) ;
done ( ) ;
} ) ;
} ) ) ;
it ( "is cleared when chatbox is maximzied after receiving messages in minimized mode" , mock . initConverseWithAsync ( function ( done , _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 500 )
. then ( function ( ) {
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
var msgsIndicatorSelector = 'a.open-chat:contains("' + chatbox . get ( 'fullname' ) + '") .msgs-indicactor' ;
var selectMsgsIndicator = function ( ) { return $ ( _converse . rosterview . $el . find ( msgsIndicatorSelector ) ) ; } ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be received as unread, but eventually will be read' ) ;
} ;
chatboxview . minimize ( ) ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( selectMsgsIndicator ( ) . text ( ) ) . toBe ( '1' ) ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( selectMsgsIndicator ( ) . text ( ) ) . toBe ( '2' ) ;
chatboxview . maximize ( ) ;
expect ( selectMsgsIndicator ( ) . length ) . toBe ( 0 ) ;
done ( ) ;
} ) ;
} ) ) ;
it ( "is cleared when unread messages are viewed which were received in scrolled-up chatbox" , mock . initConverseWithAsync ( function ( done , _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 500 )
. then ( function ( ) {
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be received as unread, but eventually will be read' ) ;
} ;
var msgsIndicatorSelector = 'a.open-chat:contains("' + chatbox . get ( 'fullname' ) + '") .msgs-indicactor' ,
selectMsgsIndicator = function ( ) { return $ ( _converse . rosterview . $el . find ( msgsIndicatorSelector ) ) ; } ;
chatbox . save ( 'scrolled' , true ) ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( selectMsgsIndicator ( ) . text ( ) ) . toBe ( '1' ) ;
chatboxview . viewUnreadMessages ( ) ;
_converse . rosterview . render ( ) ;
expect ( selectMsgsIndicator ( ) . length ) . toBe ( 0 ) ;
done ( ) ;
} ) ;
} ) ) ;
it ( "is not cleared after user clicks on roster view when chatbox is already opened and scrolled up" , mock . initConverseWithAsync ( function ( done , _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
test _utils . waitUntil ( function ( ) {
return _converse . rosterview . $el . find ( 'dt' ) . length ;
} , 500 )
. then ( function ( ) {
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be received as unread, but eventually will be read' ) ;
} ;
var msgsIndicatorSelector = 'a.open-chat:contains("' + chatbox . get ( 'fullname' ) + '") .msgs-indicactor' ,
selectMsgsIndicator = function ( ) { return $ ( _converse . rosterview . $el . find ( msgsIndicatorSelector ) ) ; } ;
chatbox . save ( 'scrolled' , true ) ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
expect ( selectMsgsIndicator ( ) . text ( ) ) . toBe ( '1' ) ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
expect ( selectMsgsIndicator ( ) . text ( ) ) . toBe ( '1' ) ;
done ( ) ;
} ) ;
} ) ) ;
} ) ;
describe ( "A Minimized ChatBoxView's Unread Message Count" , function ( ) {
it ( "is displayed when scrolled up chatbox is minimized after receiving unread messages" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be received as unread, but eventually will be read' ) ;
} ;
var selectUnreadMsgCount = function ( ) {
var minimizedChatBoxView = _converse . minimized _chats . get ( sender _jid ) ;
return minimizedChatBoxView . $el . find ( '.chat-head-message-count' ) ;
} ;
var chatbox = _converse . chatboxes . get ( sender _jid ) ;
chatbox . save ( 'scrolled' , true ) ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
chatboxview . minimize ( ) ;
var $unreadMsgCount = selectUnreadMsgCount ( ) ;
expect ( $unreadMsgCount . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( $unreadMsgCount . html ( ) ) . toBe ( '1' ) ;
} ) ) ;
it ( "is incremented when message is received and windows is not focused" , mock . initConverse ( function ( _converse ) {
test _utils . createContacts ( _converse , 'current' ) ;
test _utils . openContactsPanel ( _converse ) ;
var sender _jid = mock . cur _names [ 0 ] . replace ( / /g , '.' ) . toLowerCase ( ) + '@localhost' ;
test _utils . openChatBoxFor ( _converse , sender _jid ) ;
var msgFactory = function ( ) {
return test _utils . createChatMessage ( _converse , sender _jid , 'This message will be received as unread, but eventually will be read' ) ;
} ;
var selectUnreadMsgCount = function ( ) {
var minimizedChatBoxView = _converse . minimized _chats . get ( sender _jid ) ;
return minimizedChatBoxView . $el . find ( '.chat-head-message-count' ) ;
} ;
var chatboxview = _converse . chatboxviews . get ( sender _jid ) ;
chatboxview . minimize ( ) ;
_converse . chatboxes . onMessage ( msgFactory ( ) ) ;
var $unreadMsgCount = selectUnreadMsgCount ( ) ;
expect ( $unreadMsgCount . is ( ':visible' ) ) . toBeTruthy ( ) ;
expect ( $unreadMsgCount . html ( ) ) . toBe ( '1' ) ;
} ) ) ;
} ) ;
2016-11-03 11:01:09 +01:00
} ) ;
2013-11-02 12:37:38 +01:00
} ) ) ;