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
e07bb52d
Commit
e07bb52d
authored
Nov 18, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use async/await
parent
c46d937e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
81 deletions
+70
-81
spec/controlbox.js
spec/controlbox.js
+37
-42
spec/messages.js
spec/messages.js
+33
-39
No files found.
spec/controlbox.js
View file @
e07bb52d
...
...
@@ -68,53 +68,48 @@
it
(
"
shows the number of unread mentions received
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
all
'
).
openControlBox
();
_converse
.
emit
(
'
rosterContactsFetched
'
);
let
chatview
;
const
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
return
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxes
.
length
).
then
(()
=>
{
chatview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
chatview
.
model
.
set
({
'
minimized
'
:
true
});
expect
(
_
.
isNull
(
_converse
.
chatboxviews
.
el
.
querySelector
(
'
.restore-chat .message-count
'
))).
toBeTruthy
();
expect
(
_
.
isNull
(
_converse
.
rosterview
.
el
.
querySelector
(
'
.msgs-indicator
'
))).
toBeTruthy
();
const
msg
=
$msg
({
from
:
sender_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
();
_converse
.
chatboxes
.
onMessage
(
msg
);
return
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
"
.msgs-indicator
"
));
}).
then
(()
=>
{
spyOn
(
chatview
.
model
,
'
incrementUnreadMsgCounter
'
).
and
.
callThrough
();
expect
(
_converse
.
chatboxviews
.
el
.
querySelector
(
'
.restore-chat .message-count
'
).
textContent
).
toBe
(
'
1
'
);
expect
(
_converse
.
rosterview
.
el
.
querySelector
(
'
.msgs-indicator
'
).
textContent
).
toBe
(
'
1
'
);
const
msg
=
$msg
({
from
:
sender_jid
,
to
:
_converse
.
connection
.
jid
,
type
:
'
chat
'
,
id
:
(
new
Date
()).
getTime
()
}).
c
(
'
body
'
).
t
(
'
hello again
'
).
up
()
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
}).
tree
();
_converse
.
chatboxes
.
onMessage
(
msg
);
return
test_utils
.
waitUntil
(()
=>
chatview
.
model
.
incrementUnreadMsgCounter
.
calls
.
count
());
}).
then
(()
=>
{
expect
(
_converse
.
chatboxviews
.
el
.
querySelector
(
'
.restore-chat .message-count
'
).
textContent
).
toBe
(
'
2
'
);
expect
(
_converse
.
rosterview
.
el
.
querySelector
(
'
.msgs-indicator
'
).
textContent
).
toBe
(
'
2
'
);
chatview
.
model
.
set
({
'
minimized
'
:
false
});
expect
(
_
.
isNull
(
_converse
.
chatboxviews
.
el
.
querySelector
(
'
.restore-chat .message-count
'
))).
toBeTruthy
();
expect
(
_
.
isNull
(
_converse
.
rosterview
.
el
.
querySelector
(
'
.msgs-indicator
'
))).
toBeTruthy
();
done
();
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
await
test_utils
.
openChatBoxFor
(
_converse
,
sender_jid
);
await
test_utils
.
waitUntil
(()
=>
_converse
.
chatboxes
.
length
);
const
chatview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
chatview
.
model
.
set
({
'
minimized
'
:
true
});
expect
(
_
.
isNull
(
_converse
.
chatboxviews
.
el
.
querySelector
(
'
.restore-chat .message-count
'
))).
toBeTruthy
();
expect
(
_
.
isNull
(
_converse
.
rosterview
.
el
.
querySelector
(
'
.msgs-indicator
'
))).
toBeTruthy
();
let
msg
=
$msg
({
from
:
sender_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
();
_converse
.
chatboxes
.
onMessage
(
msg
);
await
test_utils
.
waitUntil
(()
=>
_converse
.
rosterview
.
el
.
querySelectorAll
(
"
.msgs-indicator
"
));
spyOn
(
chatview
.
model
,
'
incrementUnreadMsgCounter
'
).
and
.
callThrough
();
expect
(
_converse
.
chatboxviews
.
el
.
querySelector
(
'
.restore-chat .message-count
'
).
textContent
).
toBe
(
'
1
'
);
expect
(
_converse
.
rosterview
.
el
.
querySelector
(
'
.msgs-indicator
'
).
textContent
).
toBe
(
'
1
'
);
msg
=
$msg
({
from
:
sender_jid
,
to
:
_converse
.
connection
.
jid
,
type
:
'
chat
'
,
id
:
(
new
Date
()).
getTime
()
}).
c
(
'
body
'
).
t
(
'
hello again
'
).
up
()
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
}).
tree
();
_converse
.
chatboxes
.
onMessage
(
msg
);
await
test_utils
.
waitUntil
(()
=>
chatview
.
model
.
incrementUnreadMsgCounter
.
calls
.
count
());
expect
(
_converse
.
chatboxviews
.
el
.
querySelector
(
'
.restore-chat .message-count
'
).
textContent
).
toBe
(
'
2
'
);
expect
(
_converse
.
rosterview
.
el
.
querySelector
(
'
.msgs-indicator
'
).
textContent
).
toBe
(
'
2
'
);
chatview
.
model
.
set
({
'
minimized
'
:
false
});
expect
(
_
.
isNull
(
_converse
.
chatboxviews
.
el
.
querySelector
(
'
.restore-chat .message-count
'
))).
toBeTruthy
();
expect
(
_
.
isNull
(
_converse
.
rosterview
.
el
.
querySelector
(
'
.msgs-indicator
'
))).
toBeTruthy
();
done
();
}));
});
...
...
spec/messages.js
View file @
e07bb52d
...
...
@@ -961,51 +961,45 @@
}));
it
(
"
will render images from their URLs
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
async
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
base_url
=
document
.
URL
.
split
(
window
.
location
.
pathname
)[
0
];
let
message
=
base_url
+
"
/logo/conversejs-filled.svg
"
;
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
let
view
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
.
then
(()
=>
{
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
test_utils
.
sendMessage
(
view
,
message
);
return
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
,
1000
)
}).
then
(()
=>
{
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
const
msg
=
$
(
view
.
el
).
find
(
'
.chat-content .chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
().
trim
()).
toEqual
(
'
<!-- src/templates/image.html -->
\n
'
+
'
<a href="
'
+
base_url
+
'
/logo/conversejs-filled.svg" target="_blank" rel="noopener"><img class="chat-image img-thumbnail"
'
+
'
src="
'
+
message
+
'
"></a>
'
);
message
+=
"
?param1=val1¶m2=val2
"
;
test_utils
.
sendMessage
(
view
,
message
);
return
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
===
2
,
1000
);
}).
then
(()
=>
{
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
const
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
().
trim
()).
toEqual
(
'
<!-- src/templates/image.html -->
\n
'
+
'
<a href="
'
+
base_url
+
'
/logo/conversejs-filled.svg?param1=val1&param2=val2" target="_blank" rel="noopener"><img
'
+
'
class="chat-image img-thumbnail" src="
'
+
message
.
replace
(
/&/g
,
'
&
'
)
+
'
"></a>
'
)
// Test now with two images in one message
message
+=
'
hello world
'
+
base_url
+
"
/logo/conversejs-filled.svg
"
;
test_utils
.
sendMessage
(
view
,
message
);
return
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
===
4
,
1000
);
}).
then
(
function
()
{
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
const
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
[
0
].
textContent
.
trim
()).
toEqual
(
'
hello world
'
);
expect
(
msg
[
0
].
querySelectorAll
(
'
img
'
).
length
).
toEqual
(
2
);
done
();
});
await
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
test_utils
.
sendMessage
(
view
,
message
);
await
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
,
1000
)
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
let
msg
=
$
(
view
.
el
).
find
(
'
.chat-content .chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
().
trim
()).
toEqual
(
'
<!-- src/templates/image.html -->
\n
'
+
'
<a href="
'
+
base_url
+
'
/logo/conversejs-filled.svg" target="_blank" rel="noopener"><img class="chat-image img-thumbnail"
'
+
'
src="
'
+
message
+
'
"></a>
'
);
message
+=
"
?param1=val1¶m2=val2
"
;
test_utils
.
sendMessage
(
view
,
message
);
await
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
===
2
,
1000
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
.
html
().
trim
()).
toEqual
(
'
<!-- src/templates/image.html -->
\n
'
+
'
<a href="
'
+
base_url
+
'
/logo/conversejs-filled.svg?param1=val1&param2=val2" target="_blank" rel="noopener"><img
'
+
'
class="chat-image img-thumbnail" src="
'
+
message
.
replace
(
/&/g
,
'
&
'
)
+
'
"></a>
'
)
// Test now with two images in one message
message
+=
'
hello world
'
+
base_url
+
"
/logo/conversejs-filled.svg
"
;
test_utils
.
sendMessage
(
view
,
message
);
await
test_utils
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
===
4
,
1000
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
msg
=
$
(
view
.
el
).
find
(
'
.chat-content
'
).
find
(
'
.chat-msg
'
).
last
().
find
(
'
.chat-msg__text
'
);
expect
(
msg
[
0
].
textContent
.
trim
()).
toEqual
(
'
hello world
'
);
expect
(
msg
[
0
].
querySelectorAll
(
'
img
'
).
length
).
toEqual
(
2
);
done
();
}));
it
(
"
will render the message time as configured
"
,
...
...
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