Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
506aa331
Commit
506aa331
authored
Jul 30, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wait for promises before opening chats in API methods
parent
cb118b9c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
2491 additions
and
2401 deletions
+2491
-2401
CHANGES.md
CHANGES.md
+3
-0
dist/converse.js
dist/converse.js
+24
-19
spec/bookmarks.js
spec/bookmarks.js
+93
-97
spec/chatbox.js
spec/chatbox.js
+463
-441
spec/chatroom.js
spec/chatroom.js
+735
-725
spec/http-file-upload.js
spec/http-file-upload.js
+291
-295
spec/messages.js
spec/messages.js
+636
-598
spec/minchats.js
spec/minchats.js
+43
-36
spec/roomslist.js
spec/roomslist.js
+105
-102
spec/spoilers.js
spec/spoilers.js
+26
-22
spec/user-details-modal.js
spec/user-details-modal.js
+10
-9
src/converse-muc-views.js
src/converse-muc-views.js
+1
-2
src/i18n.js
src/i18n.js
+7
-2
tests/utils.js
tests/utils.js
+54
-53
No files found.
CHANGES.md
View file @
506aa331
...
@@ -39,6 +39,9 @@
...
@@ -39,6 +39,9 @@
-
New API method
`_converse.api.vcard.update`
.
-
New API method
`_converse.api.vcard.update`
.
-
The
`contactStatusChanged`
event has been renamed to
`contactPresenceChanged`
-
The
`contactStatusChanged`
event has been renamed to
`contactPresenceChanged`
and a event
`presenceChanged`
is now also triggered on the contact.
and a event
`presenceChanged`
is now also triggered on the contact.
-
`_converse.api.chats.open`
and
`_converse.api.rooms.open`
now returns a
`Presence`
which resolves with the
`Backbone.Model`
representing the chat
object.
## UI changes
## UI changes
...
...
dist/converse.js
View file @
506aa331
...
@@ -76149,17 +76149,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
...
@@ -76149,17 +76149,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
this.model.on('show', this.show, this);
this.model.on('show', this.show, this);
this.model.occupants.on('add', this.showJoinNotification, this);
this.model.occupants.on('add', this.showJoinNotification, this);
this.model.occupants.on('remove', this.showLeaveNotification, this);
this.model.occupants.on('remove', this.showLeaveNotification, this);
this.model.occupants.on('change:show', occupant => {
this.model.occupants.on('change:show', this.showJoinOrLeaveNotification, this);
if (!occupant.isMember() || _.includes(occupant.get('states'), '303')) {
return;
}
if (occupant.get('show') === 'offline') {
this.showLeaveNotification(occupant);
} else if (occupant.get('show') === 'online') {
this.showJoinNotification(occupant);
}
});
this.createEmojiPicker();
this.createEmojiPicker();
this.createOccupantsView();
this.createOccupantsView();
this.render().insertIntoDOM();
this.render().insertIntoDOM();
...
@@ -76169,8 +76159,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
...
@@ -76169,8 +76159,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
const handler = () => {
const handler = () => {
if (!u.isPersistableModel(this.model)) {
if (!u.isPersistableModel(this.model)) {
// Happens during tests, nothing to do if this
// Happens during tests, nothing to do if this
// is a hanging chatbox (i.e. not in the
// is a hanging chatbox (i.e. not in the collection anymore).
// collection anymore).
return;
return;
}
}
...
@@ -77047,6 +77036,18 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
...
@@ -77047,6 +77036,18 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}
}
},
},
showJoinOrLeaveNotification(occupant) {
if (!occupant.isMember() || _.includes(occupant.get('states'), '303')) {
return;
}
if (occupant.get('show') === 'offline') {
this.showLeaveNotification(occupant);
} else if (occupant.get('show') === 'online') {
this.showJoinNotification(occupant);
}
},
showJoinNotification(occupant) {
showJoinNotification(occupant) {
if (this.model.get('connection_status') !== converse.ROOMSTATUS.ENTERED) {
if (this.model.get('connection_status') !== converse.ROOMSTATUS.ENTERED) {
return;
return;
...
@@ -77094,10 +77095,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
...
@@ -77094,10 +77095,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
showLeaveNotification(occupant) {
showLeaveNotification(occupant) {
const nick = occupant.get('nick'),
const nick = occupant.get('nick'),
stat = occupant.get('status'),
stat = occupant.get('status'),
last_el = this.content.lastElementChild,
last_el = this.content.lastElementChild;
last_msg_date = last_el.getAttribute('data-isodate');
if (
_.includes(_.get(last_el, 'classList', []), 'chat-info') && moment(last_msg_date
).isSame(new Date(), "day") && _.get(last_el, 'dataset', {}).join === `"${nick}"`) {
if (
last_el && _.includes(_.get(last_el, 'classList', []), 'chat-info') && moment(last_el.getAttribute('data-isodate')
).isSame(new Date(), "day") && _.get(last_el, 'dataset', {}).join === `"${nick}"`) {
let message;
let message;
if (_.isNil(stat)) {
if (_.isNil(stat)) {
...
@@ -77128,7 +77128,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
...
@@ -77128,7 +77128,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
'data': `data-leave="${nick}"`
'data': `data-leave="${nick}"`
};
};
if (_.includes(_.get(last_el, 'classList', []), 'chat-info') && _.get(last_el, 'dataset', {}).leavejoin === `"${nick}"`) {
if (
last_el &&
_.includes(_.get(last_el, 'classList', []), 'chat-info') && _.get(last_el, 'dataset', {}).leavejoin === `"${nick}"`) {
last_el.outerHTML = tpl_info(data);
last_el.outerHTML = tpl_info(data);
} else {
} else {
const el = u.stringToElement(tpl_info(data));
const el = u.stringToElement(tpl_info(data));
...
@@ -83843,8 +83843,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
...
@@ -83843,8 +83843,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
xhr.onload = function () {
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 400) {
if (xhr.status >= 200 && xhr.status < 400) {
jed_instance = new Jed(window.JSON.parse(xhr.responseText));
try {
resolve();
const data = window.JSON.parse(xhr.responseText);
jed_instance = new Jed(data);
resolve();
} catch (e) {
xhr.onerror(e);
}
} else {
} else {
xhr.onerror();
xhr.onerror();
}
}
spec/bookmarks.js
View file @
506aa331
...
@@ -34,24 +34,24 @@
...
@@ -34,24 +34,24 @@
});
});
spyOn
(
_converse
.
connection
,
'
getUniqueId
'
).
and
.
callThrough
();
spyOn
(
_converse
.
connection
,
'
getUniqueId
'
).
and
.
callThrough
();
test_utils
.
openChatRoom
(
_converse
,
'
theplay
'
,
'
conference.shakespeare.lit
'
,
'
JC
'
)
;
let
view
;
var
jid
=
'
theplay@conference.shakespeare.lit
'
;
test_utils
.
openChatRoom
(
_converse
,
'
theplay
'
,
'
conference.shakespeare.lit
'
,
'
JC
'
)
var
view
=
_converse
.
chatboxviews
.
get
(
jid
);
.
then
(()
=>
{
spyOn
(
view
,
'
renderBookmarkForm
'
).
and
.
callThrough
()
;
var
jid
=
'
theplay@conference.shakespeare.lit
'
;
spyOn
(
view
,
'
closeForm
'
).
and
.
callThrough
(
);
view
=
_converse
.
chatboxviews
.
get
(
jid
);
spyOn
(
view
,
'
renderBookmarkForm
'
).
and
.
callThrough
();
test_utils
.
waitUntil
(
function
()
{
spyOn
(
view
,
'
closeForm
'
).
and
.
callThrough
();
return
!
_
.
isNull
(
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
));
return
test_utils
.
waitUntil
(()
=>
!
_
.
isNull
(
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
)
));
}
,
300
).
then
(
function
()
{
}
).
then
(()
=>
{
var
$bookmark
=
$
(
view
.
el
).
find
(
'
.toggle-bookmark
'
);
var
bookmark
=
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
);
$bookmark
[
0
]
.
click
();
bookmark
.
click
();
expect
(
view
.
renderBookmarkForm
).
toHaveBeenCalled
();
expect
(
view
.
renderBookmarkForm
).
toHaveBeenCalled
();
view
.
el
.
querySelector
(
'
.button-cancel
'
).
click
();
view
.
el
.
querySelector
(
'
.button-cancel
'
).
click
();
expect
(
view
.
closeForm
).
toHaveBeenCalled
();
expect
(
view
.
closeForm
).
toHaveBeenCalled
();
expect
(
$bookmark
.
hasClass
(
'
on-button
'
),
false
);
expect
(
u
.
hasClass
(
'
on-button
'
,
bookmark
),
false
);
$bookmark
[
0
]
.
click
();
bookmark
.
click
();
expect
(
view
.
renderBookmarkForm
).
toHaveBeenCalled
();
expect
(
view
.
renderBookmarkForm
).
toHaveBeenCalled
();
/* Client uploads data:
/* Client uploads data:
...
@@ -93,7 +93,7 @@
...
@@ -93,7 +93,7 @@
view
.
el
.
querySelector
(
'
.btn-primary
'
).
click
();
view
.
el
.
querySelector
(
'
.btn-primary
'
).
click
();
expect
(
view
.
model
.
get
(
'
bookmarked
'
)).
toBeTruthy
();
expect
(
view
.
model
.
get
(
'
bookmarked
'
)).
toBeTruthy
();
expect
(
$bookmark
.
hasClass
(
'
on-button
'
),
true
);
expect
(
u
.
hasClass
(
'
on-button
'
,
bookmark
),
true
);
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
"
<iq type='set' from='dummy@localhost/resource' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<iq type='set' from='dummy@localhost/resource' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
...
@@ -175,100 +175,96 @@
...
@@ -175,100 +175,96 @@
it
(
"
displays that it's bookmarked through its bookmark icon
"
,
mock
.
initConverseWithPromises
(
it
(
"
displays that it's bookmarked through its bookmark icon
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
let
view
;
test_utils
.
waitUntilDiscoConfirmed
(
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
bare_jid
,
_converse
,
_converse
.
bare_jid
,
[{
'
category
'
:
'
pubsub
'
,
'
type
'
:
'
pep
'
}],
[{
'
category
'
:
'
pubsub
'
,
'
type
'
:
'
pep
'
}],
[
'
http://jabber.org/protocol/pubsub#publish-options
'
]
[
'
http://jabber.org/protocol/pubsub#publish-options
'
]
).
then
(
function
()
{
).
then
(()
=>
test_utils
.
openChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
dummy
'
))
test_utils
.
openChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
return
test_utils
.
waitUntil
(()
=>
!
_
.
isNull
(
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
)))
test_utils
.
waitUntil
(
function
()
{
}).
then
(
function
()
{
return
!
_
.
isNull
(
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
));
var
bookmark_icon
=
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
);
},
300
).
then
(
function
()
{
expect
(
_
.
includes
(
bookmark_icon
.
classList
,
'
button-on
'
)).
toBeFalsy
();
var
bookmark_icon
=
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
);
view
.
model
.
set
(
'
bookmarked
'
,
true
);
expect
(
_
.
includes
(
bookmark_icon
.
classList
,
'
button-on
'
)).
toBeFalsy
();
expect
(
_
.
includes
(
bookmark_icon
.
classList
,
'
button-on
'
)).
toBeTruthy
();
view
.
model
.
set
(
'
bookmarked
'
,
true
);
view
.
model
.
set
(
'
bookmarked
'
,
false
);
expect
(
_
.
includes
(
bookmark_icon
.
classList
,
'
button-on
'
)).
toBeTruthy
();
expect
(
_
.
includes
(
bookmark_icon
.
classList
,
'
button-on
'
)).
toBeFalsy
();
view
.
model
.
set
(
'
bookmarked
'
,
false
);
done
();
expect
(
_
.
includes
(
bookmark_icon
.
classList
,
'
button-on
'
)).
toBeFalsy
();
done
();
});
});
});
}));
}));
it
(
"
can be unbookmarked
"
,
mock
.
initConverseWithPromises
(
it
(
"
can be unbookmarked
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
let
sent_stanza
,
IQ_id
,
view
,
sendIQ
;
test_utils
.
waitUntilDiscoConfirmed
(
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
bare_jid
,
_converse
,
_converse
.
bare_jid
,
[{
'
category
'
:
'
pubsub
'
,
'
type
'
:
'
pep
'
}],
[{
'
category
'
:
'
pubsub
'
,
'
type
'
:
'
pep
'
}],
[
'
http://jabber.org/protocol/pubsub#publish-options
'
]
[
'
http://jabber.org/protocol/pubsub#publish-options
'
]
).
then
(
function
()
{
).
then
(()
=>
{
var
sent_stanza
,
IQ_id
;
sendIQ
=
_converse
.
connection
.
sendIQ
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
return
test_utils
.
openChatRoom
(
_converse
,
'
theplay
'
,
'
conference.shakespeare.lit
'
,
'
JC
'
);
}).
then
(()
=>
{
test_utils
.
openChatRoom
(
_converse
,
'
theplay
'
,
'
conference.shakespeare.lit
'
,
'
JC
'
);
var
jid
=
'
theplay@conference.shakespeare.lit
'
;
var
jid
=
'
theplay@conference.shakespeare.lit
'
;
var
view
=
_converse
.
chatboxviews
.
get
(
jid
);
view
=
_converse
.
chatboxviews
.
get
(
jid
);
return
test_utils
.
waitUntil
(()
=>
!
_
.
isNull
(
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
)));
}).
then
(
function
()
{
spyOn
(
view
,
'
toggleBookmark
'
).
and
.
callThrough
();
spyOn
(
_converse
.
bookmarks
,
'
sendBookmarkStanza
'
).
and
.
callThrough
();
view
.
delegateEvents
();
test_utils
.
waitUntil
(
function
()
{
_converse
.
bookmarks
.
create
({
return
!
_
.
isNull
(
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
));
'
jid
'
:
view
.
model
.
get
(
'
jid
'
),
},
300
).
then
(
function
()
{
'
autojoin
'
:
false
,
spyOn
(
view
,
'
toggleBookmark
'
).
and
.
callThrough
();
'
name
'
:
'
The Play
'
,
spyOn
(
_converse
.
bookmarks
,
'
sendBookmarkStanza
'
).
and
.
callThrough
();
'
nick
'
:
'
Othello
'
view
.
delegateEvents
();
_converse
.
bookmarks
.
create
({
'
jid
'
:
view
.
model
.
get
(
'
jid
'
),
'
autojoin
'
:
false
,
'
name
'
:
'
The Play
'
,
'
nick
'
:
'
Othello
'
});
expect
(
_converse
.
bookmarks
.
length
).
toBe
(
1
);
expect
(
view
.
model
.
get
(
'
bookmarked
'
)).
toBeTruthy
();
var
$bookmark_icon
=
$
(
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
));
expect
(
$bookmark_icon
.
hasClass
(
'
button-on
'
)).
toBeTruthy
();
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
spyOn
(
_converse
.
connection
,
'
getUniqueId
'
).
and
.
callThrough
();
$bookmark_icon
[
0
].
click
();
expect
(
view
.
toggleBookmark
).
toHaveBeenCalled
();
expect
(
$bookmark_icon
.
hasClass
(
'
button-on
'
)).
toBeFalsy
();
expect
(
_converse
.
bookmarks
.
length
).
toBe
(
0
);
// Check that an IQ stanza is sent out, containing no
// conferences to bookmark (since we removed the one and
// only bookmark).
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
"
<iq type='set' from='dummy@localhost/resource' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
"
+
"
<publish node='storage:bookmarks'>
"
+
"
<item id='current'>
"
+
"
<storage xmlns='storage:bookmarks'/>
"
+
"
</item>
"
+
"
</publish>
"
+
"
<publish-options>
"
+
"
<x xmlns='jabber:x:data' type='submit'>
"
+
"
<field var='FORM_TYPE' type='hidden'>
"
+
"
<value>http://jabber.org/protocol/pubsub#publish-options</value>
"
+
"
</field>
"
+
"
<field var='pubsub#persist_items'>
"
+
"
<value>true</value>
"
+
"
</field>
"
+
"
<field var='pubsub#access_model'>
"
+
"
<value>whitelist</value>
"
+
"
</field>
"
+
"
</x>
"
+
"
</publish-options>
"
+
"
</pubsub>
"
+
"
</iq>
"
);
done
();
});
});
expect
(
_converse
.
bookmarks
.
length
).
toBe
(
1
);
expect
(
view
.
model
.
get
(
'
bookmarked
'
)).
toBeTruthy
();
var
bookmark_icon
=
view
.
el
.
querySelector
(
'
.toggle-bookmark
'
);
expect
(
u
.
hasClass
(
'
button-on
'
,
bookmark_icon
)).
toBeTruthy
();
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_stanza
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
spyOn
(
_converse
.
connection
,
'
getUniqueId
'
).
and
.
callThrough
();
bookmark_icon
.
click
();
expect
(
view
.
toggleBookmark
).
toHaveBeenCalled
();
expect
(
u
.
hasClass
(
'
button-on
'
,
bookmark_icon
)).
toBeFalsy
();
expect
(
_converse
.
bookmarks
.
length
).
toBe
(
0
);
// Check that an IQ stanza is sent out, containing no
// conferences to bookmark (since we removed the one and
// only bookmark).
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
"
<iq type='set' from='dummy@localhost/resource' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
"
+
"
<publish node='storage:bookmarks'>
"
+
"
<item id='current'>
"
+
"
<storage xmlns='storage:bookmarks'/>
"
+
"
</item>
"
+
"
</publish>
"
+
"
<publish-options>
"
+
"
<x xmlns='jabber:x:data' type='submit'>
"
+
"
<field var='FORM_TYPE' type='hidden'>
"
+
"
<value>http://jabber.org/protocol/pubsub#publish-options</value>
"
+
"
</field>
"
+
"
<field var='pubsub#persist_items'>
"
+
"
<value>true</value>
"
+
"
</field>
"
+
"
<field var='pubsub#access_model'>
"
+
"
<value>whitelist</value>
"
+
"
</field>
"
+
"
</x>
"
+
"
</publish-options>
"
+
"
</pubsub>
"
+
"
</iq>
"
);
done
();
});
});
}));
}));
});
});
...
@@ -585,9 +581,8 @@
...
@@ -585,9 +581,8 @@
'
name
'
:
'
The Play
'
,
'
name
'
:
'
The Play
'
,
'
nick
'
:
''
'
nick
'
:
''
});
});
test_utils
.
waitUntil
(
function
()
{
test_utils
.
waitUntil
(()
=>
$
(
'
#chatrooms .bookmarks.rooms-list .room-item:visible
'
).
length
return
$
(
'
#chatrooms .bookmarks.rooms-list .room-item:visible
'
).
length
;
).
then
(
function
()
{
},
300
).
then
(
function
()
{
expect
(
$
(
'
#chatrooms .bookmarks.rooms-list
'
).
hasClass
(
'
collapsed
'
)).
toBeFalsy
();
expect
(
$
(
'
#chatrooms .bookmarks.rooms-list
'
).
hasClass
(
'
collapsed
'
)).
toBeFalsy
();
expect
(
$
(
'
#chatrooms .bookmarks.rooms-list .room-item:visible
'
).
length
).
toBe
(
1
);
expect
(
$
(
'
#chatrooms .bookmarks.rooms-list .room-item:visible
'
).
length
).
toBe
(
1
);
expect
(
_converse
.
bookmarksview
.
list_model
.
get
(
'
toggle-state
'
)).
toBe
(
_converse
.
OPENED
);
expect
(
_converse
.
bookmarksview
.
list_model
.
get
(
'
toggle-state
'
)).
toBe
(
_converse
.
OPENED
);
...
@@ -612,6 +607,7 @@
...
@@ -612,6 +607,7 @@
{
hide_open_bookmarks
:
true
},
{
hide_open_bookmarks
:
true
},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
const
jid
=
'
room@conference.example.org
'
;
test_utils
.
waitUntilDiscoConfirmed
(
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
bare_jid
,
_converse
,
_converse
.
bare_jid
,
[{
'
category
'
:
'
pubsub
'
,
'
type
'
:
'
pep
'
}],
[{
'
category
'
:
'
pubsub
'
,
'
type
'
:
'
pep
'
}],
...
@@ -625,14 +621,12 @@
...
@@ -625,14 +621,12 @@
_converse
.
emit
(
'
bookmarksInitialized
'
);
_converse
.
emit
(
'
bookmarksInitialized
'
);
// Check that it's there
// Check that it's there
var
jid
=
'
room@conference.example.org
'
;
_converse
.
bookmarks
.
create
({
_converse
.
bookmarks
.
create
({
'
jid
'
:
jid
,
'
jid
'
:
jid
,
'
autojoin
'
:
false
,
'
autojoin
'
:
false
,
'
name
'
:
'
The Play
'
,
'
name
'
:
'
The Play
'
,
'
nick
'
:
'
Othello
'
'
nick
'
:
'
Othello
'
});
});
expect
(
_converse
.
bookmarks
.
length
).
toBe
(
1
);
expect
(
_converse
.
bookmarks
.
length
).
toBe
(
1
);
var
room_els
=
_converse
.
bookmarksview
.
el
.
querySelectorAll
(
"
.open-room
"
);
var
room_els
=
_converse
.
bookmarksview
.
el
.
querySelectorAll
(
"
.open-room
"
);
expect
(
room_els
.
length
).
toBe
(
1
);
expect
(
room_els
.
length
).
toBe
(
1
);
...
@@ -640,9 +634,11 @@
...
@@ -640,9 +634,11 @@
// Check that it disappears once the room is opened
// Check that it disappears once the room is opened
var
bookmark
=
_converse
.
bookmarksview
.
el
.
querySelector
(
"
.open-room
"
);
var
bookmark
=
_converse
.
bookmarksview
.
el
.
querySelector
(
"
.open-room
"
);
bookmark
.
click
();
bookmark
.
click
();
return
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxviews
.
get
(
jid
));
}).
then
(()
=>
{
expect
(
u
.
hasClass
(
'
hidden
'
,
_converse
.
bookmarksview
.
el
.
querySelector
(
"
.available-chatroom
"
))).
toBeTruthy
();
expect
(
u
.
hasClass
(
'
hidden
'
,
_converse
.
bookmarksview
.
el
.
querySelector
(
"
.available-chatroom
"
))).
toBeTruthy
();
// Check that it reappears once the room is closed
// Check that it reappears once the room is closed
var
view
=
_converse
.
chatboxviews
.
get
(
jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
jid
);
view
.
close
();
view
.
close
();
expect
(
u
.
hasClass
(
'
hidden
'
,
_converse
.
bookmarksview
.
el
.
querySelector
(
"
.available-chatroom
"
))).
toBeFalsy
();
expect
(
u
.
hasClass
(
'
hidden
'
,
_converse
.
bookmarksview
.
el
.
querySelector
(
"
.available-chatroom
"
))).
toBeFalsy
();
done
();
done
();
...
...
spec/chatbox.js
View file @
506aa331
...
@@ -7,11 +7,12 @@
...
@@ -7,11 +7,12 @@
],
factory
);
],
factory
);
}
(
this
,
function
(
$
,
jasmine
,
mock
,
test_utils
)
{
}
(
this
,
function
(
$
,
jasmine
,
mock
,
test_utils
)
{
"
use strict
"
;
"
use strict
"
;
var
_
=
converse
.
env
.
_
;
const
_
=
converse
.
env
.
_
;
var
$iq
=
converse
.
env
.
$iq
;
const
$iq
=
converse
.
env
.
$iq
;
var
$msg
=
converse
.
env
.
$msg
;
const
$msg
=
converse
.
env
.
$msg
;
var
Strophe
=
converse
.
env
.
Strophe
;
const
Strophe
=
converse
.
env
.
Strophe
;
var
u
=
converse
.
env
.
utils
;
const
u
=
converse
.
env
.
utils
;
const
sizzle
=
converse
.
env
.
sizzle
;
return
describe
(
"
Chatboxes
"
,
function
()
{
return
describe
(
"
Chatboxes
"
,
function
()
{
...
@@ -158,45 +159,50 @@
...
@@ -158,45 +159,50 @@
}));
}));
it
(
"
can be trimmed to conserve space
"
,
it
(
"
can be trimmed to conserve space
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
spyOn
(
_converse
.
chatboxviews
,
'
trimChats
'
);
const
trimmed_chatboxes
=
_converse
.
minimized_chats
;
spyOn
(
trimmed_chatboxes
,
'
addChat
'
).
and
.
callThrough
();
spyOn
(
trimmed_chatboxes
,
'
removeChat
'
).
and
.
callThrough
();
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
i
,
$el
,
jid
,
chatbox
,
chatboxview
,
trimmedview
;
let
online_contacts
;
var
i
,
jid
,
chatbox
,
chatboxview
,
trimmedview
;
// openControlBox was called earlier, so the controlbox is
// openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created.
// visible, but no other chat boxes have been created.
var
trimmed_chatboxes
=
_converse
.
minimized_chats
;
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
1
);
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
1
);
spyOn
(
_converse
.
chatboxviews
,
'
trimChats
'
);
expect
(
document
.
querySelectorAll
(
"
#conversejs .chatbox
"
).
length
).
toBe
(
1
);
// Controlbox is open
spyOn
(
trimmed_chatboxes
,
'
addChat
'
).
and
.
callThrough
();
spyOn
(
trimmed_chatboxes
,
'
removeChat
'
).
and
.
callThrough
();
expect
(
$
(
"
#conversejs .chatbox
"
).
length
).
toBe
(
1
);
// Controlbox is open
_converse
.
rosterview
.
update
();
// XXX: Hack to make sure $roster element is attached.
_converse
.
rosterview
.
update
();
// XXX: Hack to make sure $roster element is attached.
test_utils
.
waitUntil
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group li
'
).
length
)
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group li
'
).
length
;
.
then
(()
=>
{
},
700
).
then
(
function
()
{
// Test that they can be maximized again
// Test that they can be maximized again
var
online_contacts
=
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group .current-xmpp-contact a.open-chat
'
);
online_contacts
=
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group .current-xmpp-contact a.open-chat
'
);
expect
(
online_contacts
.
length
).
toBe
(
15
);
expect
(
online_contacts
.
length
).
toBe
(
15
);
for
(
i
=
0
;
i
<
online_contacts
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
online_contacts
.
length
;
i
++
)
{
$el
=
$
(
online_contacts
[
i
]);
const
el
=
online_contacts
[
i
];
jid
=
_
.
trim
(
$el
.
text
().
trim
()).
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
el
.
click
();
$el
[
0
].
click
();
}
expect
(
_converse
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
();
return
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxes
.
length
==
16
)
}).
then
(()
=>
{
expect
(
_converse
.
chatboxviews
.
trimChats
.
calls
.
count
()).
toBe
(
16
);
for
(
i
=
0
;
i
<
online_contacts
.
length
;
i
++
)
{
const
el
=
online_contacts
[
i
];
jid
=
_
.
trim
(
el
.
textContent
.
trim
()).
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
chatboxview
=
_converse
.
chatboxviews
.
get
(
jid
);
chatboxview
=
_converse
.
chatboxviews
.
get
(
jid
);
spyOn
(
chatboxview
,
'
minimize
'
).
and
.
callThrough
();
spyOn
(
chatboxview
,
'
minimize
'
).
and
.
callThrough
();
chatboxview
.
model
.
set
({
'
minimized
'
:
true
});
chatboxview
.
model
.
set
({
'
minimized
'
:
true
});
expect
(
trimmed_chatboxes
.
addChat
).
toHaveBeenCalled
();
expect
(
trimmed_chatboxes
.
addChat
).
toHaveBeenCalled
();
expect
(
chatboxview
.
minimize
).
toHaveBeenCalled
();
expect
(
chatboxview
.
minimize
).
toHaveBeenCalled
();
}
}
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxviews
.
keys
().
length
);
return
_converse
.
chatboxviews
.
keys
().
length
>
1
;
},
500
);
}).
then
(
function
()
{
}).
then
(
function
()
{
var
key
=
_converse
.
chatboxviews
.
keys
()[
1
];
var
key
=
_converse
.
chatboxviews
.
keys
()[
1
];
trimmedview
=
trimmed_chatboxes
.
get
(
key
);
trimmedview
=
trimmed_chatboxes
.
get
(
key
);
...
@@ -208,10 +214,9 @@
...
@@ -208,10 +214,9 @@
expect
(
trimmedview
.
restore
).
toHaveBeenCalled
();
expect
(
trimmedview
.
restore
).
toHaveBeenCalled
();
expect
(
chatbox
.
maximize
).
toHaveBeenCalled
();
expect
(
chatbox
.
maximize
).
toHaveBeenCalled
();
expect
(
_converse
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
(
);
expect
(
_converse
.
chatboxviews
.
trimChats
.
calls
.
count
()).
toBe
(
17
);
done
();
done
();
});
});
done
();
}));
}));
it
(
"
can be opened in minimized mode initially
"
,
it
(
"
can be opened in minimized mode initially
"
,
...
@@ -237,29 +242,26 @@
...
@@ -237,29 +242,26 @@
it
(
"
is focused if its already open and you click on its corresponding roster item
"
,
it
(
"
is focused if its already open and you click on its corresponding roster item
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
rosterview
.
update
();
// XXX: Hack to make sure $roster element is attaced.
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
$el
,
jid
,
chatbox
;
let
el
,
jid
;
// openControlBox was called earlier, so the controlbox is
// openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created.
// visible, but no other chat boxes have been created.
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
1
);
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
1
);
chatbox
=
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
$el
=
$
(
_converse
.
rosterview
.
el
).
find
(
'
a.open-chat:contains("
'
+
chatbox
.
getDisplayName
()
+
'
")
'
);
.
then
((
view
)
=>
{
jid
=
$el
.
text
().
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
el
=
sizzle
(
'
a.open-chat:contains("
'
+
view
.
model
.
getDisplayName
()
+
'
")
'
,
_converse
.
rosterview
.
el
).
pop
();
jid
=
el
.
textContent
.
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
$el
[
0
].
click
();
el
.
click
();
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
_converse
.
emit
.
calls
.
count
(),
500
);
return
_converse
.
emit
.
calls
.
count
();
}).
then
(()
=>
{
},
300
).
then
(
function
()
{
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
2
);
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
2
);
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxFocused
'
,
jasmine
.
any
(
Object
));
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxFocused
'
,
jasmine
.
any
(
Object
));
done
();
done
();
...
@@ -268,10 +270,11 @@
...
@@ -268,10 +270,11 @@
it
(
"
can be saved to, and retrieved from, browserStorage
"
,
it
(
"
can be saved to, and retrieved from, browserStorage
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
,
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
...
@@ -279,41 +282,46 @@
...
@@ -279,41 +282,46 @@
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
openChatBoxes
(
_converse
,
6
);
test_utils
.
openChatBoxes
(
_converse
,
6
);
expect
(
_converse
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
();
return
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxes
.
length
==
7
).
then
(()
=>
{
// We instantiate a new ChatBoxes collection, which by default
expect
(
_converse
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
();
// will be empty.
// We instantiate a new ChatBoxes collection, which by default
var
newchatboxes
=
new
_converse
.
ChatBoxes
();
// will be empty.
expect
(
newchatboxes
.
length
).
toEqual
(
0
);
const
newchatboxes
=
new
_converse
.
ChatBoxes
();
// The chatboxes will then be fetched from browserStorage inside the
expect
(
newchatboxes
.
length
).
toEqual
(
0
);
// onConnected method
// The chatboxes will then be fetched from browserStorage inside the
newchatboxes
.
onConnected
();
// onConnected method
expect
(
newchatboxes
.
length
).
toEqual
(
7
);
newchatboxes
.
onConnected
();
// Check that the chatboxes items retrieved from browserStorage
expect
(
newchatboxes
.
length
).
toEqual
(
7
);
// have the same attributes values as the original ones.
// Check that the chatboxes items retrieved from browserStorage
var
attrs
=
[
'
id
'
,
'
box_id
'
,
'
visible
'
];
// have the same attributes values as the original ones.
var
new_attrs
,
old_attrs
;
const
attrs
=
[
'
id
'
,
'
box_id
'
,
'
visible
'
];
for
(
var
i
=
0
;
i
<
attrs
.
length
;
i
++
)
{
let
new_attrs
,
old_attrs
;
new_attrs
=
_
.
map
(
_
.
map
(
newchatboxes
.
models
,
'
attributes
'
),
attrs
[
i
]);
for
(
var
i
=
0
;
i
<
attrs
.
length
;
i
++
)
{
old_attrs
=
_
.
map
(
_
.
map
(
_converse
.
chatboxes
.
models
,
'
attributes
'
),
attrs
[
i
]);
new_attrs
=
_
.
map
(
_
.
map
(
newchatboxes
.
models
,
'
attributes
'
),
attrs
[
i
]);
expect
(
_
.
isEqual
(
new_attrs
,
old_attrs
)).
toEqual
(
true
);
old_attrs
=
_
.
map
(
_
.
map
(
_converse
.
chatboxes
.
models
,
'
attributes
'
),
attrs
[
i
]);
}
expect
(
_
.
isEqual
(
new_attrs
,
old_attrs
)).
toEqual
(
true
);
_converse
.
rosterview
.
render
();
}
done
();
_converse
.
rosterview
.
render
();
done
();
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
}));
}));
it
(
"
can be closed by clicking a DOM element with class 'close-chatbox-button'
"
,
it
(
"
can be closed by clicking a DOM element with class 'close-chatbox-button'
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
const
contact_jid
=
mock
.
cur_names
[
7
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
},
300
).
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
)
var
chatbox
=
test_utils
.
openChatBoxes
(
_converse
,
1
)[
0
],
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
))
controlview
=
_converse
.
chatboxviews
.
get
(
'
controlbox
'
),
// The controlbox is currently open
.
then
(()
=>
{
chatview
=
_converse
.
chatboxviews
.
get
(
chatbox
.
get
(
'
jid
'
));
var
controlview
=
_converse
.
chatboxviews
.
get
(
'
controlbox
'
),
// The controlbox is currently open
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
chatview
,
'
close
'
).
and
.
callThrough
();
spyOn
(
chatview
,
'
close
'
).
and
.
callThrough
();
spyOn
(
controlview
,
'
close
'
).
and
.
callThrough
();
spyOn
(
controlview
,
'
close
'
).
and
.
callThrough
();
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
...
@@ -338,20 +346,22 @@
...
@@ -338,20 +346,22 @@
it
(
"
can be minimized by clicking a DOM element with class 'toggle-chatbox-button'
"
,
it
(
"
can be minimized by clicking a DOM element with class 'toggle-chatbox-button'
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
var
chatview
;
let
chatview
;
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
const
contact_jid
=
mock
.
cur_names
[
7
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
},
300
)
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
)
.
then
(
function
()
{
.
then
(
()
=>
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
))
var
chatbox
=
test_utils
.
openChatBoxes
(
_converse
,
1
)[
0
],
.
then
(()
=>
{
trimmed_chatboxes
=
_converse
.
minimized_chats
,
var
trimmed_chatboxes
=
_converse
.
minimized_chats
,
trimmedview
;
trimmedview
;
chatview
=
_converse
.
chatboxviews
.
get
(
c
hatbox
.
get
(
'
jid
'
)
);
chatview
=
_converse
.
chatboxviews
.
get
(
c
ontact_jid
);
spyOn
(
chatview
,
'
minimize
'
).
and
.
callThrough
();
spyOn
(
chatview
,
'
minimize
'
).
and
.
callThrough
();
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
// We need to rebind all events otherwise our spy won't be called
// We need to rebind all events otherwise our spy won't be called
...
@@ -372,9 +382,7 @@
...
@@ -372,9 +382,7 @@
expect
(
trimmedview
.
restore
).
toHaveBeenCalled
();
expect
(
trimmedview
.
restore
).
toHaveBeenCalled
();
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxMaximized
'
,
jasmine
.
any
(
Object
));
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxMaximized
'
,
jasmine
.
any
(
Object
));
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
chatview
.
el
.
querySelector
(
'
.chat-body
'
)),
500
);
return
$
(
chatview
.
el
).
find
(
'
.chat-body
'
).
is
(
'
:visible
'
);
},
500
);
}).
then
(
function
()
{
}).
then
(
function
()
{
expect
(
$
(
chatview
.
el
).
find
(
'
.toggle-chatbox-button
'
).
hasClass
(
'
fa-minus
'
)).
toBeTruthy
();
expect
(
$
(
chatview
.
el
).
find
(
'
.toggle-chatbox-button
'
).
hasClass
(
'
fa-minus
'
)).
toBeTruthy
();
expect
(
$
(
chatview
.
el
).
find
(
'
.toggle-chatbox-button
'
).
hasClass
(
'
fa-plus
'
)).
toBeFalsy
();
expect
(
$
(
chatview
.
el
).
find
(
'
.toggle-chatbox-button
'
).
hasClass
(
'
fa-plus
'
)).
toBeFalsy
();
...
@@ -385,14 +393,14 @@
...
@@ -385,14 +393,14 @@
it
(
"
will be removed from browserStorage when closed
"
,
it
(
"
will be removed from browserStorage when closed
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
)
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
.
then
(()
=>
{
},
300
).
then
(
function
()
{
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
.
chatboxviews
,
'
trimChats
'
);
spyOn
(
_converse
.
chatboxviews
,
'
trimChats
'
);
_converse
.
chatboxes
.
browserStorage
.
_clear
();
_converse
.
chatboxes
.
browserStorage
.
_clear
();
...
@@ -403,6 +411,8 @@
...
@@ -403,6 +411,8 @@
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
1
);
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
1
);
expect
(
_converse
.
chatboxes
.
pluck
(
'
id
'
)).
toEqual
([
'
controlbox
'
]);
expect
(
_converse
.
chatboxes
.
pluck
(
'
id
'
)).
toEqual
([
'
controlbox
'
]);
test_utils
.
openChatBoxes
(
_converse
,
6
);
test_utils
.
openChatBoxes
(
_converse
,
6
);
return
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxes
.
length
==
7
)
}).
then
(()
=>
{
expect
(
_converse
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
();
expect
(
_converse
.
chatboxviews
.
trimChats
).
toHaveBeenCalled
();
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
7
);
expect
(
_converse
.
chatboxes
.
length
).
toEqual
(
7
);
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxOpened
'
,
jasmine
.
any
(
Object
));
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxOpened
'
,
jasmine
.
any
(
Object
));
...
@@ -428,77 +438,70 @@
...
@@ -428,77 +438,70 @@
it
(
"
can be found on each chat box
"
,
it
(
"
can be found on each chat box
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
var
chatbox
=
_converse
.
chatboxes
.
get
(
contact_jid
);
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
contact_jid
);
expect
(
chatbox
).
toBeDefined
();
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
expect
(
view
).
toBeDefined
();
expect
(
chatbox
).
toBeDefined
();
var
toolbar
=
view
.
el
.
querySelector
(
'
ul.chat-toolbar
'
);
expect
(
view
).
toBeDefined
();
expect
(
_
.
isElement
(
toolbar
)).
toBe
(
true
);
var
toolbar
=
view
.
el
.
querySelector
(
'
ul.chat-toolbar
'
);
expect
(
toolbar
.
querySelectorAll
(
'
:scope > li
'
).
length
).
toBe
(
1
);
expect
(
_
.
isElement
(
toolbar
)).
toBe
(
true
);
done
();
expect
(
toolbar
.
querySelectorAll
(
'
:scope > li
'
).
length
).
toBe
(
1
);
done
();
});
}));
}));
it
(
"
contains a button for inserting emojis
"
,
it
(
"
contains a button for inserting emojis
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
let
timeout
=
false
,
view
,
toolbar
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
;
const
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
var
toolbar
=
view
.
el
.
querySelector
(
'
ul.chat-toolbar
'
);
.
then
(()
=>
{
expect
(
toolbar
.
querySelectorAll
(
'
li.toggle-smiley
'
).
length
).
toBe
(
1
);
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
// Register spies
toolbar
=
view
.
el
.
querySelector
(
'
ul.chat-toolbar
'
);
spyOn
(
view
,
'
toggleEmojiMenu
'
).
and
.
callThrough
(
);
expect
(
toolbar
.
querySelectorAll
(
'
li.toggle-smiley
'
).
length
).
toBe
(
1
);
spyOn
(
view
,
'
insertEmoji
'
).
and
.
callThrough
();
// Register spies
spyOn
(
view
,
'
toggleEmojiMenu
'
).
and
.
callThrough
();
view
.
delegateEvents
();
// We need to rebind all events otherwise our spy won't be called
spyOn
(
view
,
'
insertEmoji
'
).
and
.
callThrough
();
toolbar
.
querySelector
(
'
li.toggle-smiley
'
).
click
();
view
.
delegateEvents
();
// We need to rebind all events otherwise our spy won't be called
var
timeout
=
false
;
toolbar
.
querySelector
(
'
li.toggle-smiley
'
).
click
()
;
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
view
.
el
.
querySelector
(
'
.toggle-smiley .emoji-picker-container
'
),
500
));
return
u
.
isVisible
(
view
.
el
.
querySelector
(
'
.toggle-smiley .emoji-picker-container
'
));
}).
then
(()
=>
{
},
500
).
then
(
function
()
{
var
picker
=
view
.
el
.
querySelector
(
'
.toggle-smiley .emoji-picker-container
'
);
var
picker
=
view
.
el
.
querySelector
(
'
.toggle-smiley .emoji-picker-container
'
);
var
items
=
picker
.
querySelectorAll
(
'
.emoji-picker li
'
);
var
items
=
picker
.
querySelectorAll
(
'
.emoji-picker li
'
);
items
[
0
].
click
()
items
[
0
].
click
()
expect
(
view
.
insertEmoji
).
toHaveBeenCalled
();
expect
(
view
.
insertEmoji
).
toHaveBeenCalled
();
setTimeout
(
function
()
{
timeout
=
true
;
},
100
);
setTimeout
(
function
()
{
timeout
=
true
;
},
100
);
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
timeout
,
500
);
return
timeout
;
}).
then
(()
=>
{
},
500
);
}).
then
(
function
()
{
timeout
=
false
;
timeout
=
false
;
toolbar
.
querySelector
(
'
li.toggle-smiley
'
).
click
();
// Close the panel again
toolbar
.
querySelector
(
'
li.toggle-smiley
'
).
click
();
// Close the panel again
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
!
view
.
el
.
querySelector
(
'
.toggle-smiley .toolbar-menu
'
).
offsetHeight
,
500
);
return
!
view
.
el
.
querySelector
(
'
.toggle-smiley .toolbar-menu
'
).
offsetHeight
;
}).
then
(()
=>
{
},
500
);
}).
then
(
function
()
{
setTimeout
(
function
()
{
timeout
=
true
;
},
100
);
setTimeout
(
function
()
{
timeout
=
true
;
},
100
);
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
timeout
,
500
);
return
timeout
;
}).
then
(()
=>
{
},
500
);
}).
then
(
function
()
{
toolbar
.
querySelector
(
'
li.toggle-smiley
'
).
click
();
toolbar
.
querySelector
(
'
li.toggle-smiley
'
).
click
();
expect
(
view
.
toggleEmojiMenu
).
toHaveBeenCalled
();
expect
(
view
.
toggleEmojiMenu
).
toHaveBeenCalled
();
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
view
.
el
.
querySelector
(
'
.toggle-smiley .emoji-picker-container
'
)),
500
);
var
$picker
=
$
(
view
.
el
).
find
(
'
.toggle-smiley .emoji-picker-container
'
);
}).
then
(()
=>
{
return
u
.
isVisible
(
$picker
[
0
]);
},
500
);
}).
then
(
function
()
{
var
nodes
=
view
.
el
.
querySelectorAll
(
'
.toggle-smiley ul li
'
);
var
nodes
=
view
.
el
.
querySelectorAll
(
'
.toggle-smiley ul li
'
);
nodes
[
nodes
.
length
-
1
].
click
();
nodes
[
nodes
.
length
-
1
].
click
();
expect
(
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
).
value
).
toBe
(
'
:grinning:
'
);
expect
(
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
).
value
).
toBe
(
'
:grinning:
'
);
...
@@ -509,34 +512,38 @@
...
@@ -509,34 +512,38 @@
it
(
"
can contain a button for starting a call
"
,
it
(
"
can contain a button for starting a call
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
view
;
let
view
,
toolbar
,
call_button
;
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
// First check that the button doesn't show if it's not enabled
// First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons"
// via "visible_toolbar_buttons"
_converse
.
visible_toolbar_buttons
.
call
=
false
;
_converse
.
visible_toolbar_buttons
.
call
=
false
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
var
toolbar
=
view
.
el
.
querySelector
(
'
ul.chat-toolbar
'
);
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
call_button
=
toolbar
.
querySelector
(
'
.toggle-call
'
);
toolbar
=
view
.
el
.
querySelector
(
'
ul.chat-toolbar
'
);
expect
(
_
.
isNull
(
call_button
)).
toBeTruthy
();
call_button
=
toolbar
.
querySelector
(
'
.toggle-call
'
);
view
.
close
();
expect
(
_
.
isNull
(
call_button
)).
toBeTruthy
();
// Now check that it's shown if enabled and that it emits
view
.
close
();
// callButtonClicked
// Now check that it's shown if enabled and that it emits
_converse
.
visible_toolbar_buttons
.
call
=
true
;
// enable the button
// callButtonClicked
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
_converse
.
visible_toolbar_buttons
.
call
=
true
;
// enable the button
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
return
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
toolbar
=
view
.
el
.
querySelector
(
'
ul.chat-toolbar
'
);
}).
then
(()
=>
{
call_button
=
toolbar
.
querySelector
(
'
.toggle-call
'
);
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
call_button
.
click
();
toolbar
=
view
.
el
.
querySelector
(
'
ul.chat-toolbar
'
);
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
callButtonClicked
'
,
jasmine
.
any
(
Object
));
call_button
=
toolbar
.
querySelector
(
'
.toggle-call
'
);
done
();
call_button
.
click
();
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
callButtonClicked
'
,
jasmine
.
any
(
Object
));
done
();
});
}));
}));
});
});
...
@@ -568,17 +575,19 @@
...
@@ -568,17 +575,19 @@
it
(
"
is sent when the user opens a chat box
"
,
it
(
"
is sent when the user opens a chat box
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
test_utils
.
waitUntil
(
function
()
{
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
},
300
).
then
(
function
()
{
},
300
).
then
(
function
()
{
spyOn
(
_converse
.
connection
,
'
send
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
return
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
}).
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
active
'
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
active
'
);
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
...
@@ -593,26 +602,24 @@
...
@@ -593,26 +602,24 @@
}));
}));
it
(
"
is sent when the user maximizes a minimized a chat box
"
,
mock
.
initConverseWithPromises
(
it
(
"
is sent when the user maximizes a minimized a chat box
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
waitUntil
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
)
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
))
},
500
).
then
(
function
()
{
.
then
(()
=>
{
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
view
.
model
.
minimize
();
view
.
model
.
minimize
();
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
inactive
'
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
inactive
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
view
.
model
.
maximize
();
view
.
model
.
maximize
();
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
view
.
model
.
get
(
'
chat_state
'
)
===
'
active
'
,
700
);
return
view
.
model
.
get
(
'
chat_state
'
)
===
'
active
'
;
}).
then
(()
=>
{
},
700
);
}).
then
(
function
()
{
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
var
calls
=
_
.
filter
(
_converse
.
connection
.
send
.
calls
.
all
(),
function
(
call
)
{
var
calls
=
_
.
filter
(
_converse
.
connection
.
send
.
calls
.
all
(),
function
(
call
)
{
return
call
.
args
[
0
]
instanceof
Strophe
.
Builder
;
return
call
.
args
[
0
]
instanceof
Strophe
.
Builder
;
...
@@ -633,16 +640,17 @@
...
@@ -633,16 +640,17 @@
it
(
"
is sent as soon as the user starts typing a message which is not a command
"
,
it
(
"
is sent as soon as the user starts typing a message which is not a command
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
},
300
).
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
)
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
))
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
active
'
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
active
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
...
@@ -720,21 +728,20 @@
...
@@ -720,21 +728,20 @@
it
(
"
can be a composing carbon message that this user sent from a different client
"
,
it
(
"
can be a composing carbon message that this user sent from a different client
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
var
contact
,
sent_stanza
,
IQ_id
,
stanza
;
let
contact
,
sent_stanza
,
IQ_id
,
stanza
,
recipient_jid
;
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
localhost
'
,
[],
[
'
vcard-temp
'
])
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
localhost
'
,
[],
[
'
vcard-temp
'
])
.
then
(()
=>
test_utils
.
waitUntil
(()
=>
_converse
.
xmppstatus
.
vcard
.
get
(
'
fullname
'
)))
.
then
(
function
()
{
.
then
(
function
()
{
return
test_utils
.
waitUntil
(
function
()
{
return
_converse
.
xmppstatus
.
vcard
.
get
(
'
fullname
'
);
},
300
);
}).
then
(
function
()
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
// Send a message from a different resource
// Send a message from a different resource
spyOn
(
_converse
,
'
log
'
);
spyOn
(
_converse
,
'
log
'
);
var
recipient_jid
=
mock
.
cur_names
[
5
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
recipient_jid
=
mock
.
cur_names
[
5
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
recipient_jid
);
return
test_utils
.
openChatBoxFor
(
_converse
,
recipient_jid
);
}).
then
(()
=>
{
var
msg
=
$msg
({
var
msg
=
$msg
({
'
from
'
:
_converse
.
bare_jid
,
'
from
'
:
_converse
.
bare_jid
,
'
id
'
:
(
new
Date
()).
getTime
(),
'
id
'
:
(
new
Date
()).
getTime
(),
...
@@ -771,19 +778,19 @@
...
@@ -771,19 +778,19 @@
it
(
"
is sent if the user has stopped typing since 30 seconds
"
,
it
(
"
is sent if the user has stopped typing since 30 seconds
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
var
view
,
contact_jid
;
let
view
;
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group li
'
).
length
,
700
)
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group li
'
).
length
;
.
then
(()
=>
{
},
700
).
then
(
function
()
{
_converse
.
TIMEOUTS
.
PAUSED
=
200
;
// Make the timeout shorter so that we can test
_converse
.
TIMEOUTS
.
PAUSED
=
200
;
// Make the timeout shorter so that we can test
return
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
}).
then
(()
=>
{
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
_converse
.
connection
,
'
send
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
spyOn
(
view
,
'
setChatState
'
).
and
.
callThrough
();
spyOn
(
view
,
'
setChatState
'
).
and
.
callThrough
();
...
@@ -796,10 +803,8 @@
...
@@ -796,10 +803,8 @@
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
var
$stanza
=
$
(
_converse
.
connection
.
send
.
calls
.
argsFor
(
0
)[
0
].
tree
());
var
$stanza
=
$
(
_converse
.
connection
.
send
.
calls
.
argsFor
(
0
)[
0
].
tree
());
expect
(
$stanza
.
children
().
get
(
0
).
tagName
).
toBe
(
'
composing
'
);
expect
(
$stanza
.
children
().
get
(
0
).
tagName
).
toBe
(
'
composing
'
);
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
view
.
model
.
get
(
'
chat_state
'
)
===
'
paused
'
,
500
);
return
view
.
model
.
get
(
'
chat_state
'
)
===
'
paused
'
;
}).
then
(()
=>
{
},
500
);
}).
then
(
function
()
{
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
var
calls
=
_
.
filter
(
_converse
.
connection
.
send
.
calls
.
all
(),
function
(
call
)
{
var
calls
=
_
.
filter
(
_converse
.
connection
.
send
.
calls
.
all
(),
function
(
call
)
{
return
call
.
args
[
0
]
instanceof
Strophe
.
Builder
;
return
call
.
args
[
0
]
instanceof
Strophe
.
Builder
;
...
@@ -828,7 +833,7 @@
...
@@ -828,7 +833,7 @@
});
});
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
composing
'
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
composing
'
);
done
();
done
();
})
;
})
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
))
}));
}));
it
(
"
will be shown if received
"
,
it
(
"
will be shown if received
"
,
...
@@ -868,21 +873,20 @@
...
@@ -868,21 +873,20 @@
it
(
"
can be a paused carbon message that this user sent from a different client
"
,
it
(
"
can be a paused carbon message that this user sent from a different client
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
var
contact
,
sent_stanza
,
IQ_id
,
stanza
;
let
contact
,
sent_stanza
,
IQ_id
,
stanza
,
recipient_jid
;
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
localhost
'
,
[],
[
'
vcard-temp
'
])
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
localhost
'
,
[],
[
'
vcard-temp
'
])
.
then
(
function
()
{
.
then
(()
=>
test_utils
.
waitUntil
(()
=>
_converse
.
xmppstatus
.
vcard
.
get
(
'
fullname
'
)))
return
test_utils
.
waitUntil
(
function
()
{
.
then
(()
=>
{
return
_converse
.
xmppstatus
.
vcard
.
get
(
'
fullname
'
);
},
300
);
}).
then
(
function
()
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
// Send a message from a different resource
// Send a message from a different resource
spyOn
(
_converse
,
'
log
'
);
spyOn
(
_converse
,
'
log
'
);
var
recipient_jid
=
mock
.
cur_names
[
5
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
recipient_jid
=
mock
.
cur_names
[
5
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
recipient_jid
);
return
test_utils
.
openChatBoxFor
(
_converse
,
recipient_jid
);
}).
then
(()
=>
{
var
msg
=
$msg
({
var
msg
=
$msg
({
'
from
'
:
_converse
.
bare_jid
,
'
from
'
:
_converse
.
bare_jid
,
'
id
'
:
(
new
Date
()).
getTime
(),
'
id
'
:
(
new
Date
()).
getTime
(),
...
@@ -979,38 +983,40 @@
...
@@ -979,38 +983,40 @@
it
(
"
is sent when the user a minimizes a chat box
"
,
it
(
"
is sent when the user a minimizes a chat box
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
spyOn
(
_converse
.
connection
,
'
send
'
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
view
.
minimize
();
spyOn
(
_converse
.
connection
,
'
send
'
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
inactive
'
);
view
.
minimize
();
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
inactive
'
);
var
$stanza
=
$
(
_converse
.
connection
.
send
.
calls
.
argsFor
(
0
)[
0
].
tree
());
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
expect
(
$stanza
.
attr
(
'
to
'
)).
toBe
(
contact_jid
);
var
$stanza
=
$
(
_converse
.
connection
.
send
.
calls
.
argsFor
(
0
)[
0
].
tree
());
expect
(
$stanza
.
children
().
get
(
0
).
tagName
).
toBe
(
'
inactive
'
);
expect
(
$stanza
.
attr
(
'
to
'
)).
toBe
(
contact_jid
);
done
();
expect
(
$stanza
.
children
().
get
(
0
).
tagName
).
toBe
(
'
inactive
'
);
done
();
});
}));
}));
it
(
"
is sent if the user closes a chat box
"
,
it
(
"
is sent if the user closes a chat box
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
)
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
))
},
300
).
then
(
function
()
{
.
then
((
view
)
=>
{
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
active
'
);
expect
(
view
.
model
.
get
(
'
chat_state
'
)).
toBe
(
'
active
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
view
.
close
();
view
.
close
();
...
@@ -1028,40 +1034,43 @@
...
@@ -1028,40 +1034,43 @@
it
(
"
will clear any other chat status notifications
"
,
it
(
"
will clear any other chat status notifications
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
const
sender_jid
=
mock
.
cur_names
[
1
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
var
sender_jid
=
mock
.
cur_names
[
1
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-event
'
).
length
).
toBe
(
0
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-event
'
).
length
).
toBe
(
0
);
// Insert <composing> message, to also check that
// Insert <composing> message, to also check that
// text messages are inserted correctly with
// text messages are inserted correctly with
// temporary chat events in the chat contents.
// temporary chat events in the chat contents.
var
msg
=
$msg
({
var
msg
=
$msg
({
'
to
'
:
_converse
.
bare_jid
,
'
to
'
:
_converse
.
bare_jid
,
'
xmlns
'
:
'
jabber:client
'
,
'
xmlns
'
:
'
jabber:client
'
,
'
from
'
:
sender_jid
,
'
from
'
:
sender_jid
,
'
type
'
:
'
chat
'
})
'
type
'
:
'
chat
'
})
.
c
(
'
composing
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
CHATSTATES
}).
up
()
.
c
(
'
composing
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
CHATSTATES
}).
up
()
.
tree
();
.
tree
();
_converse
.
chatboxes
.
onMessage
(
msg
);
_converse
.
chatboxes
.
onMessage
(
msg
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-state-notification
'
).
length
).
toBe
(
1
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-state-notification
'
).
length
).
toBe
(
1
);
msg
=
$msg
({
msg
=
$msg
({
from
:
sender_jid
,
from
:
sender_jid
,
to
:
_converse
.
connection
.
jid
,
to
:
_converse
.
connection
.
jid
,
type
:
'
chat
'
,
type
:
'
chat
'
,
id
:
(
new
Date
()).
getTime
()
id
:
(
new
Date
()).
getTime
()
}).
c
(
'
body
'
).
c
(
'
inactive
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
CHATSTATES
}).
tree
();
}).
c
(
'
body
'
).
c
(
'
inactive
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
CHATSTATES
}).
tree
();
_converse
.
chatboxes
.
onMessage
(
msg
);
_converse
.
chatboxes
.
onMessage
(
msg
);
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
message
'
,
jasmine
.
any
(
Object
));
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
message
'
,
jasmine
.
any
(
Object
));
expect
(
$
(
view
.
el
).
find
(
'
.chat-state-notification
'
).
length
).
toBe
(
0
);
expect
(
$
(
view
.
el
).
find
(
'
.chat-state-notification
'
).
length
).
toBe
(
0
);
done
();
done
();
});
}));
}));
});
});
...
@@ -1103,39 +1112,42 @@
...
@@ -1103,39 +1112,42 @@
it
(
"
'/clear' can be used to clear messages in a conversation
"
,
it
(
"
'/clear' can be used to clear messages in a conversation
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
message
=
'
This message is another sent from this chatbox
'
;
var
message
=
'
This message is another sent from this chatbox
'
;
// Lets make sure there is at least one message already
// Lets make sure there is at least one message already
// (e.g for when this test is run on its own).
// (e.g for when this test is run on its own).
test_utils
.
sendMessage
(
view
,
message
);
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
model
.
messages
.
length
>
0
).
toBeTruthy
();
expect
(
view
.
model
.
messages
.
length
>
0
).
toBeTruthy
();
expect
(
view
.
model
.
messages
.
browserStorage
.
records
.
length
>
0
).
toBeTruthy
();
expect
(
view
.
model
.
messages
.
browserStorage
.
records
.
length
>
0
).
toBeTruthy
();
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
messageSend
'
,
message
);
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
messageSend
'
,
message
);
message
=
'
/clear
'
;
message
=
'
/clear
'
;
spyOn
(
view
,
'
onMessageSubmitted
'
).
and
.
callThrough
();
spyOn
(
view
,
'
onMessageSubmitted
'
).
and
.
callThrough
();
spyOn
(
view
,
'
clearMessages
'
).
and
.
callThrough
();
spyOn
(
view
,
'
clearMessages
'
).
and
.
callThrough
();
spyOn
(
window
,
'
confirm
'
).
and
.
callFake
(
function
()
{
spyOn
(
window
,
'
confirm
'
).
and
.
callFake
(
function
()
{
return
true
;
return
true
;
});
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
onMessageSubmitted
).
toHaveBeenCalled
();
expect
(
view
.
clearMessages
).
toHaveBeenCalled
();
expect
(
window
.
confirm
).
toHaveBeenCalled
();
expect
(
view
.
model
.
messages
.
length
,
0
);
// The messages must be removed from the chatbox
expect
(
view
.
model
.
messages
.
browserStorage
.
records
.
length
,
0
);
// And also from browserStorage
expect
(
_converse
.
emit
.
calls
.
count
(),
1
);
expect
(
_converse
.
emit
.
calls
.
mostRecent
().
args
,
[
'
messageSend
'
,
message
]);
done
();
});
});
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
onMessageSubmitted
).
toHaveBeenCalled
();
expect
(
view
.
clearMessages
).
toHaveBeenCalled
();
expect
(
window
.
confirm
).
toHaveBeenCalled
();
expect
(
view
.
model
.
messages
.
length
,
0
);
// The messages must be removed from the chatbox
expect
(
view
.
model
.
messages
.
browserStorage
.
records
.
length
,
0
);
// And also from browserStorage
expect
(
_converse
.
emit
.
calls
.
count
(),
1
);
expect
(
_converse
.
emit
.
calls
.
mostRecent
().
args
,
[
'
messageSend
'
,
message
]);
done
();
}));
}));
});
});
...
@@ -1267,133 +1279,133 @@
...
@@ -1267,133 +1279,133 @@
it
(
"
is incremented when the message is received and ChatBoxView is scrolled up
"
,
it
(
"
is incremented when the message is received and ChatBoxView is scrolled up
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
,
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
,
msg
=
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
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
);
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
.
then
((
view
)
=>
{
done
();
view
.
model
.
save
(
'
scrolled
'
,
true
);
_converse
.
chatboxes
.
onMessage
(
msg
);
expect
(
view
.
model
.
get
(
'
num_unread
'
)).
toBe
(
1
);
done
();
});
}));
}));
it
(
"
is not incremented when the message is received and ChatBoxView is scrolled down
"
,
it
(
"
is not incremented when the message is received and ChatBoxView is scrolled down
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
,
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
,
msg
=
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be read
'
);
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
);
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
0
);
.
then
(()
=>
{
done
();
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
_converse
.
chatboxes
.
onMessage
(
msg
);
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
0
);
done
();
});
}));
}));
it
(
"
is incremeted when message is received, chatbox is scrolled down and the window is not focused
"
,
it
(
"
is incremeted when message is received, chatbox is scrolled down and the window is not focused
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
msgFactory
=
function
()
{
var
msgFactory
=
function
()
{
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
};
};
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
_converse
.
windowState
=
'
hidden
'
;
_converse
.
windowState
=
'
hidden
'
;
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
done
();
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
});
done
();
}));
}));
it
(
"
is incremeted when message is received, chatbox is scrolled up and the window is not focused
"
,
it
(
"
is incremeted when message is received, chatbox is scrolled up and the window is not focused
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
msgFactory
=
function
()
{
var
msgFactory
=
function
()
{
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
};
};
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
chatbox
.
save
(
'
scrolled
'
,
true
);
chatbox
.
save
(
'
scrolled
'
,
true
);
_converse
.
windowState
=
'
hidden
'
;
_converse
.
windowState
=
'
hidden
'
;
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
done
();
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
});
done
();
}));
}));
it
(
"
is cleared when ChatBoxView was scrolled down and the window become focused
"
,
it
(
"
is cleared when ChatBoxView was scrolled down and the window become focused
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
msgFactory
=
function
()
{
var
msgFactory
=
function
()
{
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
};
};
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
const
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
_converse
.
windowState
=
'
hidden
'
;
_converse
.
windowState
=
'
hidden
'
;
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
_converse
.
saveWindowState
(
null
,
'
focus
'
);
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
0
);
_converse
.
saveWindowState
(
null
,
'
focus
'
);
done
();
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
0
);
});
done
();
}));
}));
it
(
"
is not cleared when ChatBoxView was scrolled up and the windows become focused
"
,
it
(
"
is not cleared when ChatBoxView was scrolled up and the windows become focused
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
msgFactory
=
function
()
{
var
msgFactory
=
function
()
{
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be unread
'
);
};
};
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
chatbox
.
save
(
'
scrolled
'
,
true
);
chatbox
.
save
(
'
scrolled
'
,
true
);
_converse
.
windowState
=
'
hidden
'
;
_converse
.
windowState
=
'
hidden
'
;
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
_converse
.
saveWindowState
(
null
,
'
focus
'
);
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
_converse
.
saveWindowState
(
null
,
'
focus
'
);
done
();
expect
(
chatbox
.
get
(
'
num_unread
'
)).
toBe
(
1
);
});
done
();
}));
}));
});
});
...
@@ -1401,16 +1413,16 @@
...
@@ -1401,16 +1413,16 @@
it
(
"
is updated when message is received and chatbox is scrolled up
"
,
it
(
"
is updated when message is received and chatbox is scrolled up
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
waitUntil
(
function
()
{
_converse
.
emit
(
'
rosterContactsFetched
'
);
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
},
500
)
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
,
500
)
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
))
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
chatbox
.
save
(
'
scrolled
'
,
true
);
chatbox
.
save
(
'
scrolled
'
,
true
);
...
@@ -1433,16 +1445,16 @@
...
@@ -1433,16 +1445,16 @@
it
(
"
is updated when message is received and chatbox is minimized
"
,
it
(
"
is updated when message is received and chatbox is minimized
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
waitUntil
(
function
()
{
_converse
.
emit
(
'
rosterContactsFetched
'
);
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
},
500
)
.
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
,
500
)
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
))
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
chatboxview
.
minimize
();
chatboxview
.
minimize
();
...
@@ -1466,16 +1478,16 @@
...
@@ -1466,16 +1478,16 @@
it
(
"
is cleared when chatbox is maximzied after receiving messages in minimized mode
"
,
it
(
"
is cleared when chatbox is maximzied after receiving messages in minimized mode
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
waitUntil
(
function
()
{
_converse
.
emit
(
'
rosterContactsFetched
'
);
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
},
500
)
.
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
,
500
)
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
))
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
msgsIndicatorSelector
=
'
a.open-chat:contains("
'
+
chatbox
.
get
(
'
fullname
'
)
+
'
") .msgs-indicator
'
;
var
msgsIndicatorSelector
=
'
a.open-chat:contains("
'
+
chatbox
.
get
(
'
fullname
'
)
+
'
") .msgs-indicator
'
;
...
@@ -1483,7 +1495,6 @@
...
@@ -1483,7 +1495,6 @@
var
msgFactory
=
function
()
{
var
msgFactory
=
function
()
{
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be received as unread, but eventually will be read
'
);
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be received as unread, but eventually will be read
'
);
};
};
chatboxview
.
minimize
();
chatboxview
.
minimize
();
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
...
@@ -1500,16 +1511,16 @@
...
@@ -1500,16 +1511,16 @@
it
(
"
is cleared when unread messages are viewed which were received in scrolled-up chatbox
"
,
it
(
"
is cleared when unread messages are viewed which were received in scrolled-up chatbox
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
waitUntil
(
function
()
{
_converse
.
emit
(
'
rosterContactsFetched
'
);
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
},
500
)
.
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
,
500
)
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
))
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
msgFactory
=
function
()
{
var
msgFactory
=
function
()
{
...
@@ -1532,16 +1543,16 @@
...
@@ -1532,16 +1543,16 @@
it
(
"
is not cleared after user clicks on roster view when chatbox is already opened and scrolled up
"
,
it
(
"
is not cleared after user clicks on roster view when chatbox is already opened and scrolled up
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
waitUntil
(
function
()
{
_converse
.
emit
(
'
rosterContactsFetched
'
);
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
},
500
)
.
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
,
500
)
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
))
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
msgFactory
=
function
()
{
var
msgFactory
=
function
()
{
...
@@ -1565,89 +1576,100 @@
...
@@ -1565,89 +1576,100 @@
describe
(
"
A Minimized ChatBoxView's Unread Message Count
"
,
function
()
{
describe
(
"
A Minimized ChatBoxView's Unread Message Count
"
,
function
()
{
it
(
"
is displayed when scrolled up chatbox is minimized after receiving unread messages
"
,
it
(
"
is displayed when scrolled up chatbox is minimized after receiving unread messages
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
msgFactory
=
function
()
{
const
msgFactory
=
function
()
{
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be received as unread, but eventually will be read
'
);
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be received as unread, but eventually will be read
'
);
};
};
var
selectUnreadMsgCount
=
function
()
{
const
selectUnreadMsgCount
=
function
()
{
var
minimizedChatBoxView
=
_converse
.
minimized_chats
.
get
(
sender_jid
);
const
minimizedChatBoxView
=
_converse
.
minimized_chats
.
get
(
sender_jid
);
return
$
(
minimizedChatBoxView
.
el
).
find
(
'
.message-count
'
);
return
$
(
minimizedChatBoxView
.
el
).
find
(
'
.message-count
'
);
};
};
var
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
const
chatbox
=
_converse
.
chatboxes
.
get
(
sender_jid
);
chatbox
.
save
(
'
scrolled
'
,
true
);
chatbox
.
save
(
'
scrolled
'
,
true
);
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
const
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
chatboxview
.
minimize
();
chatboxview
.
minimize
();
var
$unreadMsgCount
=
selectUnreadMsgCount
();
const
$unreadMsgCount
=
selectUnreadMsgCount
();
expect
(
u
.
isVisible
(
$unreadMsgCount
[
0
])).
toBeTruthy
();
expect
(
u
.
isVisible
(
$unreadMsgCount
[
0
])).
toBeTruthy
();
expect
(
$unreadMsgCount
.
html
()).
toBe
(
'
1
'
);
expect
(
$unreadMsgCount
.
html
()).
toBe
(
'
1
'
);
done
();
done
();
});
}));
}));
it
(
"
is incremented when message is received and windows is not focused
"
,
it
(
"
is incremented when message is received and windows is not focused
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
.
then
(()
=>
{
var
msgFactory
=
function
()
{
const
msgFactory
=
function
()
{
return
test_utils
.
createChatMessage
(
_converse
,
sender_jid
,
'
This message will be received as unread, but eventually will be read
'
);
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
);
const
selectUnreadMsgCount
=
function
()
{
return
$
(
minimizedChatBoxView
.
el
).
find
(
'
.message-count
'
);
const
minimizedChatBoxView
=
_converse
.
minimized_chats
.
get
(
sender_jid
);
};
return
$
(
minimizedChatBoxView
.
el
).
find
(
'
.message-count
'
);
};
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
const
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
chatboxview
.
minimize
();
chatboxview
.
minimize
();
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
_converse
.
chatboxes
.
onMessage
(
msgFactory
());
var
$unreadMsgCount
=
selectUnreadMsgCount
();
const
$unreadMsgCount
=
selectUnreadMsgCount
();
expect
(
u
.
isVisible
(
$unreadMsgCount
[
0
])).
toBeTruthy
();
expect
(
u
.
isVisible
(
$unreadMsgCount
[
0
])).
toBeTruthy
();
expect
(
$unreadMsgCount
.
html
()).
toBe
(
'
1
'
);
expect
(
$unreadMsgCount
.
html
()).
toBe
(
'
1
'
);
done
();
done
();
});
}));
}));
it
(
"
will render Openstreetmap-URL from geo-URI
"
,
it
(
"
will render Openstreetmap-URL from geo-URI
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
var
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
message
=
"
geo:37.786971,-122.399677
"
;
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
let
view
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
const
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
],
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
message
=
"
geo:37.786971,-122.399677
"
,
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
.
then
(()
=>
{
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
test_utils
.
sendMessage
(
view
,
message
);
test_utils
.
sendMessage
(
view
,
message
);
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg
'
).
length
,
1000
);
return
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
length
;
}).
then
(()
=>
{
},
1000
).
then
(
function
()
{
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
var
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
var
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
()).
toEqual
(
expect
(
msg
.
html
()).
toEqual
(
'
<a target="_blank" rel="noopener" href="https://www.openstreetmap.org/?mlat=37.786971&
'
+
'
<a target="_blank" rel="noopener" href="https://www.openstreetmap.org/?mlat=37.786971&
'
+
'
mlon=-122.399677#map=18/37.786971/-122.399677">https://www.openstreetmap.org/?mlat=37.7869
'
+
'
mlon=-122.399677#map=18/37.786971/-122.399677">https://www.openstreetmap.org/?mlat=37.7869
'
+
'
71&mlon=-122.399677#map=18/37.786971/-122.399677</a>
'
);
'
71&mlon=-122.399677#map=18/37.786971/-122.399677</a>
'
);
done
();
done
();
});
});
}));
}));
});
});
});
});
}));
}));
spec/chatroom.js
View file @
506aa331
This source diff could not be displayed because it is too large. You can
view the blob
instead.
spec/http-file-upload.js
View file @
506aa331
...
@@ -225,25 +225,28 @@
...
@@ -225,25 +225,28 @@
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
[
'
http://jabber.org/protocol/disco#items
'
],
[],
'
info
'
).
then
(
function
()
{
[
'
http://jabber.org/protocol/disco#items
'
],
[],
'
info
'
).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.localhost
'
],
'
items
'
).
then
(
function
()
{
let
contact_jid
,
view
;
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.localhost
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]).
then
(
function
()
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.localhost
'
],
'
items
'
)
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(()
=>
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.localhost
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]))
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
3
);
test_utils
.
waitUntil
(
function
()
{
_converse
.
emit
(
'
rosterContactsFetched
'
);
return
view
.
el
.
querySelector
(
'
.upload-file
'
);
},
150
).
then
(
function
()
{
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
expect
(
view
.
el
.
querySelector
(
'
.chat-toolbar .upload-file
'
)).
not
.
toBe
(
null
);
return
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
done
();
}).
then
(()
=>
{
});
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
});
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelector
(
'
.upload-file
'
));
}).
then
(()
=>
{
expect
(
view
.
el
.
querySelector
(
'
.chat-toolbar .upload-file
'
)).
not
.
toBe
(
null
);
done
();
});
});
});
});
}));
}));
it
(
"
appears in MUC chats
"
,
mock
.
initConverseWithPromises
(
it
(
"
appears in MUC chats
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
waitUntilDiscoConfirmed
(
test_utils
.
waitUntilDiscoConfirmed
(
...
@@ -251,19 +254,15 @@
...
@@ -251,19 +254,15 @@
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
[
'
http://jabber.org/protocol/disco#items
'
],
[],
'
info
'
).
then
(
function
()
{
[
'
http://jabber.org/protocol/disco#items
'
],
[],
'
info
'
).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.localhost
'
],
'
items
'
).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.localhost
'
],
'
items
'
)
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.localhost
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]).
then
(
function
()
{
.
then
(()
=>
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.localhost
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]))
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
dummy
'
).
then
(
function
()
{
.
then
(()
=>
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
dummy
'
))
var
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
.
then
(()
=>
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
).
el
.
querySelector
(
'
.upload-file
'
)))
test_utils
.
waitUntil
(
function
()
{
.
then
(()
=>
{
return
view
.
el
.
querySelector
(
'
.upload-file
'
);
const
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
}).
then
(
function
()
{
expect
(
view
.
el
.
querySelector
(
'
.chat-toolbar .upload-file
'
)).
not
.
toBe
(
null
);
expect
(
view
.
el
.
querySelector
(
'
.chat-toolbar .upload-file
'
)).
not
.
toBe
(
null
);
done
();
done
();
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
});
});
});
});
});
});
}));
}));
...
@@ -277,101 +276,104 @@
...
@@ -277,101 +276,104 @@
var
send_backup
=
XMLHttpRequest
.
prototype
.
send
;
var
send_backup
=
XMLHttpRequest
.
prototype
.
send
;
var
IQ_stanzas
=
_converse
.
connection
.
IQ_stanzas
;
var
IQ_stanzas
=
_converse
.
connection
.
IQ_stanzas
;
let
contact_jid
;
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.montague.tld
'
],
'
items
'
).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.montague.tld
'
],
'
items
'
)
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.montague.tld
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]).
then
(
function
()
{
.
then
(()
=>
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.montague.tld
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]))
test_utils
.
createContacts
(
_converse
,
'
current
'
);
.
then
(()
=>
{
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
file
=
{
return
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
'
type
'
:
'
image/jpeg
'
,
}).
then
(()
=>
{
'
size
'
:
'
23456
'
,
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
'
lastModifiedDate
'
:
""
,
var
file
=
{
'
name
'
:
"
my-juliet.jpg
"
'
type
'
:
'
image/jpeg
'
,
};
'
size
'
:
'
23456
'
,
view
.
model
.
sendFiles
([
file
]);
'
lastModifiedDate
'
:
""
,
return
test_utils
.
waitUntil
(
function
()
{
'
name
'
:
"
my-juliet.jpg
"
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
};
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.montague.tld"] request
'
);
view
.
model
.
sendFiles
([
file
]);
}).
length
>
0
;
return
test_utils
.
waitUntil
(
function
()
{
}).
then
(
function
()
{
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
var
iq
=
IQ_stanzas
.
pop
();
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.montague.tld"] request
'
);
expect
(
iq
.
toLocaleString
()).
toBe
(
}).
length
>
0
;
"
<iq from='dummy@localhost/resource'
"
+
}).
then
(
function
()
{
"
to='upload.montague.tld'
"
+
var
iq
=
IQ_stanzas
.
pop
();
"
type='get'
"
+
expect
(
iq
.
toLocaleString
()).
toBe
(
"
xmlns='jabber:client'
"
+
"
<iq from='dummy@localhost/resource'
"
+
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'>
"
+
"
to='upload.montague.tld'
"
+
"
<request xmlns='urn:xmpp:http:upload:0'
"
+
"
type='get'
"
+
"
filename='my-juliet.jpg'
"
+
"
xmlns='jabber:client'
"
+
"
size='23456'
"
+
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'>
"
+
"
content-type='image/jpeg'/>
"
+
"
<request xmlns='urn:xmpp:http:upload:0'
"
+
"
</iq>
"
);
"
filename='my-juliet.jpg'
"
+
"
size='23456'
"
+
var
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
"
content-type='image/jpeg'/>
"
+
var
message
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
"
</iq>
"
);
var
stanza
=
Strophe
.
xmlHtmlNode
(
var
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
"
<iq from='upload.montague.tld'
"
+
var
message
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'
"
+
"
to='dummy@localhost/resource'
"
+
var
stanza
=
Strophe
.
xmlHtmlNode
(
"
type='result'>
"
+
"
<iq from='upload.montague.tld'
"
+
"
<slot xmlns='urn:xmpp:http:upload:0'>
"
+
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'
"
+
"
<put url='https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my-juliet.jpg'>
"
+
"
to='dummy@localhost/resource'
"
+
"
<header name='Authorization'>Basic Base64String==</header>
"
+
"
type='result'>
"
+
"
<header name='Cookie'>foo=bar; user=romeo</header>
"
+
"
<slot xmlns='urn:xmpp:http:upload:0'>
"
+
"
</put>
"
+
"
<put url='https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my-juliet.jpg'>
"
+
"
<get url='
"
+
message
+
"
' />
"
+
"
<header name='Authorization'>Basic Base64String==</header>
"
+
"
</slot>
"
+
"
<header name='Cookie'>foo=bar; user=romeo</header>
"
+
"
</iq>
"
).
firstElementChild
;
"
</put>
"
+
"
<get url='
"
+
message
+
"
' />
"
+
spyOn
(
XMLHttpRequest
.
prototype
,
'
send
'
).
and
.
callFake
(
function
()
{
"
</slot>
"
+
const
message
=
view
.
model
.
messages
.
at
(
0
);
"
</iq>
"
).
firstElementChild
;
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0
'
);
message
.
set
(
'
progress
'
,
0.5
);
spyOn
(
XMLHttpRequest
.
prototype
,
'
send
'
).
and
.
callFake
(
function
()
{
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0.5
'
);
const
message
=
view
.
model
.
messages
.
at
(
0
);
message
.
set
(
'
progress
'
,
1
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0
'
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
1
'
);
message
.
set
(
'
progress
'
,
0.5
);
message
.
save
({
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0.5
'
);
'
upload
'
:
_converse
.
SUCCESS
,
message
.
set
(
'
progress
'
,
1
);
'
oob_url
'
:
message
.
get
(
'
get
'
),
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
1
'
);
'
message
'
:
message
.
get
(
'
get
'
)
message
.
save
({
});
'
upload
'
:
_converse
.
SUCCESS
,
});
'
oob_url
'
:
message
.
get
(
'
get
'
),
var
sent_stanza
;
'
message
'
:
message
.
get
(
'
get
'
)
spyOn
(
_converse
.
connection
,
'
send
'
).
and
.
callFake
(
function
(
stanza
)
{
sent_stanza
=
stanza
;
});
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
});
var
sent_stanza
;
spyOn
(
_converse
.
connection
,
'
send
'
).
and
.
callFake
(
function
(
stanza
)
{
sent_stanza
=
stanza
;
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
return
test_utils
.
waitUntil
(
function
()
{
return
sent_stanza
;
},
1000
).
then
(
function
()
{
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
"
<message from='dummy@localhost/resource'
"
+
"
to='irini.vlastuin@localhost'
"
+
"
type='chat'
"
+
"
id='
"
+
sent_stanza
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
' xmlns='jabber:client'>
"
+
"
<body>
"
+
message
+
"
</body>
"
+
"
<active xmlns='http://jabber.org/protocol/chatstates'/>
"
+
"
<x xmlns='jabber:x:oob'>
"
+
"
<url>
"
+
message
+
"
</url>
"
+
"
</x>
"
+
"
</message>
"
);
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(
function
()
{
return
sent_stanza
;
return
view
.
el
.
querySelector
(
'
.chat-image
'
);
},
1000
).
then
(
function
()
{
},
1000
);
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
}).
then
(
function
()
{
"
<message from='dummy@localhost/resource'
"
+
// Check that the image renders
"
to='irini.vlastuin@localhost'
"
+
expect
(
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
).
innerHTML
.
trim
()).
toEqual
(
"
type='chat'
"
+
`<!-- src/templates/image.html -->\n`
+
"
id='
"
+
sent_stanza
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
' xmlns='jabber:client'>
"
+
`<a href="
${
window
.
location
.
origin
}
/logo/conversejs-filled.svg" target="_blank" rel="noopener">`
+
"
<body>
"
+
message
+
"
</body>
"
+
`<img class="chat-image img-thumbnail" src="
${
window
.
location
.
origin
}
/logo/conversejs-filled.svg">`
+
"
<active xmlns='http://jabber.org/protocol/chatstates'/>
"
+
`</a>`
);
"
<x xmlns='jabber:x:oob'>
"
+
XMLHttpRequest
.
prototype
.
send
=
send_backup
;
"
<url>
"
+
message
+
"
</url>
"
+
done
();
"
</x>
"
+
"
</message>
"
);
return
test_utils
.
waitUntil
(
function
()
{
return
view
.
el
.
querySelector
(
'
.chat-image
'
);
},
1000
);
}).
then
(
function
()
{
// Check that the image renders
expect
(
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
).
innerHTML
.
trim
()).
toEqual
(
`<!-- src/templates/image.html -->\n`
+
`<a href="
${
window
.
location
.
origin
}
/logo/conversejs-filled.svg" target="_blank" rel="noopener">`
+
`<img class="chat-image img-thumbnail" src="
${
window
.
location
.
origin
}
/logo/conversejs-filled.svg">`
+
`</a>`
);
XMLHttpRequest
.
prototype
.
send
=
send_backup
;
done
();
});
});
});
});
});
});
});
...
@@ -487,56 +489,53 @@
...
@@ -487,56 +489,53 @@
});
});
}));
}));
it
(
"
shows and error message if the file is too large
"
,
mock
.
initConverseWithAsync
(
function
(
done
,
_converse
)
{
it
(
"
shows an error message if the file is too large
"
,
mock
.
initConverseWithAsync
(
function
(
done
,
_converse
)
{
var
IQ_stanzas
=
_converse
.
connection
.
IQ_stanzas
;
const
IQ_stanzas
=
_converse
.
connection
.
IQ_stanzas
;
var
IQ_ids
=
_converse
.
connection
.
IQ_ids
;
const
IQ_ids
=
_converse
.
connection
.
IQ_ids
;
var
send_backup
=
XMLHttpRequest
.
prototype
.
send
;
const
send_backup
=
XMLHttpRequest
.
prototype
.
send
;
let
view
,
contact_jid
;
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
bare_jid
,
[],
[])
.
then
(()
=>
test_utils
.
waitUntil
(()
=>
_
.
filter
(
IQ_stanzas
,
(
iq
)
=>
iq
.
nodeTree
.
querySelector
(
'
iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]
'
)).
length
)).
then
(()
=>
{
var
stanza
=
_
.
find
(
IQ_stanzas
,
function
(
iq
)
{
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]
'
);
});
var
info_IQ_id
=
IQ_ids
[
IQ_stanzas
.
indexOf
(
stanza
)];
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
bare_jid
,
[],
[]).
then
(
function
()
{
stanza
=
$iq
({
test_utils
.
waitUntil
(
function
()
{
'
type
'
:
'
result
'
,
'
from
'
:
'
localhost
'
,
'
to
'
:
'
dummy@localhost/resource
'
,
'
id
'
:
info_IQ_id
}).
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
server
'
,
'
type
'
:
'
im
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/disco#info
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/disco#items
'
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
return
_converse
.
api
.
disco
.
entities
.
get
();
}).
then
(
function
(
entities
)
{
expect
(
entities
.
length
).
toBe
(
2
);
expect
(
_
.
includes
(
entities
.
pluck
(
'
jid
'
),
'
localhost
'
)).
toBe
(
true
);
expect
(
_
.
includes
(
entities
.
pluck
(
'
jid
'
),
'
dummy@localhost
'
)).
toBe
(
true
);
expect
(
entities
.
get
(
_converse
.
domain
).
features
.
length
).
toBe
(
2
);
expect
(
entities
.
get
(
_converse
.
domain
).
identities
.
length
).
toBe
(
1
);
return
test_utils
.
waitUntil
(
function
()
{
// Converse.js sees that the entity has a disco#items feature,
// so it will make a query for it.
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
return
iq
.
nodeTree
.
querySelector
(
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]
'
);
'
iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]
'
);
}).
length
>
0
;
}).
length
>
0
;
},
300
).
then
(
function
()
{
},
300
);
var
stanza
=
_
.
find
(
IQ_stanzas
,
function
(
iq
)
{
}).
then
(
function
()
{
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]
'
);
});
var
info_IQ_id
=
IQ_ids
[
IQ_stanzas
.
indexOf
(
stanza
)];
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
from
'
:
'
localhost
'
,
'
to
'
:
'
dummy@localhost/resource
'
,
'
id
'
:
info_IQ_id
}).
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
server
'
,
'
type
'
:
'
im
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/disco#info
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/disco#items
'
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
_converse
.
api
.
disco
.
entities
.
get
().
then
(
function
(
entities
)
{
expect
(
entities
.
length
).
toBe
(
2
);
expect
(
_
.
includes
(
entities
.
pluck
(
'
jid
'
),
'
localhost
'
)).
toBe
(
true
);
expect
(
_
.
includes
(
entities
.
pluck
(
'
jid
'
),
'
dummy@localhost
'
)).
toBe
(
true
);
expect
(
entities
.
get
(
_converse
.
domain
).
features
.
length
).
toBe
(
2
);
expect
(
entities
.
get
(
_converse
.
domain
).
identities
.
length
).
toBe
(
1
);
return
test_utils
.
waitUntil
(
function
()
{
// Converse.js sees that the entity has a disco#items feature,
// so it will make a query for it.
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]
'
);
}).
length
>
0
;
},
300
);
});
}).
then
(
function
()
{
var
stanza
=
_
.
find
(
IQ_stanzas
,
function
(
iq
)
{
var
stanza
=
_
.
find
(
IQ_stanzas
,
function
(
iq
)
{
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]
'
);
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#items"]
'
);
});
});
...
@@ -550,77 +549,77 @@
...
@@ -550,77 +549,77 @@
.
c
(
'
item
'
,
{
.
c
(
'
item
'
,
{
'
jid
'
:
'
upload.localhost
'
,
'
jid
'
:
'
upload.localhost
'
,
'
name
'
:
'
HTTP File Upload
'
});
'
name
'
:
'
HTTP File Upload
'
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
_converse
.
api
.
disco
.
entities
.
get
().
then
(
function
(
entities
)
{
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
entities
.
length
).
toBe
(
2
);
expect
(
entities
.
get
(
'
localhost
'
).
items
.
length
).
toBe
(
1
);
_converse
.
api
.
disco
.
entities
.
get
().
then
(
function
(
entities
)
{
return
test_utils
.
waitUntil
(
function
()
{
expect
(
entities
.
length
).
toBe
(
2
);
// Converse.js sees that the entity has a disco#info feature,
expect
(
entities
.
get
(
'
localhost
'
).
items
.
length
).
toBe
(
1
);
// so it will make a query for it.
return
test_utils
.
waitUntil
(
function
()
{
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
// Converse.js sees that the entity has a disco#info feature,
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]
'
);
// so it will make a query for it.
}).
length
>
0
;
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
},
300
);
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]
'
);
});
}).
length
>
0
;
}).
then
(
function
()
{
},
300
);
var
stanza
=
_
.
find
(
IQ_stanzas
,
function
(
iq
)
{
});
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]
'
);
}).
then
(
function
()
{
});
var
stanza
=
_
.
find
(
IQ_stanzas
,
function
(
iq
)
{
var
IQ_id
=
IQ_ids
[
IQ_stanzas
.
indexOf
(
stanza
)];
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]
'
);
expect
(
stanza
.
toLocaleString
()).
toBe
(
});
"
<iq from='dummy@localhost/resource' to='upload.localhost' type='get' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
var
IQ_id
=
IQ_ids
[
IQ_stanzas
.
indexOf
(
stanza
)];
"
<query xmlns='http://jabber.org/protocol/disco#info'/>
"
+
expect
(
stanza
.
toLocaleString
()).
toBe
(
"
</iq>
"
);
"
<iq from='dummy@localhost/resource' to='upload.localhost' type='get' xmlns='jabber:client' id='
"
+
IQ_id
+
"
'>
"
+
"
<query xmlns='http://jabber.org/protocol/disco#info'/>
"
+
// Upload service responds and reports a maximum file size of 5MiB
"
</iq>
"
);
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
to
'
:
'
dummy@localhost/resource
'
,
'
id
'
:
IQ_id
,
'
from
'
:
'
upload.localhost
'
})
.
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
// Upload service responds and reports a maximum file size of 5MiB
.
c
(
'
identity
'
,
{
'
category
'
:
'
store
'
,
'
type
'
:
'
file
'
,
'
name
'
:
'
HTTP File Upload
'
}).
up
()
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
to
'
:
'
dummy@localhost/resource
'
,
'
id
'
:
IQ_id
,
'
from
'
:
'
upload.localhost
'
})
.
c
(
'
feature
'
,
{
'
var
'
:
'
urn:xmpp:http:upload:0
'
}).
up
()
.
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
.
c
(
'
x
'
,
{
'
type
'
:
'
result
'
,
'
xmlns
'
:
'
jabber:x:data
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
store
'
,
'
type
'
:
'
file
'
,
'
name
'
:
'
HTTP File Upload
'
}).
up
()
.
c
(
'
field
'
,
{
'
var
'
:
'
FORM_TYPE
'
,
'
type
'
:
'
hidden
'
})
.
c
(
'
feature
'
,
{
'
var
'
:
'
urn:xmpp:http:upload:0
'
}).
up
()
.
c
(
'
value
'
).
t
(
'
urn:xmpp:http:upload:0
'
).
up
().
up
()
.
c
(
'
x
'
,
{
'
type
'
:
'
result
'
,
'
xmlns
'
:
'
jabber:x:data
'
})
.
c
(
'
field
'
,
{
'
var
'
:
'
max-file-size
'
})
.
c
(
'
field
'
,
{
'
var
'
:
'
FORM_TYPE
'
,
'
type
'
:
'
hidden
'
})
.
c
(
'
value
'
).
t
(
'
5242880
'
);
.
c
(
'
value
'
).
t
(
'
urn:xmpp:http:upload:0
'
).
up
().
up
()
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
.
c
(
'
field
'
,
{
'
var
'
:
'
max-file-size
'
})
.
c
(
'
value
'
).
t
(
'
5242880
'
);
_converse
.
api
.
disco
.
entities
.
get
().
then
(
function
(
entities
)
{
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
entities
.
get
(
'
localhost
'
).
items
.
get
(
'
upload.localhost
'
).
identities
.
where
({
'
category
'
:
'
store
'
}).
length
).
toBe
(
1
);
return
_converse
.
api
.
disco
.
entities
.
get
();
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
HTTPUPLOAD
,
_converse
.
domain
).
then
(
}).
then
(
function
(
entities
)
{
function
(
result
)
{
expect
(
entities
.
get
(
'
localhost
'
).
items
.
get
(
'
upload.localhost
'
).
identities
.
where
({
'
category
'
:
'
store
'
}).
length
).
toBe
(
1
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
return
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
HTTPUPLOAD
,
_converse
.
domain
);
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
}).
then
(
function
(
result
)
{
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
file
=
{
'
type
'
:
'
image/jpeg
'
,
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
'
size
'
:
'
5242881
'
,
return
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
'
lastModifiedDate
'
:
""
,
}).
then
(()
=>
{
'
name
'
:
"
my-juliet.jpg
"
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
};
var
file
=
{
view
.
model
.
sendFiles
([
file
]);
'
type
'
:
'
image/jpeg
'
,
return
test_utils
.
waitUntil
(
function
()
{
'
size
'
:
'
5242881
'
,
return
view
.
el
.
querySelectorAll
(
'
.message
'
).
length
;
'
lastModifiedDate
'
:
""
,
}).
then
(
function
()
{
'
name
'
:
"
my-juliet.jpg
"
const
messages
=
view
.
el
.
querySelectorAll
(
'
.message.chat-error
'
);
};
expect
(
messages
.
length
).
toBe
(
1
);
view
.
model
.
sendFiles
([
file
]);
expect
(
messages
[
0
].
textContent
).
toBe
(
return
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.message
'
).
length
)
'
The size of your file, my-juliet.jpg, exceeds the maximum allowed by your server, which is 5 MB.
'
);
}).
then
(
function
()
{
done
();
const
messages
=
view
.
el
.
querySelectorAll
(
'
.message.chat-error
'
);
});
expect
(
messages
.
length
).
toBe
(
1
);
}
expect
(
messages
[
0
].
textContent
).
toBe
(
);
'
The size of your file, my-juliet.jpg, exceeds the maximum allowed by your server, which is 5 MB.
'
);
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
done
();
})
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
))
});
}));
}));
});
});
});
});
describe
(
"
While a file is being uploaded
"
,
function
()
{
describe
(
"
While a file is being uploaded
"
,
function
()
{
it
(
"
shows a progress bar
"
,
mock
.
initConverseWithAsync
(
function
(
done
,
_converse
)
{
it
(
"
shows a progress bar
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
waitUntilDiscoConfirmed
(
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
_converse
,
_converse
.
domain
,
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
...
@@ -628,77 +627,74 @@
...
@@ -628,77 +627,74 @@
var
send_backup
=
XMLHttpRequest
.
prototype
.
send
;
var
send_backup
=
XMLHttpRequest
.
prototype
.
send
;
var
IQ_stanzas
=
_converse
.
connection
.
IQ_stanzas
;
var
IQ_stanzas
=
_converse
.
connection
.
IQ_stanzas
;
let
view
,
contact_jid
;
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.montague.tld
'
],
'
items
'
).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.montague.tld
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]).
then
(
function
()
{
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[],
[],
[
'
upload.montague.tld
'
],
'
items
'
)
test_utils
.
createContacts
(
_converse
,
'
current
'
);
.
then
(()
=>
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
'
upload.montague.tld
'
,
[],
[
Strophe
.
NS
.
HTTPUPLOAD
],
[]))
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(()
=>
{
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
var
file
=
{
'
type
'
:
'
image/jpeg
'
,
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
'
size
'
:
'
23456
'
,
return
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
'
lastModifiedDate
'
:
""
,
}).
then
(()
=>
{
'
name
'
:
"
my-juliet.jpg
"
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
};
const
file
=
{
view
.
model
.
sendFiles
([
file
]);
'
type
'
:
'
image/jpeg
'
,
return
test_utils
.
waitUntil
(
function
()
{
'
size
'
:
'
23456
'
,
return
_
.
filter
(
IQ_stanzas
,
function
(
iq
)
{
'
lastModifiedDate
'
:
""
,
return
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.montague.tld"] request
'
);
'
name
'
:
"
my-juliet.jpg
"
}).
length
>
0
;
};
}).
then
(
function
()
{
view
.
model
.
sendFiles
([
file
]);
var
iq
=
IQ_stanzas
.
pop
();
return
test_utils
.
waitUntil
(()
=>
_
.
filter
(
IQ_stanzas
,
(
iq
)
=>
iq
.
nodeTree
.
querySelector
(
'
iq[to="upload.montague.tld"] request
'
)).
length
)
expect
(
iq
.
toLocaleString
()).
toBe
(
}).
then
(
function
()
{
"
<iq from='dummy@localhost/resource'
"
+
const
iq
=
IQ_stanzas
.
pop
();
"
to='upload.montague.tld'
"
+
expect
(
iq
.
toLocaleString
()).
toBe
(
"
type='get'
"
+
"
<iq from='dummy@localhost/resource'
"
+
"
xmlns='jabber:client'
"
+
"
to='upload.montague.tld'
"
+
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'>
"
+
"
type='get'
"
+
"
<request xmlns='urn:xmpp:http:upload:0'
"
+
"
xmlns='jabber:client'
"
+
"
filename='my-juliet.jpg'
"
+
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'>
"
+
"
size='23456'
"
+
"
<request xmlns='urn:xmpp:http:upload:0'
"
+
"
content-type='image/jpeg'/>
"
+
"
filename='my-juliet.jpg'
"
+
"
</iq>
"
);
"
size='23456'
"
+
"
content-type='image/jpeg'/>
"
+
var
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
"
</iq>
"
);
var
message
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
const
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
var
stanza
=
Strophe
.
xmlHtmlNode
(
const
message
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
"
<iq from='upload.montague.tld'
"
+
const
stanza
=
Strophe
.
xmlHtmlNode
(
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'
"
+
"
<iq from='upload.montague.tld'
"
+
"
to='dummy@localhost/resource'
"
+
"
id='
"
+
iq
.
nodeTree
.
getAttribute
(
'
id
'
)
+
"
'
"
+
"
type='result'>
"
+
"
to='dummy@localhost/resource'
"
+
"
<slot xmlns='urn:xmpp:http:upload:0'>
"
+
"
type='result'>
"
+
"
<put url='https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my-juliet.jpg'>
"
+
"
<slot xmlns='urn:xmpp:http:upload:0'>
"
+
"
<header name='Authorization'>Basic Base64String==</header>
"
+
"
<put url='https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my-juliet.jpg'>
"
+
"
<header name='Cookie'>foo=bar; user=romeo</header>
"
+
"
<header name='Authorization'>Basic Base64String==</header>
"
+
"
</put>
"
+
"
<header name='Cookie'>foo=bar; user=romeo</header>
"
+
"
<get url='
"
+
message
+
"
' />
"
+
"
</put>
"
+
"
</slot>
"
+
"
<get url='
"
+
message
+
"
' />
"
+
"
</iq>
"
).
firstElementChild
;
"
</slot>
"
+
"
</iq>
"
).
firstElementChild
;
spyOn
(
XMLHttpRequest
.
prototype
,
'
send
'
).
and
.
callFake
(
function
()
{
spyOn
(
XMLHttpRequest
.
prototype
,
'
send
'
).
and
.
callFake
(
function
()
{
const
message
=
view
.
model
.
messages
.
at
(
0
);
const
message
=
view
.
model
.
messages
.
at
(
0
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0
'
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0
'
);
message
.
set
(
'
progress
'
,
0.5
);
message
.
set
(
'
progress
'
,
0.5
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0.5
'
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
0.5
'
);
message
.
set
(
'
progress
'
,
1
);
message
.
set
(
'
progress
'
,
1
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
1
'
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content progress
'
).
getAttribute
(
'
value
'
)).
toBe
(
'
1
'
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content .chat-msg__text
'
).
textContent
).
toBe
(
'
Uploading file: my-juliet.jpg, 22.91 KB
'
);
expect
(
view
.
el
.
querySelector
(
'
.chat-content .chat-msg__text
'
).
textContent
).
toBe
(
'
Uploading file: my-juliet.jpg, 22.91 KB
'
);
done
();
done
();
});
var
sent_stanza
;
spyOn
(
_converse
.
connection
,
'
send
'
).
and
.
callFake
(
function
(
stanza
)
{
sent_stanza
=
stanza
;
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
});
});
});
var
sent_stanza
;
spyOn
(
_converse
.
connection
,
'
send
'
).
and
.
callFake
(
function
(
stanza
)
{
sent_stanza
=
stanza
;
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
});
});
});
});
}));
}));
});
});
});
});
});
});
}));
}));
spec/messages.js
View file @
506aa331
...
@@ -21,247 +21,251 @@
...
@@ -21,247 +21,251 @@
it
(
"
can be sent as a correction by clicking the pencil icon
"
,
it
(
"
can be sent as a correction by clicking the pencil icon
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
.
then
(()
=>
{
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
const
textarea
=
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
);
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
textarea
.
value
=
'
But soft, what light through yonder airlock breaks?
'
;
const
textarea
=
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
);
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
view
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
textarea
.
value
).
toBe
(
''
);
textarea
.
value
=
'
But soft, what light through yonder airlock breaks?
'
;
const
first_msg
=
view
.
model
.
messages
.
findWhere
({
'
message
'
:
'
But soft, what light through yonder airlock breaks?
'
});
view
.
keyPressed
({
target
:
textarea
,
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg .chat-msg__action
'
).
length
).
toBe
(
1
);
preventDefault
:
_
.
noop
,
let
action
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__action
'
);
keyCode
:
13
// Enter
expect
(
action
.
getAttribute
(
'
title
'
)).
toBe
(
'
Edit this message
'
);
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
action
.
style
.
opacity
=
1
;
expect
(
view
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
)
action
.
click
();
.
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
textarea
.
value
).
toBe
(
''
);
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
const
first_msg
=
view
.
model
.
messages
.
findWhere
({
'
message
'
:
'
But soft, what light through yonder airlock breaks?
'
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg .chat-msg__action
'
).
length
).
toBe
(
1
);
let
action
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__action
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
expect
(
action
.
getAttribute
(
'
title
'
)).
toBe
(
'
Edit this message
'
);
textarea
.
value
=
'
But soft, what light through yonder window breaks?
'
;
view
.
keyPressed
({
action
.
style
.
opacity
=
1
;
target
:
textarea
,
action
.
click
();
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
});
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
const
msg
=
_converse
.
connection
.
send
.
calls
.
all
()[
0
].
args
[
0
];
expect
(
msg
.
toLocaleString
())
spyOn
(
_converse
.
connection
,
'
send
'
);
.
toBe
(
`<message from='dummy@localhost/resource' `
+
textarea
.
value
=
'
But soft, what light through yonder window breaks?
'
;
`to='max.frankfurter@localhost' type='chat' id='
${
msg
.
nodeTree
.
getAttribute
(
'
id
'
)}
' `
+
view
.
keyPressed
({
`xmlns='jabber:client'>`
+
target
:
textarea
,
`<body>But soft, what light through yonder window breaks?</body>`
+
preventDefault
:
_
.
noop
,
`<active xmlns='http://jabber.org/protocol/chatstates'/>`
+
keyCode
:
13
// Enter
`<replace xmlns='urn:xmpp:message-correct:0' id='
${
first_msg
.
get
(
'
msgid
'
)}
'/>`
+
`</message>`
);
expect
(
view
.
model
.
messages
.
models
.
length
).
toBe
(
1
);
const
corrected_message
=
view
.
model
.
messages
.
at
(
0
);
expect
(
corrected_message
.
get
(
'
msgid
'
)).
toBe
(
first_msg
.
get
(
'
msgid
'
));
expect
(
corrected_message
.
get
(
'
correcting
'
)).
toBe
(
false
);
expect
(
corrected_message
.
get
(
'
older_versions
'
).
length
).
toBe
(
1
);
expect
(
corrected_message
.
get
(
'
older_versions
'
)[
0
]).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
// Test that clicking the pencil icon a second time cancels editing.
action
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__action
'
);
action
.
style
.
opacity
=
1
;
action
.
click
();
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder window breaks?
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
action
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__action
'
);
action
.
style
.
opacity
=
1
;
action
.
click
();
expect
(
textarea
.
value
).
toBe
(
''
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
false
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
// Test that messages from other users don't have the pencil icon
_converse
.
chatboxes
.
onMessage
(
$msg
({
'
from
'
:
contact_jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
chat
'
,
'
id
'
:
(
new
Date
()).
getTime
()
}).
c
(
'
body
'
).
t
(
'
Hello
'
).
up
()
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
}).
tree
()
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg .chat-msg__action
'
).
length
).
toBe
(
1
);
done
();
});
});
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
const
msg
=
_converse
.
connection
.
send
.
calls
.
all
()[
0
].
args
[
0
];
expect
(
msg
.
toLocaleString
())
.
toBe
(
`<message from='dummy@localhost/resource' `
+
`to='max.frankfurter@localhost' type='chat' id='
${
msg
.
nodeTree
.
getAttribute
(
'
id
'
)}
' `
+
`xmlns='jabber:client'>`
+
`<body>But soft, what light through yonder window breaks?</body>`
+
`<active xmlns='http://jabber.org/protocol/chatstates'/>`
+
`<replace xmlns='urn:xmpp:message-correct:0' id='
${
first_msg
.
get
(
'
msgid
'
)}
'/>`
+
`</message>`
);
expect
(
view
.
model
.
messages
.
models
.
length
).
toBe
(
1
);
const
corrected_message
=
view
.
model
.
messages
.
at
(
0
);
expect
(
corrected_message
.
get
(
'
msgid
'
)).
toBe
(
first_msg
.
get
(
'
msgid
'
));
expect
(
corrected_message
.
get
(
'
correcting
'
)).
toBe
(
false
);
expect
(
corrected_message
.
get
(
'
older_versions
'
).
length
).
toBe
(
1
);
expect
(
corrected_message
.
get
(
'
older_versions
'
)[
0
]).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
// Test that clicking the pencil icon a second time cancels editing.
action
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__action
'
);
action
.
style
.
opacity
=
1
;
action
.
click
();
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder window breaks?
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
action
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__action
'
);
action
.
style
.
opacity
=
1
;
action
.
click
();
expect
(
textarea
.
value
).
toBe
(
''
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
false
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
// Test that messages from other users don't have the pencil icon
_converse
.
chatboxes
.
onMessage
(
$msg
({
'
from
'
:
contact_jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
chat
'
,
'
id
'
:
(
new
Date
()).
getTime
()
}).
c
(
'
body
'
).
t
(
'
Hello
'
).
up
()
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
}).
tree
()
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg .chat-msg__action
'
).
length
).
toBe
(
1
);
done
();
}));
}));
it
(
"
can be sent as a correction by using the up arrow
"
,
it
(
"
can be sent as a correction by using the up arrow
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
.
then
(()
=>
{
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
const
textarea
=
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
);
expect
(
textarea
.
value
).
toBe
(
''
);
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
38
// Up arrow
});
expect
(
textarea
.
value
).
toBe
(
''
);
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
textarea
.
value
=
'
But soft, what light through yonder airlock breaks?
'
;
const
textarea
=
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
);
view
.
keyPressed
({
expect
(
textarea
.
value
).
toBe
(
''
);
target
:
textarea
,
view
.
keyPressed
({
preventDefault
:
_
.
noop
,
target
:
textarea
,
keyCode
:
13
// Enter
keyCode
:
38
// Up arrow
});
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
textarea
.
value
).
toBe
(
''
);
expect
(
view
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
textarea
.
value
=
'
But soft, what light through yonder airlock breaks?
'
;
const
first_msg
=
view
.
model
.
messages
.
findWhere
({
'
message
'
:
'
But soft, what light through yonder airlock breaks?
'
});
view
.
keyPressed
({
expect
(
textarea
.
value
).
toBe
(
''
);
target
:
textarea
,
view
.
keyPressed
({
preventDefault
:
_
.
noop
,
target
:
textarea
,
keyCode
:
13
// Enter
keyCode
:
38
// Up arrow
});
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
view
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
)
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
.
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
const
first_msg
=
view
.
model
.
messages
.
findWhere
({
'
message
'
:
'
But soft, what light through yonder airlock breaks?
'
});
expect
(
textarea
.
value
).
toBe
(
''
);
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
38
// Up arrow
});
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
spyOn
(
_converse
.
connection
,
'
send
'
);
textarea
.
value
=
'
But soft, what light through yonder window breaks?
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
const
msg
=
_converse
.
connection
.
send
.
calls
.
all
()[
0
].
args
[
0
];
expect
(
msg
.
toLocaleString
())
.
toBe
(
`<message from='dummy@localhost/resource' `
+
`to='max.frankfurter@localhost' type='chat' id='
${
msg
.
nodeTree
.
getAttribute
(
'
id
'
)}
' `
+
`xmlns='jabber:client'>`
+
`<body>But soft, what light through yonder window breaks?</body>`
+
`<active xmlns='http://jabber.org/protocol/chatstates'/>`
+
`<replace xmlns='urn:xmpp:message-correct:0' id='
${
first_msg
.
get
(
'
msgid
'
)}
'/>`
+
`</message>`
);
expect
(
view
.
model
.
messages
.
models
.
length
).
toBe
(
1
);
const
corrected_message
=
view
.
model
.
messages
.
at
(
0
);
expect
(
corrected_message
.
get
(
'
msgid
'
)).
toBe
(
first_msg
.
get
(
'
msgid
'
));
expect
(
corrected_message
.
get
(
'
correcting
'
)).
toBe
(
false
);
expect
(
corrected_message
.
get
(
'
older_versions
'
).
length
).
toBe
(
1
);
expect
(
corrected_message
.
get
(
'
older_versions
'
)[
0
]).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
// Test that pressing the down arrow cancels message correction
expect
(
textarea
.
value
).
toBe
(
''
);
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
38
// Up arrow
});
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder window breaks?
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder window breaks?
'
);
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
40
// Down arrow
});
expect
(
textarea
.
value
).
toBe
(
''
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
false
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
textarea
.
value
=
'
It is the east, and Juliet is the one.
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
2
);
textarea
.
value
=
'
Arise, fair sun, and kill the envious moon
'
;
spyOn
(
_converse
.
connection
,
'
send
'
);
view
.
keyPressed
({
textarea
.
value
=
'
But soft, what light through yonder window breaks?
'
;
target
:
textarea
,
view
.
keyPressed
({
preventDefault
:
_
.
noop
,
target
:
textarea
,
keyCode
:
13
// Enter
preventDefault
:
_
.
noop
,
});
keyCode
:
13
// Enter
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
3
);
});
expect
(
_converse
.
connection
.
send
).
toHaveBeenCalled
();
view
.
keyPressed
({
const
msg
=
_converse
.
connection
.
send
.
calls
.
all
()[
0
].
args
[
0
];
target
:
textarea
,
expect
(
msg
.
toLocaleString
())
keyCode
:
38
// Up arrow
.
toBe
(
`<message from='dummy@localhost/resource' `
+
});
`to='max.frankfurter@localhost' type='chat' id='
${
msg
.
nodeTree
.
getAttribute
(
'
id
'
)}
' `
+
expect
(
textarea
.
value
).
toBe
(
'
Arise, fair sun, and kill the envious moon
'
);
`xmlns='jabber:client'>`
+
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
`<body>But soft, what light through yonder window breaks?</body>`
+
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBeFalsy
();
`<active xmlns='http://jabber.org/protocol/chatstates'/>`
+
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBe
(
true
);
`<replace xmlns='urn:xmpp:message-correct:0' id='
${
first_msg
.
get
(
'
msgid
'
)}
'/>`
+
`</message>`
);
textarea
.
selectionEnd
=
0
;
// Happens by pressing up,
expect
(
view
.
model
.
messages
.
models
.
length
).
toBe
(
1
);
// but for some reason not in tests, so we set it manually.
const
corrected_message
=
view
.
model
.
messages
.
at
(
0
);
view
.
keyPressed
({
expect
(
corrected_message
.
get
(
'
msgid
'
)).
toBe
(
first_msg
.
get
(
'
msgid
'
));
target
:
textarea
,
expect
(
corrected_message
.
get
(
'
correcting
'
)).
toBe
(
false
);
keyCode
:
38
// Up arrow
expect
(
corrected_message
.
get
(
'
older_versions
'
).
length
).
toBe
(
1
);
});
expect
(
corrected_message
.
get
(
'
older_versions
'
)[
0
]).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
textarea
.
value
).
toBe
(
'
It is the east, and Juliet is the one.
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBeFalsy
();
// Test that pressing the down arrow cancels message correction
textarea
.
value
=
'
It is the east, and Juliet is the sun.
'
;
expect
(
textarea
.
value
).
toBe
(
''
);
view
.
keyPressed
({
view
.
keyPressed
({
target
:
textarea
,
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
38
// Up arrow
keyCode
:
13
// Enter
});
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder window breaks?
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
expect
(
textarea
.
value
).
toBe
(
'
But soft, what light through yonder window breaks?
'
);
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
40
// Down arrow
});
expect
(
textarea
.
value
).
toBe
(
''
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
false
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
false
);
textarea
.
value
=
'
It is the east, and Juliet is the one.
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
2
);
textarea
.
value
=
'
Arise, fair sun, and kill the envious moon
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
3
);
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
38
// Up arrow
});
expect
(
textarea
.
value
).
toBe
(
'
Arise, fair sun, and kill the envious moon
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBe
(
true
);
textarea
.
selectionEnd
=
0
;
// Happens by pressing up,
// but for some reason not in tests, so we set it manually.
view
.
keyPressed
({
target
:
textarea
,
keyCode
:
38
// Up arrow
});
expect
(
textarea
.
value
).
toBe
(
'
It is the east, and Juliet is the one.
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBeFalsy
();
textarea
.
value
=
'
It is the east, and Juliet is the sun.
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
expect
(
textarea
.
value
).
toBe
(
''
);
const
messages
=
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
);
expect
(
messages
.
length
).
toBe
(
3
);
expect
(
messages
[
0
].
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
But soft, what light through yonder window breaks?
'
);
expect
(
messages
[
1
].
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
It is the east, and Juliet is the sun.
'
);
expect
(
messages
[
2
].
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
Arise, fair sun, and kill the envious moon
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBeFalsy
();
done
();
});
});
expect
(
textarea
.
value
).
toBe
(
''
);
const
messages
=
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
);
expect
(
messages
.
length
).
toBe
(
3
);
expect
(
messages
[
0
].
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
But soft, what light through yonder window breaks?
'
);
expect
(
messages
[
1
].
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
It is the east, and Juliet is the sun.
'
);
expect
(
messages
[
2
].
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
Arise, fair sun, and kill the envious moon
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
1
).
get
(
'
correcting
'
)).
toBeFalsy
();
expect
(
view
.
model
.
messages
.
at
(
2
).
get
(
'
correcting
'
)).
toBeFalsy
();
done
();
}));
}));
...
@@ -321,65 +325,67 @@
...
@@ -321,65 +325,67 @@
it
(
"
can be replaced with a correction
"
,
it
(
"
can be replaced with a correction
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
const
message
=
'
This is a received message
'
;
const
message
=
'
This is a received message
'
;
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
.
then
(()
=>
{
const
msg_id
=
u
.
getUniqueId
();
const
msg_id
=
u
.
getUniqueId
();
_converse
.
chatboxes
.
onMessage
(
$msg
({
_converse
.
chatboxes
.
onMessage
(
$msg
({
'
from
'
:
sender_jid
,
'
from
'
:
sender_jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
chat
'
,
'
type
'
:
'
chat
'
,
'
id
'
:
msg_id
,
'
id
'
:
msg_id
,
}).
c
(
'
body
'
).
t
(
'
But soft, what light through yonder airlock breaks?
'
).
tree
());
}).
c
(
'
body
'
).
t
(
'
But soft, what light through yonder airlock breaks?
'
).
tree
());
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
chatboxview
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
_converse
.
chatboxes
.
onMessage
(
$msg
({
'
from
'
:
sender_jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
chat
'
,
'
id
'
:
u
.
getUniqueId
(),
}).
c
(
'
body
'
).
t
(
'
But soft, what light through yonder chimney breaks?
'
).
up
()
.
c
(
'
replace
'
,
{
'
id
'
:
msg_id
,
'
xmlns
'
:
'
urn:xmpp:message-correct:0
'
}).
tree
());
test_utils
.
waitUntil
(()
=>
chatboxview
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
===
'
But soft, what light through yonder chimney breaks?
'
).
then
(()
=>
{
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg__content .fa-edit
'
).
length
).
toBe
(
1
);
expect
(
chatboxview
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
)
.
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
_converse
.
chatboxes
.
onMessage
(
$msg
({
_converse
.
chatboxes
.
onMessage
(
$msg
({
'
from
'
:
sender_jid
,
'
from
'
:
sender_jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
chat
'
,
'
type
'
:
'
chat
'
,
'
id
'
:
u
.
getUniqueId
(),
'
id
'
:
u
.
getUniqueId
(),
}).
c
(
'
body
'
).
t
(
'
But soft, what light through yonder
window
breaks?
'
).
up
()
}).
c
(
'
body
'
).
t
(
'
But soft, what light through yonder
chimney
breaks?
'
).
up
()
.
c
(
'
replace
'
,
{
'
id
'
:
msg_id
,
'
xmlns
'
:
'
urn:xmpp:message-correct:0
'
}).
tree
());
.
c
(
'
replace
'
,
{
'
id
'
:
msg_id
,
'
xmlns
'
:
'
urn:xmpp:message-correct:0
'
}).
tree
());
return
test_utils
.
waitUntil
(()
=>
chatboxview
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
===
test_utils
.
waitUntil
(()
=>
chatboxview
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
===
'
But soft, what light through yonder window breaks?
'
);
'
But soft, what light through yonder chimney breaks?
'
).
then
(()
=>
{
}).
then
(()
=>
{
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg__content .fa-edit
'
).
length
).
toBe
(
1
);
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg__content .fa-edit
'
).
length
).
toBe
(
1
);
chatboxview
.
el
.
querySelector
(
'
.chat-msg__content .fa-edit
'
).
click
();
const
modal
=
chatboxview
.
model
.
messages
.
at
(
0
).
message_versions_modal
;
_converse
.
chatboxes
.
onMessage
(
$msg
({
return
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
1000
);
'
from
'
:
sender_jid
,
}).
then
(()
=>
{
'
to
'
:
_converse
.
connection
.
jid
,
const
modal
=
chatboxview
.
model
.
messages
.
at
(
0
).
message_versions_modal
;
'
type
'
:
'
chat
'
,
const
older_msgs
=
modal
.
el
.
querySelectorAll
(
'
.older-msg
'
);
'
id
'
:
u
.
getUniqueId
(),
expect
(
older_msgs
.
length
).
toBe
(
2
);
}).
c
(
'
body
'
).
t
(
'
But soft, what light through yonder window breaks?
'
).
up
()
expect
(
older_msgs
[
0
].
textContent
).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
.
c
(
'
replace
'
,
{
'
id
'
:
msg_id
,
'
xmlns
'
:
'
urn:xmpp:message-correct:0
'
}).
tree
());
expect
(
older_msgs
[
1
].
textContent
).
toBe
(
'
But soft, what light through yonder chimney breaks?
'
);
done
();
return
test_utils
.
waitUntil
(()
=>
chatboxview
.
el
.
querySelector
(
'
.chat-msg__text
'
).
textContent
===
'
But soft, what light through yonder window breaks?
'
);
}).
then
(()
=>
{
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
chatboxview
.
el
.
querySelectorAll
(
'
.chat-msg__content .fa-edit
'
).
length
).
toBe
(
1
);
chatboxview
.
el
.
querySelector
(
'
.chat-msg__content .fa-edit
'
).
click
();
const
modal
=
chatboxview
.
model
.
messages
.
at
(
0
).
message_versions_modal
;
return
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
1000
);
}).
then
(()
=>
{
const
modal
=
chatboxview
.
model
.
messages
.
at
(
0
).
message_versions_modal
;
const
older_msgs
=
modal
.
el
.
querySelectorAll
(
'
.older-msg
'
);
expect
(
older_msgs
.
length
).
toBe
(
2
);
expect
(
older_msgs
[
0
].
textContent
).
toBe
(
'
But soft, what light through yonder airlock breaks?
'
);
expect
(
older_msgs
[
1
].
textContent
).
toBe
(
'
But soft, what light through yonder chimney breaks?
'
);
done
();
});
});
});
}));
}));
...
@@ -500,10 +506,11 @@
...
@@ -500,10 +506,11 @@
it
(
"
will have the error message displayed after itself
"
,
it
(
"
will have the error message displayed after itself
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
// TODO: what could still be done for error
// TODO: what could still be done for error
...
@@ -513,154 +520,152 @@
...
@@ -513,154 +520,152 @@
// that.
// that.
/* <message from="scotty@enterprise.com/_converse.js-84843526"
/* <message from="scotty@enterprise.com/_converse.js-84843526"
* to="kirk@enterprise.com.com"
* to="kirk@enterprise.com.com"
* type="chat"
* type="chat"
* id="82bc02ce-9651-4336-baf0-fa04762ed8d2"
* id="82bc02ce-9651-4336-baf0-fa04762ed8d2"
* xmlns="jabber:client">
* xmlns="jabber:client">
* <body>yo</body>
* <body>yo</body>
* <active xmlns="http://jabber.org/protocol/chatstates"/>
* <active xmlns="http://jabber.org/protocol/chatstates"/>
* </message>
* </message>
*/
*/
var
sender_jid
=
mock
.
cur_names
[
5
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
sender_jid
=
mock
.
cur_names
[
5
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
fullname
=
_converse
.
xmppstatus
.
get
(
'
fullname
'
);
var
fullname
=
_converse
.
xmppstatus
.
get
(
'
fullname
'
);
fullname
=
_
.
isEmpty
(
fullname
)?
_converse
.
bare_jid
:
fullname
;
fullname
=
_
.
isEmpty
(
fullname
)?
_converse
.
bare_jid
:
fullname
;
_converse
.
api
.
chats
.
open
(
sender_jid
);
_converse
.
api
.
chats
.
open
(
sender_jid
)
var
msg_text
=
'
This message will not be sent, due to an error
'
;
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
msg_text
=
'
This message will not be sent, due to an error
'
;
var
message
=
view
.
model
.
messages
.
create
({
var
view
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
'
msgid
'
:
'
82bc02ce-9651-4336-baf0-fa04762ed8d2
'
,
var
message
=
view
.
model
.
messages
.
create
({
'
fullname
'
:
fullname
,
'
msgid
'
:
'
82bc02ce-9651-4336-baf0-fa04762ed8d2
'
,
'
sender
'
:
'
me
'
,
'
fullname
'
:
fullname
,
'
time
'
:
moment
().
format
(),
'
sender
'
:
'
me
'
,
'
message
'
:
msg_text
'
time
'
:
moment
().
format
(),
});
'
message
'
:
msg_text
view
.
model
.
sendMessage
(
message
);
});
var
$chat_content
=
$
(
view
.
el
).
find
(
'
.chat-content
'
);
view
.
model
.
sendMessage
(
message
);
var
msg_txt
=
$chat_content
.
find
(
'
.chat-msg:last
'
).
find
(
'
.chat-msg__text
'
).
text
();
var
$chat_content
=
$
(
view
.
el
).
find
(
'
.chat-content
'
);
expect
(
msg_txt
).
toEqual
(
msg_text
);
var
msg_txt
=
$chat_content
.
find
(
'
.chat-msg:last
'
).
find
(
'
.chat-msg__text
'
).
text
();
expect
(
msg_txt
).
toEqual
(
msg_text
);
// We send another message, for which an error will
// not be received, to test that errors appear
// We send another message, for which an error will
// after the relevant message.
// not be received, to test that errors appear
msg_text
=
'
This message will be sent, and also receive an error
'
;
// after the relevant message.
message
=
view
.
model
.
messages
.
create
({
msg_text
=
'
This message will be sent, and also receive an error
'
;
'
msgid
'
:
'
6fcdeee3-000f-4ce8-a17e-9ce28f0ae104
'
,
message
=
view
.
model
.
messages
.
create
({
'
fullname
'
:
fullname
,
'
msgid
'
:
'
6fcdeee3-000f-4ce8-a17e-9ce28f0ae104
'
,
'
sender
'
:
'
me
'
,
'
fullname
'
:
fullname
,
'
time
'
:
moment
().
format
(),
'
sender
'
:
'
me
'
,
'
message
'
:
msg_text
'
time
'
:
moment
().
format
(),
'
message
'
:
msg_text
});
view
.
model
.
sendMessage
(
message
);
msg_txt
=
$chat_content
.
find
(
'
.chat-msg:last
'
).
find
(
'
.chat-msg__text
'
).
text
();
expect
(
msg_txt
).
toEqual
(
msg_text
);
/* <message xmlns="jabber:client"
* to="scotty@enterprise.com/_converse.js-84843526"
* 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</text>
* </error>
* </message>
*/
var
error_txt
=
'
Server-to-server connection failed: Connecting failed: connection timeout
'
;
var
stanza
=
$msg
({
'
to
'
:
_converse
.
connection
.
jid
,
'
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
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
$chat_content
.
find
(
'
.chat-error
'
).
text
()).
toEqual
(
error_txt
);
stanza
=
$msg
({
'
to
'
:
_converse
.
connection
.
jid
,
'
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
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
$chat_content
.
find
(
'
.chat-error
'
).
length
).
toEqual
(
2
);
// If the last message is already an error message,
// then we don't render it another time.
stanza
=
$msg
({
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
error
'
,
'
id
'
:
'
another-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
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
$chat_content
.
find
(
'
.chat-error
'
).
length
).
toEqual
(
2
);
// A different error message will however render
stanza
=
$msg
({
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
error
'
,
'
id
'
:
'
another-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
(
'
Something else went wrong as well
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
$chat_content
.
find
(
'
.chat-error
'
).
length
).
toEqual
(
3
);
done
();
});
});
view
.
model
.
sendMessage
(
message
);
msg_txt
=
$chat_content
.
find
(
'
.chat-msg:last
'
).
find
(
'
.chat-msg__text
'
).
text
();
expect
(
msg_txt
).
toEqual
(
msg_text
);
/* <message xmlns="jabber:client"
* to="scotty@enterprise.com/_converse.js-84843526"
* 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</text>
* </error>
* </message>
*/
var
error_txt
=
'
Server-to-server connection failed: Connecting failed: connection timeout
'
;
var
stanza
=
$msg
({
'
to
'
:
_converse
.
connection
.
jid
,
'
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
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
$chat_content
.
find
(
'
.chat-error
'
).
text
()).
toEqual
(
error_txt
);
stanza
=
$msg
({
'
to
'
:
_converse
.
connection
.
jid
,
'
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
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
$chat_content
.
find
(
'
.chat-error
'
).
length
).
toEqual
(
2
);
// If the last message is already an error message,
// then we don't render it another time.
stanza
=
$msg
({
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
error
'
,
'
id
'
:
'
another-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
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
$chat_content
.
find
(
'
.chat-error
'
).
length
).
toEqual
(
2
);
// A different error message will however render
stanza
=
$msg
({
'
to
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
error
'
,
'
id
'
:
'
another-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
(
'
Something else went wrong as well
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
$chat_content
.
find
(
'
.chat-error
'
).
length
).
toEqual
(
3
);
done
();
}));
}));
});
});
it
(
"
will cause the chat area to be scrolled down only if it was at the bottom originally
"
,
it
(
"
will cause the chat area to be scrolled down only if it was at the bottom originally
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
let
chatboxview
;
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
message
=
'
This message is received while the chat area is scrolled up
'
;
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
)
spyOn
(
chatboxview
,
'
onScrolledDown
'
).
and
.
callThrough
();
.
then
(()
=>
{
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
// Create enough messages so that there's a scrollbar.
spyOn
(
chatboxview
,
'
onScrolledDown
'
).
and
.
callThrough
();
var
message
=
'
This message is received while the chat area is scrolled up
'
;
for
(
var
i
=
0
;
i
<
20
;
i
++
)
{
// Create enough messages so that there's a scrollbar.
_converse
.
chatboxes
.
onMessage
(
$msg
({
for
(
var
i
=
0
;
i
<
20
;
i
++
)
{
from
:
sender_jid
,
_converse
.
chatboxes
.
onMessage
(
$msg
({
to
:
_converse
.
connection
.
jid
,
from
:
sender_jid
,
type
:
'
chat
'
,
to
:
_converse
.
connection
.
jid
,
id
:
(
new
Date
()).
getTime
()
type
:
'
chat
'
,
}).
c
(
'
body
'
).
t
(
'
Message:
'
+
i
).
up
()
id
:
(
new
Date
()).
getTime
()
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
}).
tree
());
}).
c
(
'
body
'
).
t
(
'
Message:
'
+
i
).
up
()
}
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
}).
tree
());
return
test_utils
.
waitUntil
(
function
()
{
}
return
chatboxview
.
content
.
scrollTop
;
return
test_utils
.
waitUntil
(()
=>
chatboxview
.
content
.
scrollTop
,
1000
)
},
1000
).
then
(
function
()
{
.
then
(()
=>
test_utils
.
waitUntil
(()
=>
!
chatboxview
.
model
.
get
(
'
auto_scrolled
'
),
500
))
return
test_utils
.
waitUntil
(
function
()
{
}).
then
(()
=>
{
return
!
chatboxview
.
model
.
get
(
'
auto_scrolled
'
);
},
500
);
}).
then
(
function
()
{
chatboxview
.
content
.
scrollTop
=
0
;
chatboxview
.
content
.
scrollTop
=
0
;
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
chatboxview
.
model
.
get
(
'
scrolled
'
),
900
);
return
chatboxview
.
model
.
get
(
'
scrolled
'
);
}).
then
(()
=>
{
},
900
);
}).
then
(
function
()
{
_converse
.
chatboxes
.
onMessage
(
$msg
({
_converse
.
chatboxes
.
onMessage
(
$msg
({
from
:
sender_jid
,
from
:
sender_jid
,
to
:
_converse
.
connection
.
jid
,
to
:
_converse
.
connection
.
jid
,
...
@@ -1109,23 +1114,22 @@
...
@@ -1109,23 +1114,22 @@
it
(
"
received for a minimized chat box will increment a counter on its header
"
,
it
(
"
received for a minimized chat box will increment a counter on its header
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
if
(
_converse
.
view_mode
===
'
fullscreen
'
)
{
if
(
_converse
.
view_mode
===
'
fullscreen
'
)
{
return
done
();
return
done
();
}
}
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_name
=
mock
.
cur_names
[
0
];
const
contact_jid
=
contact_name
.
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
spyOn
(
_converse
,
'
emit
'
).
and
.
callThrough
();
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
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
();
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
)
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
))
.
then
(()
=>
{
var
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
expect
(
u
.
isVisible
(
chatview
.
el
)).
toBeTruthy
();
expect
(
u
.
isVisible
(
chatview
.
el
)).
toBeTruthy
();
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeFalsy
();
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeFalsy
();
...
@@ -1171,19 +1175,18 @@
...
@@ -1171,19 +1175,18 @@
it
(
"
will indicate when it has a time difference of more than a day between it and its predecessor
"
,
it
(
"
will indicate when it has a time difference of more than a day between it and its predecessor
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
test_utils
.
waitUntil
(
function
()
{
spyOn
(
_converse
,
'
emit
'
);
return
$
(
_converse
.
rosterview
.
el
).
find
(
'
.roster-group
'
).
length
;
const
contact_name
=
mock
.
cur_names
[
1
];
},
300
)
const
contact_jid
=
contact_name
.
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
.
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
'
.roster-group
'
).
length
)
spyOn
(
_converse
,
'
emit
'
);
.
then
(()
=>
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
))
var
contact_name
=
mock
.
cur_names
[
1
];
.
then
(()
=>
{
var
contact_jid
=
contact_name
.
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
clearChatBoxMessages
(
_converse
,
contact_jid
);
test_utils
.
clearChatBoxMessages
(
_converse
,
contact_jid
);
var
one_day_ago
=
moment
();
var
one_day_ago
=
moment
();
one_day_ago
.
subtract
(
'
days
'
,
1
);
one_day_ago
.
subtract
(
'
days
'
,
1
);
...
@@ -1269,117 +1272,132 @@
...
@@ -1269,117 +1272,132 @@
}));
}));
it
(
"
can be sent from a chatbox, and will appear inside it
"
,
it
(
"
can be sent from a chatbox, and will appear inside it
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
,
'
emit
'
);
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxFocused
'
,
jasmine
.
any
(
Object
));
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
expect
(
_converse
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxFocused
'
,
jasmine
.
any
(
Object
));
var
message
=
'
This message is sent from this chatbox
'
;
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
const
message
=
'
This message is sent from this chatbox
'
;
test_utils
.
sendMessage
(
view
,
message
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
model
.
messages
.
length
,
2
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
_converse
.
emit
.
calls
.
mostRecent
().
args
,
[
'
messageSend
'
,
message
]);
expect
(
view
.
model
.
messages
.
length
,
2
);
expect
(
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
).
text
()).
toEqual
(
message
);
expect
(
_converse
.
emit
.
calls
.
mostRecent
().
args
,
[
'
messageSend
'
,
message
]);
done
();
expect
(
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
).
text
()).
toEqual
(
message
);
done
();
});
}));
}));
it
(
"
is sanitized to prevent Javascript injection attacks
"
,
it
(
"
is sanitized to prevent Javascript injection attacks
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
var
message
=
'
<p>This message contains <em>some</em> <b>markup</b></p>
'
;
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
const
message
=
'
<p>This message contains <em>some</em> <b>markup</b></p>
'
;
test_utils
.
sendMessage
(
view
,
message
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
test_utils
.
sendMessage
(
view
,
message
);
var
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
msg
.
text
()).
toEqual
(
message
);
const
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
()).
toEqual
(
'
<p>This message contains <em>some</em> <b>markup</b></p>
'
);
expect
(
msg
.
text
()).
toEqual
(
message
);
done
();
expect
(
msg
.
html
()).
toEqual
(
'
<p>This message contains <em>some</em> <b>markup</b></p>
'
);
done
();
});
}));
}));
it
(
"
can contain hyperlinks, which will be clickable
"
,
it
(
"
can contain hyperlinks, which will be clickable
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
var
message
=
'
This message contains a hyperlink: www.opkode.com
'
;
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
const
message
=
'
This message contains a hyperlink: www.opkode.com
'
;
test_utils
.
sendMessage
(
view
,
message
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
test_utils
.
sendMessage
(
view
,
message
);
var
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
msg
.
text
()).
toEqual
(
message
);
const
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
()).
toEqual
(
'
This message contains a hyperlink: <a target="_blank" rel="noopener" href="http://www.opkode.com">www.opkode.com</a>
'
);
expect
(
msg
.
text
()).
toEqual
(
message
);
done
();
expect
(
msg
.
html
()).
toEqual
(
'
This message contains a hyperlink: <a target="_blank" rel="noopener" href="http://www.opkode.com">www.opkode.com</a>
'
);
done
();
});
}));
}));
it
(
"
will have properly escaped URLs
"
,
it
(
"
will have properly escaped URLs
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
message
,
msg
;
let
message
,
msg
;
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
message
=
"
http://www.opkode.com/'onmouseover='alert(1)'whatever
"
;
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
test_utils
.
sendMessage
(
view
,
message
);
message
=
"
http://www.opkode.com/'onmouseover='alert(1)'whatever
"
;
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
test_utils
.
sendMessage
(
view
,
message
);
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
msg
.
text
()).
toEqual
(
message
);
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
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>
'
);
expect
(
msg
.
text
()).
toEqual
(
message
);
message
=
'
http://www.opkode.com/"onmouseover="alert(1)"whatever
'
;
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>
'
);
test_utils
.
sendMessage
(
view
,
message
);
message
=
'
http://www.opkode.com/"onmouseover="alert(1)"whatever
'
;
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
msg
.
text
()).
toEqual
(
message
);
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
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>
'
);
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>
'
);
message
=
"
https://en.wikipedia.org/wiki/Ender's_Game
"
;
test_utils
.
sendMessage
(
view
,
message
);
message
=
"
https://en.wikipedia.org/wiki/Ender's_Game
"
;
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
msg
.
text
()).
toEqual
(
message
);
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
()).
toEqual
(
'
<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">
'
+
message
+
'
</a>
'
);
expect
(
msg
.
text
()).
toEqual
(
message
);
expect
(
msg
.
html
()).
toEqual
(
'
<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">
'
+
message
+
'
</a>
'
);
message
=
"
https://en.wikipedia.org/wiki/Ender's_Game
"
;
test_utils
.
sendMessage
(
view
,
message
);
message
=
"
https://en.wikipedia.org/wiki/Ender's_Game
"
;
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
msg
.
text
()).
toEqual
(
message
);
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
()).
toEqual
(
'
<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">
'
+
message
+
'
</a>
'
);
expect
(
msg
.
text
()).
toEqual
(
message
);
done
();
expect
(
msg
.
html
()).
toEqual
(
'
<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">
'
+
message
+
'
</a>
'
);
done
();
});
}));
}));
it
(
"
will render newlines
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
it
(
"
will render newlines
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
...
@@ -1416,20 +1434,23 @@
...
@@ -1416,20 +1434,23 @@
}));
}));
it
(
"
will render images from their URLs
"
,
it
(
"
will render images from their URLs
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
const
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
let
message
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
let
message
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
let
view
;
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
.
then
(()
=>
{
test_utils
.
sendMessage
(
view
,
message
);
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
,
1000
).
then
(()
=>
{
test_utils
.
sendMessage
(
view
,
message
);
return
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
,
1000
)
}).
then
(()
=>
{
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
const
msg
=
$
(
view
.
el
).
find
(
'
.chat-content .chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
const
msg
=
$
(
view
.
el
).
find
(
'
.chat-content .chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
().
trim
()).
toEqual
(
expect
(
msg
.
html
().
trim
()).
toEqual
(
...
@@ -1461,30 +1482,33 @@
...
@@ -1461,30 +1482,33 @@
}));
}));
it
(
"
will render the message time as configured
"
,
it
(
"
will render the message time as configured
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{}
,
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
]
,
function
(
done
,
_converse
)
{
{},
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
_converse
.
time_format
=
'
hh:mm
'
;
_converse
.
time_format
=
'
hh:mm
'
;
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
var
message
=
'
This message is sent from this chatbox
'
;
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
test_utils
.
sendMessage
(
view
,
message
);
const
message
=
'
This message is sent from this chatbox
'
;
test_utils
.
sendMessage
(
view
,
message
);
var
chatbox
=
_converse
.
chatboxes
.
get
(
contact_jid
);
const
chatbox
=
_converse
.
chatboxes
.
get
(
contact_jid
);
expect
(
chatbox
.
messages
.
models
.
length
,
1
);
expect
(
chatbox
.
messages
.
models
.
length
,
1
);
var
msg_object
=
chatbox
.
messages
.
models
[
0
];
const
msg_object
=
chatbox
.
messages
.
models
[
0
];
var
msg_author
=
view
.
el
.
querySelector
(
'
.chat-content .chat-msg:last-child .chat-msg__author
'
);
const
msg_author
=
view
.
el
.
querySelector
(
'
.chat-content .chat-msg:last-child .chat-msg__author
'
);
expect
(
msg_author
.
textContent
.
trim
()).
toBe
(
'
Max Mustermann
'
);
expect
(
msg_author
.
textContent
.
trim
()).
toBe
(
'
Max Mustermann
'
);
var
msg_time
=
view
.
el
.
querySelector
(
'
.chat-content .chat-msg:last-child .chat-msg__time
'
);
const
msg_time
=
view
.
el
.
querySelector
(
'
.chat-content .chat-msg:last-child .chat-msg__time
'
);
var
time
=
moment
(
msg_object
.
get
(
'
time
'
)).
format
(
_converse
.
time_format
);
const
time
=
moment
(
msg_object
.
get
(
'
time
'
)).
format
(
_converse
.
time_format
);
expect
(
msg_time
.
textContent
).
toBe
(
time
);
expect
(
msg_time
.
textContent
).
toBe
(
time
);
done
();
done
();
});
}));
}));
it
(
"
will be correctly identified and rendered as a followup message
"
,
it
(
"
will be correctly identified and rendered as a followup message
"
,
...
@@ -1655,29 +1679,33 @@
...
@@ -1655,29 +1679,33 @@
}));
}));
describe
(
"
which contains a OOB URL
"
,
function
()
{
describe
(
"
which contains a
n
OOB URL
"
,
function
()
{
it
(
"
will render audio from oob mp3 URLs
"
,
it
(
"
will render audio from oob mp3 URLs
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
let
view
;
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
.
then
(()
=>
{
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
const
stanza
=
Strophe
.
xmlHtmlNode
(
const
stanza
=
Strophe
.
xmlHtmlNode
(
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
type='chat'
"
+
"
type='chat'
"
+
"
to='dummy@localhost/resource'>
"
+
"
to='dummy@localhost/resource'>
"
+
"
<body>Have you heard this funny audio?</body>
"
+
"
<body>Have you heard this funny audio?</body>
"
+
"
<x xmlns='jabber:x:oob'><url>http://localhost/audio.mp3</url></x>
"
+
"
<x xmlns='jabber:x:oob'><url>http://localhost/audio.mp3</url></x>
"
+
"
</message>
"
).
firstChild
;
"
</message>
"
).
firstChild
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg audio
'
).
length
,
1000
).
then
(
function
()
{
return
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg audio
'
).
length
,
1000
);
}).
then
(()
=>
{
let
msg
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__text
'
);
let
msg
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__text
'
);
expect
(
msg
.
outerHTML
).
toEqual
(
'
<div class="chat-msg__text">Have you heard this funny audio?</div>
'
);
expect
(
msg
.
outerHTML
).
toEqual
(
'
<div class="chat-msg__text">Have you heard this funny audio?</div>
'
);
let
media
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
);
let
media
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
);
...
@@ -1708,76 +1736,83 @@
...
@@ -1708,76 +1736,83 @@
}));
}));
it
(
"
will render video from oob mp4 URLs
"
,
it
(
"
will render video from oob mp4 URLs
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
const
stanza
=
Strophe
.
xmlHtmlNode
(
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
type='chat'
"
+
"
to='dummy@localhost/resource'>
"
+
"
<body>Have you seen this funny video?</body>
"
+
"
<x xmlns='jabber:x:oob'><url>http://localhost/video.mp4</url></x>
"
+
"
</message>
"
).
firstChild
;
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg video
'
).
length
,
2000
).
then
(
function
()
{
let
msg
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__text
'
);
expect
(
msg
.
outerHTML
).
toEqual
(
'
<div class="chat-msg__text">Have you seen this funny video?</div>
'
);
let
media
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
);
expect
(
media
.
innerHTML
.
replace
(
/
(\r\n
|
\n
|
\r)
/gm
,
""
)).
toEqual
(
'
<!-- src/templates/video.html -->
'
+
'
<video controls=""><source src="http://localhost/video.mp4" type="video/mp4"></video>
'
+
'
<a target="_blank" rel="noopener" href="http://localhost/video.mp4">Download video file</a>
'
);
// If the <url> and <body> contents is the same, don't duplicate.
const
stanza
=
Strophe
.
xmlHtmlNode
(
const
stanza
=
Strophe
.
xmlHtmlNode
(
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
type='chat'
"
+
"
type='chat'
"
+
"
to='dummy@localhost/resource'>
"
+
"
to='dummy@localhost/resource'>
"
+
"
<body>
http://localhost/video.mp4
</body>
"
+
"
<body>
Have you seen this funny video?
</body>
"
+
"
<x xmlns='jabber:x:oob'><url>http://localhost/video.mp4</url></x>
"
+
"
<x xmlns='jabber:x:oob'><url>http://localhost/video.mp4</url></x>
"
+
"
</message>
"
).
firstChild
;
"
</message>
"
).
firstChild
;
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
msg
=
view
.
el
.
querySelector
(
'
.chat-msg:last-child .chat-msg__text
'
);
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg video
'
).
length
,
2000
).
then
(
function
()
{
expect
(
msg
.
innerHTML
).
toEqual
(
'
<!-- message gets added here via renderMessage -->
'
);
// Emtpy
let
msg
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__text
'
);
media
=
view
.
el
.
querySelector
(
'
.chat-msg:last-child .chat-msg__media
'
);
expect
(
msg
.
outerHTML
).
toEqual
(
'
<div class="chat-msg__text">Have you seen this funny video?</div>
'
);
expect
(
media
.
innerHTML
.
replace
(
/
(\r\n
|
\n
|
\r)
/gm
,
""
)).
toEqual
(
let
media
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
);
'
<!-- src/templates/video.html -->
'
+
expect
(
media
.
innerHTML
.
replace
(
/
(\r\n
|
\n
|
\r)
/gm
,
""
)).
toEqual
(
'
<video controls=""><source src="http://localhost/video.mp4" type="video/mp4"></video>
'
+
'
<!-- src/templates/video.html -->
'
+
'
<a target="_blank" rel="noopener" href="http://localhost/video.mp4">Download video file</a>
'
);
'
<video controls=""><source src="http://localhost/video.mp4" type="video/mp4"></video>
'
+
done
();
'
<a target="_blank" rel="noopener" href="http://localhost/video.mp4">Download video file</a>
'
);
// If the <url> and <body> contents is the same, don't duplicate.
const
stanza
=
Strophe
.
xmlHtmlNode
(
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
type='chat'
"
+
"
to='dummy@localhost/resource'>
"
+
"
<body>http://localhost/video.mp4</body>
"
+
"
<x xmlns='jabber:x:oob'><url>http://localhost/video.mp4</url></x>
"
+
"
</message>
"
).
firstChild
;
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
msg
=
view
.
el
.
querySelector
(
'
.chat-msg:last-child .chat-msg__text
'
);
expect
(
msg
.
innerHTML
).
toEqual
(
'
<!-- message gets added here via renderMessage -->
'
);
// Emtpy
media
=
view
.
el
.
querySelector
(
'
.chat-msg:last-child .chat-msg__media
'
);
expect
(
media
.
innerHTML
.
replace
(
/
(\r\n
|
\n
|
\r)
/gm
,
""
)).
toEqual
(
'
<!-- src/templates/video.html -->
'
+
'
<video controls=""><source src="http://localhost/video.mp4" type="video/mp4"></video>
'
+
'
<a target="_blank" rel="noopener" href="http://localhost/video.mp4">Download video file</a>
'
);
done
();
});
});
});
}));
}));
it
(
"
will render download links for files from oob URLs
"
,
it
(
"
will render download links for files from oob URLs
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
let
view
;
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
.
then
(()
=>
{
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
const
stanza
=
Strophe
.
xmlHtmlNode
(
const
stanza
=
Strophe
.
xmlHtmlNode
(
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
type='chat'
"
+
"
type='chat'
"
+
"
to='dummy@localhost/resource'>
"
+
"
to='dummy@localhost/resource'>
"
+
"
<body>Have you downloaded this funny file?</body>
"
+
"
<body>Have you downloaded this funny file?</body>
"
+
"
<x xmlns='jabber:x:oob'><url>http://localhost/funny.pdf</url></x>
"
+
"
<x xmlns='jabber:x:oob'><url>http://localhost/funny.pdf</url></x>
"
+
"
</message>
"
).
firstChild
;
"
</message>
"
).
firstChild
;
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg a
'
).
length
,
1000
).
then
(
function
()
{
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg a
'
).
length
,
1000
);
}).
then
(
function
()
{
const
msg
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__text
'
);
const
msg
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__text
'
);
expect
(
msg
.
outerHTML
).
toEqual
(
'
<div class="chat-msg__text">Have you downloaded this funny file?</div>
'
);
expect
(
msg
.
outerHTML
).
toEqual
(
'
<div class="chat-msg__text">Have you downloaded this funny file?</div>
'
);
const
media
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
);
const
media
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
);
...
@@ -1789,28 +1824,31 @@
...
@@ -1789,28 +1824,31 @@
}));
}));
it
(
"
will render images from oob URLs
"
,
it
(
"
will render images from oob URLs
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroup
sFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxe
sFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
let
view
;
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
.
then
(()
=>
{
const
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
const
url
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
const
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
const
stanza
=
Strophe
.
xmlHtmlNode
(
const
url
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
type='chat'
"
+
"
to='dummy@localhost/resource'>
"
+
"
<body>Have you seen this funny image?</body>
"
+
"
<x xmlns='jabber:x:oob'><url>
"
+
url
+
"
</url></x>
"
+
"
</message>
"
).
firstChild
;
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg img
'
).
length
,
2000
).
then
(
function
()
{
const
stanza
=
Strophe
.
xmlHtmlNode
(
"
<message from='
"
+
contact_jid
+
"
'
"
+
"
type='chat'
"
+
"
to='dummy@localhost/resource'>
"
+
"
<body>Have you seen this funny image?</body>
"
+
"
<x xmlns='jabber:x:oob'><url>
"
+
url
+
"
</url></x>
"
+
"
</message>
"
).
firstChild
;
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
return
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-msg img
'
).
length
,
2000
);
}).
then
(
function
()
{
const
msg
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__text
'
);
const
msg
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__text
'
);
expect
(
msg
.
outerHTML
).
toEqual
(
'
<div class="chat-msg__text">Have you seen this funny image?</div>
'
);
expect
(
msg
.
outerHTML
).
toEqual
(
'
<div class="chat-msg__text">Have you seen this funny image?</div>
'
);
const
media
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
);
const
media
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__media
'
);
...
...
spec/minchats.js
View file @
506aa331
...
@@ -13,32 +13,37 @@
...
@@ -13,32 +13,37 @@
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
_converse
.
minimized_chats
.
toggleview
.
model
.
browserStorage
.
_clear
();
_converse
.
minimized_chats
.
toggleview
.
model
.
browserStorage
.
_clear
();
_converse
.
minimized_chats
.
initToggle
();
_converse
.
minimized_chats
.
initToggle
();
var
contact_jid
,
chatview
;
let
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
let
chatview
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeFalsy
();
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
expect
(
$
(
_converse
.
minimized_chats
.
el
).
is
(
'
:visible
'
)).
toBeFalsy
();
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeFalsy
();
chatview
.
el
.
querySelector
(
'
.toggle-chatbox-button
'
).
click
();
expect
(
$
(
_converse
.
minimized_chats
.
el
).
is
(
'
:visible
'
)).
toBeFalsy
();
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeTruthy
();
chatview
.
el
.
querySelector
(
'
.toggle-chatbox-button
'
).
click
();
expect
(
$
(
_converse
.
minimized_chats
.
el
).
is
(
'
:visible
'
)).
toBeTruthy
();
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeTruthy
();
expect
(
_converse
.
minimized_chats
.
keys
().
length
).
toBe
(
1
);
expect
(
$
(
_converse
.
minimized_chats
.
el
).
is
(
'
:visible
'
)).
toBeTruthy
();
expect
(
_converse
.
minimized_chats
.
keys
()[
0
]).
toBe
(
contact_jid
);
expect
(
_converse
.
minimized_chats
.
keys
().
length
).
toBe
(
1
);
expect
(
_converse
.
minimized_chats
.
keys
()[
0
]).
toBe
(
contact_jid
);
contact_jid
=
mock
.
cur_names
[
1
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
contact_jid
=
mock
.
cur_names
[
1
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
return
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeFalsy
();
}).
then
(()
=>
{
chatview
.
el
.
querySelector
(
'
.toggle-chatbox-button
'
).
click
();
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeTruthy
();
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeFalsy
();
expect
(
$
(
_converse
.
minimized_chats
.
el
).
is
(
'
:visible
'
)).
toBeTruthy
();
chatview
.
el
.
querySelector
(
'
.toggle-chatbox-button
'
).
click
();
expect
(
_converse
.
minimized_chats
.
keys
().
length
).
toBe
(
2
);
expect
(
chatview
.
model
.
get
(
'
minimized
'
)).
toBeTruthy
();
expect
(
_
.
includes
(
_converse
.
minimized_chats
.
keys
(),
contact_jid
)).
toBeTruthy
();
expect
(
$
(
_converse
.
minimized_chats
.
el
).
is
(
'
:visible
'
)).
toBeTruthy
();
done
();
expect
(
_converse
.
minimized_chats
.
keys
().
length
).
toBe
(
2
);
expect
(
_
.
includes
(
_converse
.
minimized_chats
.
keys
(),
contact_jid
)).
toBeTruthy
();
done
();
});
}));
}));
it
(
"
can be toggled to hide or show minimized chats
"
,
it
(
"
can be toggled to hide or show minimized chats
"
,
...
@@ -47,24 +52,26 @@
...
@@ -47,24 +52,26 @@
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
_converse
.
minimized_chats
.
toggleview
.
model
.
browserStorage
.
_clear
();
_converse
.
minimized_chats
.
toggleview
.
model
.
browserStorage
.
_clear
();
_converse
.
minimized_chats
.
initToggle
();
_converse
.
minimized_chats
.
initToggle
();
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
var
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
.
then
(()
=>
{
expect
(
$
(
_converse
.
minimized_chats
.
el
).
is
(
'
:visible
'
)).
toBeFalsy
(
);
const
chatview
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
chatview
.
model
.
set
({
'
minimized
'
:
true
}
);
expect
(
u
.
isVisible
(
_converse
.
minimized_chats
.
el
)).
toBeFalsy
(
);
expect
(
$
(
_converse
.
minimized_chats
.
el
).
is
(
'
:visible
'
)).
toBeTruthy
(
);
chatview
.
model
.
set
({
'
minimized
'
:
true
}
);
expect
(
_converse
.
minimized_chats
.
keys
().
length
).
toBe
(
1
);
expect
(
u
.
isVisible
(
_converse
.
minimized_chats
.
el
)).
toBeTruthy
(
);
expect
(
_converse
.
minimized_chats
.
keys
()[
0
]).
toBe
(
contact_jid
);
expect
(
_converse
.
minimized_chats
.
keys
().
length
).
toBe
(
1
);
expect
(
$
(
_converse
.
minimized_chats
.
el
.
querySelector
(
'
.minimized-chats-flyout
'
)).
is
(
'
:visible
'
)).
toBeTruthy
(
);
expect
(
_converse
.
minimized_chats
.
keys
()[
0
]).
toBe
(
contact_jid
);
expect
(
_converse
.
minimized_chats
.
toggleview
.
model
.
get
(
'
collapsed
'
)).
toBeFals
y
();
expect
(
u
.
isVisible
(
_converse
.
minimized_chats
.
el
.
querySelector
(
'
.minimized-chats-flyout
'
))).
toBeTruth
y
();
_converse
.
minimized_chats
.
el
.
querySelector
(
'
#toggle-minimized-chats
'
).
click
();
expect
(
_converse
.
minimized_chats
.
toggleview
.
model
.
get
(
'
collapsed
'
)).
toBeFalsy
();
_converse
.
minimized_chats
.
el
.
querySelector
(
'
#toggle-minimized-chats
'
).
click
();
return
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
u
.
isVisible
(
_converse
.
minimized_chats
.
el
.
querySelector
(
'
.minimized-chats-flyout
'
))))
return
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
_converse
.
minimized_chats
.
el
.
querySelector
(
'
.minimized-chats-flyout
'
)));
.
then
(
function
()
{
}).
then
(()
=>
{
expect
(
_converse
.
minimized_chats
.
toggleview
.
model
.
get
(
'
collapsed
'
)).
toBeTruthy
();
expect
(
_converse
.
minimized_chats
.
toggleview
.
model
.
get
(
'
collapsed
'
)).
toBeTruthy
();
done
();
done
();
});
});
...
...
spec/roomslist.js
View file @
506aa331
...
@@ -12,44 +12,46 @@
...
@@ -12,44 +12,46 @@
describe
(
"
A list of open rooms
"
,
function
()
{
describe
(
"
A list of open rooms
"
,
function
()
{
it
(
"
is shown in the
\"
Rooms
\"
panel
"
,
mock
.
initConverseWithPromises
(
it
(
"
is shown in the
\"
Rooms
\"
panel
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{
allow_bookmarks
:
false
// Makes testing easier, otherwise we
{
allow_bookmarks
:
false
// Makes testing easier, otherwise we
// have to mock stanza traffic.
// have to mock stanza traffic.
},
},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
controlbox
=
_converse
.
chatboxviews
.
get
(
'
controlbox
'
);
const
controlbox
=
_converse
.
chatboxviews
.
get
(
'
controlbox
'
);
let
list
=
controlbox
.
el
.
querySelector
(
'
div.rooms-list-container
'
);
var
list
=
controlbox
.
el
.
querySelector
(
'
div.rooms-list-container
'
);
expect
(
_
.
includes
(
list
.
classList
,
'
hidden
'
)).
toBeTruthy
();
expect
(
_
.
includes
(
list
.
classList
,
'
hidden
'
)).
toBeTruthy
();
test_utils
.
openChatRoom
(
_converse
,
'
room
'
,
'
conference.shakespeare.lit
'
,
'
JC
'
);
let
room_els
;
expect
(
_
.
isUndefined
(
_converse
.
rooms_list_view
)).
toBeFalsy
();
test_utils
.
openChatRoom
(
_converse
,
'
room
'
,
'
conference.shakespeare.lit
'
,
'
JC
'
)
var
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
.
then
(()
=>
{
expect
(
room_els
.
length
).
toBe
(
1
);
expect
(
_
.
isUndefined
(
_converse
.
rooms_list_view
)).
toBeFalsy
();
expect
(
room_els
[
0
].
innerText
).
toBe
(
'
room@conference.shakespeare.lit
'
);
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
expect
(
room_els
.
length
).
toBe
(
1
);
test_utils
.
openChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
expect
(
room_els
[
0
].
innerText
).
toBe
(
'
room@conference.shakespeare.lit
'
);
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
return
test_utils
.
openChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
expect
(
room_els
.
length
).
toBe
(
2
);
}).
then
(()
=>
{
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
var
view
=
_converse
.
chatboxviews
.
get
(
'
room@conference.shakespeare.lit
'
);
expect
(
room_els
.
length
).
toBe
(
2
);
view
.
close
();
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
var
view
=
_converse
.
chatboxviews
.
get
(
'
room@conference.shakespeare.lit
'
);
expect
(
room_els
.
length
).
toBe
(
1
);
view
.
close
();
expect
(
room_els
[
0
].
innerText
).
toBe
(
'
lounge@localhost
'
);
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
list
=
controlbox
.
el
.
querySelector
(
'
div.rooms-list-container
'
);
expect
(
room_els
.
length
).
toBe
(
1
);
expect
(
_
.
includes
(
list
.
classList
,
'
hidden
'
)).
toBeFalsy
();
expect
(
room_els
[
0
].
innerText
).
toBe
(
'
lounge@localhost
'
);
list
=
controlbox
.
el
.
querySelector
(
'
div.rooms-list-container
'
);
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
expect
(
_
.
includes
(
list
.
classList
,
'
hidden
'
)).
toBeFalsy
();
view
.
close
();
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
expect
(
room_els
.
length
).
toBe
(
0
);
view
.
close
();
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
list
=
controlbox
.
el
.
querySelector
(
'
div.rooms-list-container
'
);
expect
(
room_els
.
length
).
toBe
(
0
);
expect
(
_
.
includes
(
list
.
classList
,
'
hidden
'
)).
toBeTruthy
();
done
();
list
=
controlbox
.
el
.
querySelector
(
'
div.rooms-list-container
'
);
expect
(
_
.
includes
(
list
.
classList
,
'
hidden
'
)).
toBeTruthy
();
done
();
});
}
}
));
));
});
});
...
@@ -57,79 +59,81 @@
...
@@ -57,79 +59,81 @@
describe
(
"
A groupchat shown in the groupchats list
"
,
function
()
{
describe
(
"
A groupchat shown in the groupchats list
"
,
function
()
{
it
(
"
is highlighted if its currently open
"
,
mock
.
initConverseWithPromises
(
it
(
"
is highlighted if its currently open
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{
whitelisted_plugins
:
[
'
converse-roomslist
'
],
{
whitelisted_plugins
:
[
'
converse-roomslist
'
],
allow_bookmarks
:
false
// Makes testing easier, otherwise we
allow_bookmarks
:
false
// Makes testing easier, otherwise we
// have to mock stanza traffic.
// have to mock stanza traffic.
},
function
(
done
,
_converse
)
{
},
function
(
done
,
_converse
)
{
spyOn
(
_converse
,
'
isSingleton
'
).
and
.
callFake
(
function
()
{
spyOn
(
_converse
,
'
isSingleton
'
).
and
.
callFake
(()
=>
true
);
return
true
;
});
let
room_els
,
item
;
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
_converse
.
api
.
rooms
.
open
(
'
coven@chat.shakespeare.lit
'
,
{
'
nick
'
:
'
some1
'
});
_converse
.
api
.
rooms
.
open
(
'
coven@chat.shakespeare.lit
'
,
{
'
nick
'
:
'
some1
'
})
let
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.available-chatroom
"
);
.
then
(()
=>
{
expect
(
room_els
.
length
).
toBe
(
1
);
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.available-chatroom
"
);
expect
(
room_els
.
length
).
toBe
(
1
);
let
item
=
room_els
[
0
];
expect
(
u
.
hasClass
(
'
open
'
,
item
)).
toBe
(
true
);
expect
(
item
.
textContent
.
trim
()).
toBe
(
'
coven@chat.shakespeare.lit
'
);
_converse
.
api
.
rooms
.
open
(
'
balcony@chat.shakespeare.lit
'
,
{
'
nick
'
:
'
some1
'
});
item
=
room_els
[
0
];
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
expect
(
u
.
hasClass
(
'
open
'
,
item
)).
toBe
(
true
);
expect
(
room_els
.
length
).
toBe
(
2
);
expect
(
item
.
textContent
.
trim
()).
toBe
(
'
coven@chat.shakespeare.lit
'
);
return
_converse
.
api
.
rooms
.
open
(
'
balcony@chat.shakespeare.lit
'
,
{
'
nick
'
:
'
some1
'
});
}).
then
(()
=>
{
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
expect
(
room_els
.
length
).
toBe
(
2
);
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.available-chatroom.open
"
);
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.available-chatroom.open
"
);
expect
(
room_els
.
length
).
toBe
(
1
);
expect
(
room_els
.
length
).
toBe
(
1
);
item
=
room_els
[
0
];
item
=
room_els
[
0
];
expect
(
item
.
textContent
.
trim
()).
toBe
(
'
balcony@chat.shakespeare.lit
'
);
expect
(
item
.
textContent
.
trim
()).
toBe
(
'
balcony@chat.shakespeare.lit
'
);
done
();
done
();
});
}));
}));
it
(
"
has an info icon which opens a details modal when clicked
"
,
mock
.
initConverseWithPromises
(
it
(
"
has an info icon which opens a details modal when clicked
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{
whitelisted_plugins
:
[
'
converse-roomslist
'
],
{
whitelisted_plugins
:
[
'
converse-roomslist
'
],
allow_bookmarks
:
false
// Makes testing easier, otherwise we
allow_bookmarks
:
false
// Makes testing easier, otherwise we
// have to mock stanza traffic.
// have to mock stanza traffic.
},
function
(
done
,
_converse
)
{
},
function
(
done
,
_converse
)
{
let
view
;
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
_converse
.
api
.
rooms
.
open
(
'
coven@chat.shakespeare.lit
'
,
{
'
nick
'
:
'
some1
'
})
;
_converse
.
api
.
rooms
.
open
(
'
coven@chat.shakespeare.lit
'
,
{
'
nick
'
:
'
some1
'
})
const
view
=
_converse
.
chatboxviews
.
get
(
'
coven@chat.shakespeare.lit
'
);
.
then
(()
=>
{
const
last_stanza
=
_
.
last
(
_converse
.
connection
.
IQ_stanzas
).
nodeTree
;
view
=
_converse
.
chatboxviews
.
get
(
'
coven@chat.shakespeare.lit
'
)
;
const
IQ_id
=
last_stanza
.
getAttribute
(
'
id
'
)
;
const
last_stanza
=
_
.
last
(
_converse
.
connection
.
IQ_stanzas
).
nodeTree
;
const
features_stanza
=
$iq
({
const
IQ_id
=
last_stanza
.
getAttribute
(
'
id
'
);
'
from
'
:
'
coven@chat.shakespeare.lit
'
,
const
features_stanza
=
$iq
({
'
id
'
:
IQ_id
,
'
from
'
:
'
coven@chat.shakespeare.lit
'
,
'
to
'
:
'
dummy@localhost/desktop
'
,
'
id
'
:
IQ_id
,
'
type
'
:
'
result
'
'
to
'
:
'
dummy@localhost/desktop
'
,
})
'
type
'
:
'
result
'
.
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
})
.
c
(
'
identity
'
,
{
.
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
'
category
'
:
'
conference
'
,
.
c
(
'
identity
'
,
{
'
name
'
:
'
A Dark Cav
e
'
,
'
category
'
:
'
conferenc
e
'
,
'
type
'
:
'
text
'
'
name
'
:
'
A Dark Cave
'
,
}).
up
()
'
type
'
:
'
text
'
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/muc
'
}).
up
()
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_passwordprotected
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/muc
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_hidden
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_passwordprotected
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_temporary
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_hidden
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_open
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_temporary
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_unmoderated
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_open
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_nonanonymous
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_unmoderated
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
urn:xmpp:mam:0
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_nonanonymous
'
}).
up
()
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:data
'
,
'
type
'
:
'
result
'
}
)
.
c
(
'
feature
'
,
{
'
var
'
:
'
urn:xmpp:mam:0
'
}).
up
(
)
.
c
(
'
field
'
,
{
'
var
'
:
'
FORM_TYPE
'
,
'
type
'
:
'
hidden
'
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:data
'
,
'
type
'
:
'
result
'
})
.
c
(
'
value
'
).
t
(
'
http://jabber.org/protocol/muc#roominfo
'
).
up
().
up
(
)
.
c
(
'
field
'
,
{
'
var
'
:
'
FORM_TYPE
'
,
'
type
'
:
'
hidden
'
}
)
.
c
(
'
field
'
,
{
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#roominfo_description
'
,
'
label
'
:
'
Description
'
}
)
.
c
(
'
value
'
).
t
(
'
http://jabber.org/protocol/muc#roominfo
'
).
up
().
up
(
)
.
c
(
'
value
'
).
t
(
'
This is the description
'
).
up
().
up
(
)
.
c
(
'
field
'
,
{
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#roominfo_description
'
,
'
label
'
:
'
Description
'
}
)
.
c
(
'
field
'
,
{
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#roominfo_occupants
'
,
'
label
'
:
'
Number of occupants
'
}
)
.
c
(
'
value
'
).
t
(
'
This is the description
'
).
up
().
up
(
)
.
c
(
'
value
'
).
t
(
0
);
.
c
(
'
field
'
,
{
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#roominfo_occupants
'
,
'
label
'
:
'
Number of occupants
'
})
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
features_stanza
)
);
.
c
(
'
value
'
).
t
(
0
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
features_stanza
));
test_utils
.
waitUntil
(()
=>
view
.
model
.
get
(
'
connection_status
'
)
===
converse
.
ROOMSTATUS
.
CONNECTING
)
return
test_utils
.
waitUntil
(()
=>
view
.
model
.
get
(
'
connection_status
'
)
===
converse
.
ROOMSTATUS
.
CONNECTING
)
.
then
(
function
()
{
})
.
then
(
function
()
{
var
presence
=
$pres
({
var
presence
=
$pres
({
to
:
_converse
.
connection
.
jid
,
to
:
_converse
.
connection
.
jid
,
from
:
'
coven@chat.shakespeare.lit/some1
'
,
from
:
'
coven@chat.shakespeare.lit/some1
'
,
...
@@ -201,23 +205,22 @@
...
@@ -201,23 +205,22 @@
},
},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
spyOn
(
window
,
'
confirm
'
).
and
.
callFake
(
function
()
{
spyOn
(
window
,
'
confirm
'
).
and
.
callFake
(()
=>
true
);
return
true
;
});
expect
(
_converse
.
chatboxes
.
length
).
toBe
(
1
);
expect
(
_converse
.
chatboxes
.
length
).
toBe
(
1
);
test_utils
.
openChatRoom
(
test_utils
.
openChatRoom
(
_converse
,
'
lounge
'
,
'
conference.shakespeare.lit
'
,
'
JC
'
)
_converse
,
'
lounge
'
,
'
conference.shakespeare.lit
'
,
'
JC
'
);
.
then
(()
=>
{
expect
(
_converse
.
chatboxes
.
length
).
toBe
(
2
);
expect
(
_converse
.
chatboxes
.
length
).
toBe
(
2
);
var
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
var
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
expect
(
room_els
.
length
).
toBe
(
1
);
expect
(
room_els
.
length
).
toBe
(
1
);
var
close_el
=
_converse
.
rooms_list_view
.
el
.
querySelector
(
"
.close-room
"
);
var
close_el
=
_converse
.
rooms_list_view
.
el
.
querySelector
(
"
.close-room
"
);
close_el
.
click
();
close_el
.
click
();
expect
(
window
.
confirm
).
toHaveBeenCalledWith
(
expect
(
window
.
confirm
).
toHaveBeenCalledWith
(
'
Are you sure you want to leave the groupchat lounge@conference.shakespeare.lit?
'
);
'
Are you sure you want to leave the groupchat lounge@conference.shakespeare.lit?
'
);
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
room_els
=
_converse
.
rooms_list_view
.
el
.
querySelectorAll
(
"
.open-room
"
);
expect
(
room_els
.
length
).
toBe
(
0
);
expect
(
room_els
.
length
).
toBe
(
0
);
expect
(
_converse
.
chatboxes
.
length
).
toBe
(
1
);
expect
(
_converse
.
chatboxes
.
length
).
toBe
(
1
);
done
();
done
();
});
}));
}));
it
(
"
shows unread messages directed at the user
"
,
mock
.
initConverseWithAsync
(
it
(
"
shows unread messages directed at the user
"
,
mock
.
initConverseWithAsync
(
...
...
spec/spoilers.js
View file @
506aa331
...
@@ -92,12 +92,14 @@
...
@@ -92,12 +92,14 @@
it
(
"
can be sent without a hint
"
,
it
(
"
can be sent without a hint
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
// XXX: We need to send a presence from the contact, so that we
// XXX: We need to send a presence from the contact, so that we
// have a resource, that resource is then queried to see
// have a resource, that resource is then queried to see
...
@@ -108,9 +110,9 @@
...
@@ -108,9 +110,9 @@
'
to
'
:
'
dummy@localhost
'
'
to
'
:
'
dummy@localhost
'
});
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
presence
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
presence
));
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
.
then
(()
=>
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
contact_jid
+
'
/phone
'
,
[],
[
Strophe
.
NS
.
SPOILER
]))
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
contact_jid
+
'
/phone
'
,
[],
[
Strophe
.
NS
.
SPOILER
]).
then
(
function
()
{
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
,
'
onMessageSubmitted
'
).
and
.
callThrough
();
spyOn
(
view
,
'
onMessageSubmitted
'
).
and
.
callThrough
();
spyOn
(
_converse
.
connection
,
'
send
'
);
spyOn
(
_converse
.
connection
,
'
send
'
);
...
@@ -167,10 +169,12 @@
...
@@ -167,10 +169,12 @@
it
(
"
can be sent with a hint
"
,
it
(
"
can be sent with a hint
"
,
mock
.
initConverseWithPromises
(
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
test_utils
.
openControlBox
();
test_utils
.
openControlBox
();
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
...
@@ -183,9 +187,9 @@
...
@@ -183,9 +187,9 @@
'
to
'
:
'
dummy@localhost
'
'
to
'
:
'
dummy@localhost
'
});
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
presence
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
presence
));
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
.
then
(()
=>
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
contact_jid
+
'
/phone
'
,
[],
[
Strophe
.
NS
.
SPOILER
]))
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
contact_jid
+
'
/phone
'
,
[],
[
Strophe
.
NS
.
SPOILER
]).
then
(
function
()
{
.
then
(()
=>
{
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
var
spoiler_toggle
=
view
.
el
.
querySelector
(
'
.toggle-compose-spoiler
'
);
var
spoiler_toggle
=
view
.
el
.
querySelector
(
'
.toggle-compose-spoiler
'
);
spoiler_toggle
.
click
();
spoiler_toggle
.
click
();
...
@@ -206,17 +210,17 @@
...
@@ -206,17 +210,17 @@
expect
(
view
.
onMessageSubmitted
).
toHaveBeenCalled
();
expect
(
view
.
onMessageSubmitted
).
toHaveBeenCalled
();
/* Test the XML stanza
/* Test the XML stanza
*
*
* <message from="dummy@localhost/resource"
* <message from="dummy@localhost/resource"
* to="max.frankfurter@localhost"
* to="max.frankfurter@localhost"
* type="chat"
* type="chat"
* id="4547c38b-d98b-45a5-8f44-b4004dbc335e"
* id="4547c38b-d98b-45a5-8f44-b4004dbc335e"
* xmlns="jabber:client">
* xmlns="jabber:client">
* <body>This is the spoiler</body>
* <body>This is the spoiler</body>
* <active xmlns="http://jabber.org/protocol/chatstates"/>
* <active xmlns="http://jabber.org/protocol/chatstates"/>
* <spoiler xmlns="urn:xmpp:spoiler:0">This is the hint</spoiler>
* <spoiler xmlns="urn:xmpp:spoiler:0">This is the hint</spoiler>
* </message>"
* </message>"
*/
*/
var
stanza
=
_converse
.
connection
.
send
.
calls
.
argsFor
(
0
)[
0
].
tree
();
var
stanza
=
_converse
.
connection
.
send
.
calls
.
argsFor
(
0
)[
0
].
tree
();
var
spoiler_el
=
stanza
.
querySelector
(
'
spoiler[xmlns="urn:xmpp:spoiler:0"]
'
);
var
spoiler_el
=
stanza
.
querySelector
(
'
spoiler[xmlns="urn:xmpp:spoiler:0"]
'
);
...
...
spec/user-details-modal.js
View file @
506aa331
...
@@ -58,16 +58,17 @@
...
@@ -58,16 +58,17 @@
test_utils
.
createContacts
(
_converse
,
'
current
'
);
test_utils
.
createContacts
(
_converse
,
'
current
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
let
view
,
modal
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
.
then
(()
=>
{
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
const
show_modal_button
=
view
.
el
.
querySelector
(
'
.show-user-details-modal
'
);
const
show_modal_button
=
view
.
el
.
querySelector
(
'
.show-user-details-modal
'
);
expect
(
u
.
isVisible
(
show_modal_button
)).
toBeTruthy
();
expect
(
u
.
isVisible
(
show_modal_button
)).
toBeTruthy
();
show_modal_button
.
click
();
show_modal_button
.
click
();
const
modal
=
view
.
user_details_modal
;
modal
=
view
.
user_details_modal
;
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
2000
)
return
test_utils
.
waitUntil
(()
=>
u
.
isVisible
(
modal
.
el
),
2000
);
.
then
(
function
()
{
})
.
then
(
function
()
{
spyOn
(
window
,
'
confirm
'
).
and
.
returnValue
(
true
);
spyOn
(
window
,
'
confirm
'
).
and
.
returnValue
(
true
);
spyOn
(
view
.
model
.
contact
,
'
removeFromRoster
'
).
and
.
callFake
(
function
(
callback
,
errback
)
{
spyOn
(
view
.
model
.
contact
,
'
removeFromRoster
'
).
and
.
callFake
(
function
(
callback
,
errback
)
{
errback
();
errback
();
...
...
src/converse-muc-views.js
View file @
506aa331
...
@@ -561,8 +561,7 @@
...
@@ -561,8 +561,7 @@
const
handler
=
()
=>
{
const
handler
=
()
=>
{
if
(
!
u
.
isPersistableModel
(
this
.
model
))
{
if
(
!
u
.
isPersistableModel
(
this
.
model
))
{
// Happens during tests, nothing to do if this
// Happens during tests, nothing to do if this
// is a hanging chatbox (i.e. not in the
// is a hanging chatbox (i.e. not in the collection anymore).
// collection anymore).
return
;
return
;
}
}
this
.
populateAndJoin
();
this
.
populateAndJoin
();
...
...
src/i18n.js
View file @
506aa331
...
@@ -148,8 +148,13 @@
...
@@ -148,8 +148,13 @@
);
);
xhr
.
onload
=
function
()
{
xhr
.
onload
=
function
()
{
if
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
)
{
if
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
)
{
jed_instance
=
new
Jed
(
window
.
JSON
.
parse
(
xhr
.
responseText
));
try
{
resolve
();
const
data
=
window
.
JSON
.
parse
(
xhr
.
responseText
);
jed_instance
=
new
Jed
(
data
);
resolve
();
}
catch
(
e
)
{
xhr
.
onerror
(
e
);
}
}
else
{
}
else
{
xhr
.
onerror
();
xhr
.
onerror
();
}
}
...
...
tests/utils.js
View file @
506aa331
...
@@ -98,8 +98,9 @@
...
@@ -98,8 +98,9 @@
return
views
;
return
views
;
};
};
utils
.
openChatBoxFor
=
function
(
converse
,
jid
)
{
utils
.
openChatBoxFor
=
function
(
_converse
,
jid
)
{
return
converse
.
roster
.
get
(
jid
).
trigger
(
"
open
"
);
_converse
.
roster
.
get
(
jid
).
trigger
(
"
open
"
);
return
utils
.
waitUntil
(()
=>
_converse
.
chatboxviews
.
get
(
jid
));
};
};
utils
.
openChatRoomViaModal
=
function
(
_converse
,
jid
,
nick
)
{
utils
.
openChatRoomViaModal
=
function
(
_converse
,
jid
,
nick
)
{
...
@@ -121,64 +122,64 @@
...
@@ -121,64 +122,64 @@
};
};
utils
.
openChatRoom
=
function
(
_converse
,
room
,
server
,
nick
)
{
utils
.
openChatRoom
=
function
(
_converse
,
room
,
server
,
nick
)
{
_converse
.
api
.
rooms
.
open
(
`
${
room
}
@
${
server
}
`
);
return
_converse
.
api
.
rooms
.
open
(
`
${
room
}
@
${
server
}
`
);
};
};
utils
.
openAndEnterChatRoom
=
function
(
_converse
,
room
,
server
,
nick
)
{
utils
.
openAndEnterChatRoom
=
function
(
_converse
,
room
,
server
,
nick
)
{
let
last_stanza
;
let
last_stanza
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
_converse
.
api
.
rooms
.
open
(
`
${
room
}
@
${
server
}
`
);
return
_converse
.
api
.
rooms
.
open
(
`
${
room
}
@
${
server
}
`
).
then
(()
=>
{
const
view
=
_converse
.
chatboxviews
.
get
((
room
+
'
@
'
+
server
).
toLowerCase
());
const
view
=
_converse
.
chatboxviews
.
get
((
room
+
'
@
'
+
server
).
toLowerCase
());
// We pretend this is a new room, so no disco info is returned.
// We pretend this is a new room, so no disco info is returned.
let
last_stanza
=
_
.
last
(
_converse
.
connection
.
IQ_stanzas
).
nodeTree
;
let
last_stanza
=
_
.
last
(
_converse
.
connection
.
IQ_stanzas
).
nodeTree
;
const
IQ_id
=
last_stanza
.
getAttribute
(
'
id
'
);
const
features_stanza
=
$iq
({
'
from
'
:
room
+
'
@
'
+
server
,
'
id
'
:
IQ_id
,
'
to
'
:
nick
+
'
@
'
+
server
,
'
type
'
:
'
error
'
}).
c
(
'
error
'
,
{
'
type
'
:
'
cancel
'
})
.
c
(
'
item-not-found
'
,
{
'
xmlns
'
:
"
urn:ietf:params:xml:ns:xmpp-stanzas
"
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
features_stanza
));
utils
.
waitUntil
(()
=>
{
return
_
.
filter
(
_converse
.
connection
.
IQ_stanzas
,
(
node
)
=>
{
const
query
=
node
.
nodeTree
.
querySelector
(
'
query
'
);
if
(
query
&&
query
.
getAttribute
(
'
node
'
)
===
'
x-roomuser-item
'
)
{
last_stanza
=
node
.
nodeTree
;
return
true
;
}
}).
length
}).
then
(
function
()
{
// The XMPP server returns the reserved nick for this user.
const
IQ_id
=
last_stanza
.
getAttribute
(
'
id
'
);
const
IQ_id
=
last_stanza
.
getAttribute
(
'
id
'
);
const
stanza
=
$iq
({
const
features_stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
from
'
:
room
+
'
@
'
+
server
,
'
id
'
:
IQ_id
,
'
id
'
:
IQ_id
,
'
from
'
:
view
.
model
.
get
(
'
jid
'
),
'
to
'
:
nick
+
'
@
'
+
server
,
'
to
'
:
_converse
.
connection
.
jid
'
type
'
:
'
error
'
}).
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
,
'
node
'
:
'
x-roomuser-item
'
})
}).
c
(
'
error
'
,
{
'
type
'
:
'
cancel
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
conference
'
,
'
name
'
:
nick
,
'
type
'
:
'
text
'
});
.
c
(
'
item-not-found
'
,
{
'
xmlns
'
:
"
urn:ietf:params:xml:ns:xmpp-stanzas
"
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
stanza
));
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
features_stanza
));
// The user has just entered the room (because join was called)
// and receives their own presence from the server.
// See example 24: http://xmpp.org/extensions/xep-0045.html#enter-pres
var
presence
=
$pres
({
to
:
_converse
.
connection
.
jid
,
from
:
room
+
'
@
'
+
server
+
'
/
'
+
nick
,
id
:
'
DC352437-C019-40EC-B590-AF29E879AF97
'
}).
c
(
'
x
'
).
attrs
({
xmlns
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
item
'
).
attrs
({
affiliation
:
'
member
'
,
jid
:
_converse
.
bare_jid
,
role
:
'
participant
'
}).
up
()
.
c
(
'
status
'
).
attrs
({
code
:
'
110
'
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
presence
));
resolve
();
utils
.
waitUntil
(()
=>
{
return
_
.
filter
(
_converse
.
connection
.
IQ_stanzas
,
(
node
)
=>
{
const
query
=
node
.
nodeTree
.
querySelector
(
'
query
'
);
if
(
query
&&
query
.
getAttribute
(
'
node
'
)
===
'
x-roomuser-item
'
)
{
last_stanza
=
node
.
nodeTree
;
return
true
;
}
}).
length
}).
then
(
function
()
{
// The XMPP server returns the reserved nick for this user.
const
IQ_id
=
last_stanza
.
getAttribute
(
'
id
'
);
const
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
id
'
:
IQ_id
,
'
from
'
:
view
.
model
.
get
(
'
jid
'
),
'
to
'
:
_converse
.
connection
.
jid
}).
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
,
'
node
'
:
'
x-roomuser-item
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
conference
'
,
'
name
'
:
nick
,
'
type
'
:
'
text
'
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
stanza
));
// The user has just entered the room (because join was called)
// and receives their own presence from the server.
// See example 24: http://xmpp.org/extensions/xep-0045.html#enter-pres
var
presence
=
$pres
({
to
:
_converse
.
connection
.
jid
,
from
:
room
+
'
@
'
+
server
+
'
/
'
+
nick
,
id
:
'
DC352437-C019-40EC-B590-AF29E879AF97
'
}).
c
(
'
x
'
).
attrs
({
xmlns
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
item
'
).
attrs
({
affiliation
:
'
member
'
,
jid
:
_converse
.
bare_jid
,
role
:
'
participant
'
}).
up
()
.
c
(
'
status
'
).
attrs
({
code
:
'
110
'
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
presence
));
resolve
();
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment