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
94306271
Commit
94306271
authored
Jun 26, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-group some message specs
parent
2cbc4aaa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
75 deletions
+77
-75
spec/messages.js
spec/messages.js
+77
-75
No files found.
spec/messages.js
View file @
94306271
...
...
@@ -824,28 +824,6 @@
done
();
}));
it
(
"
can be sent from a chatbox, and will appear inside it
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
async
function
(
done
,
_converse
)
{
await
test_utils
.
waitForRoster
(
_converse
,
'
current
'
);
test_utils
.
openControlBox
();
spyOn
(
_converse
.
api
,
"
trigger
"
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@montague.lit
'
;
await
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
expect
(
_converse
.
api
.
trigger
).
toHaveBeenCalledWith
(
'
chatBoxFocused
'
,
jasmine
.
any
(
Object
));
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
const
message
=
'
This message is sent from this chatbox
'
;
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
await
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
view
.
model
.
messages
.
length
,
2
);
expect
(
_converse
.
api
.
trigger
.
calls
.
mostRecent
().
args
,
[
'
messageSend
'
,
message
]);
expect
(
sizzle
(
'
.chat-content .chat-msg:last .chat-msg__text
'
,
view
.
el
).
pop
().
textContent
).
toEqual
(
message
);
done
();
}));
it
(
"
is sanitized to prevent Javascript injection attacks
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
...
...
@@ -1340,63 +1318,87 @@
done
();
}));
it
(
"
delivery can be acknowledged by a receipt
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
async
function
(
done
,
_converse
)
{
describe
(
"
when sent
"
,
function
()
{
await
test_utils
.
waitForRoster
(
_converse
,
'
current
'
,
1
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@montague.lit
'
;
await
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
const
textarea
=
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
);
textarea
.
value
=
'
But soft, what light through yonder airlock breaks?
'
;
view
.
onKeyDown
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
await
test_utils
.
waitUntil
(()
=>
_converse
.
api
.
chats
.
get
().
length
);
const
chatbox
=
_converse
.
chatboxes
.
get
(
contact_jid
);
expect
(
chatbox
).
toBeDefined
();
await
new
Promise
((
resolve
,
reject
)
=>
view
.
once
(
'
messageInserted
'
,
resolve
));
let
msg_obj
=
chatbox
.
messages
.
models
[
0
];
let
msg_id
=
msg_obj
.
get
(
'
msgid
'
);
let
msg
=
$msg
({
'
from
'
:
contact_jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
id
'
:
u
.
getUniqueId
(),
}).
c
(
'
received
'
,
{
'
id
'
:
msg_id
,
xmlns
:
Strophe
.
NS
.
RECEIPTS
}).
up
().
tree
();
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
msg
));
await
new
Promise
((
resolve
,
reject
)
=>
view
.
model
.
messages
.
once
(
'
rendered
'
,
resolve
));
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg__receipt
'
).
length
).
toBe
(
1
);
it
(
"
can have its delivery acknowledged by a receipt
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
async
function
(
done
,
_converse
)
{
// Also handle receipts with type 'chat'. See #1353
spyOn
(
_converse
.
chatboxes
,
'
onMessage
'
).
and
.
callThrough
();
textarea
.
value
=
'
Another message
'
;
view
.
onKeyDown
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
await
new
Promise
((
resolve
,
reject
)
=>
view
.
once
(
'
messageInserted
'
,
resolve
));
await
test_utils
.
waitForRoster
(
_converse
,
'
current
'
,
1
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@montague.lit
'
;
await
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
const
textarea
=
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
);
textarea
.
value
=
'
But soft, what light through yonder airlock breaks?
'
;
view
.
onKeyDown
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
await
test_utils
.
waitUntil
(()
=>
_converse
.
api
.
chats
.
get
().
length
);
const
chatbox
=
_converse
.
chatboxes
.
get
(
contact_jid
);
expect
(
chatbox
).
toBeDefined
();
await
new
Promise
((
resolve
,
reject
)
=>
view
.
once
(
'
messageInserted
'
,
resolve
));
let
msg_obj
=
chatbox
.
messages
.
models
[
0
];
let
msg_id
=
msg_obj
.
get
(
'
msgid
'
);
let
msg
=
$msg
({
'
from
'
:
contact_jid
,
'
to
'
:
_converse
.
connection
.
jid
,
'
id
'
:
u
.
getUniqueId
(),
}).
c
(
'
received
'
,
{
'
id
'
:
msg_id
,
xmlns
:
Strophe
.
NS
.
RECEIPTS
}).
up
().
tree
();
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
msg
));
await
new
Promise
((
resolve
,
reject
)
=>
view
.
model
.
messages
.
once
(
'
rendered
'
,
resolve
));
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg__receipt
'
).
length
).
toBe
(
1
);
// Also handle receipts with type 'chat'. See #1353
spyOn
(
_converse
.
chatboxes
,
'
onMessage
'
).
and
.
callThrough
();
textarea
.
value
=
'
Another message
'
;
view
.
onKeyDown
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
// Enter
});
await
new
Promise
((
resolve
,
reject
)
=>
view
.
once
(
'
messageInserted
'
,
resolve
));
msg_obj
=
chatbox
.
messages
.
models
[
1
];
msg_id
=
msg_obj
.
get
(
'
msgid
'
);
msg
=
$msg
({
'
from
'
:
contact_jid
,
'
type
'
:
'
chat
'
,
'
to
'
:
_converse
.
connection
.
jid
,
'
id
'
:
u
.
getUniqueId
(),
}).
c
(
'
received
'
,
{
'
id
'
:
msg_id
,
xmlns
:
Strophe
.
NS
.
RECEIPTS
}).
up
().
tree
();
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
msg
));
await
new
Promise
((
resolve
,
reject
)
=>
view
.
model
.
messages
.
once
(
'
rendered
'
,
resolve
));
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg__receipt
'
).
length
).
toBe
(
2
);
expect
(
_converse
.
chatboxes
.
onMessage
.
calls
.
count
()).
toBe
(
1
);
done
();
}));
msg_obj
=
chatbox
.
messages
.
models
[
1
];
msg_id
=
msg_obj
.
get
(
'
msgid
'
);
msg
=
$msg
({
'
from
'
:
contact_jid
,
'
type
'
:
'
chat
'
,
'
to
'
:
_converse
.
connection
.
jid
,
'
id
'
:
u
.
getUniqueId
(),
}).
c
(
'
received
'
,
{
'
id
'
:
msg_id
,
xmlns
:
Strophe
.
NS
.
RECEIPTS
}).
up
().
tree
();
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
msg
));
await
new
Promise
((
resolve
,
reject
)
=>
view
.
model
.
messages
.
once
(
'
rendered
'
,
resolve
));
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg__receipt
'
).
length
).
toBe
(
2
);
expect
(
_converse
.
chatboxes
.
onMessage
.
calls
.
count
()).
toBe
(
1
);
done
();
}));
it
(
"
will appear inside the chatbox it was sent from
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
async
function
(
done
,
_converse
)
{
await
test_utils
.
waitForRoster
(
_converse
,
'
current
'
);
test_utils
.
openControlBox
();
spyOn
(
_converse
.
api
,
"
trigger
"
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@montague.lit
'
;
await
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
expect
(
_converse
.
api
.
trigger
).
toHaveBeenCalledWith
(
'
chatBoxFocused
'
,
jasmine
.
any
(
Object
));
const
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
const
message
=
'
This message is sent from this chatbox
'
;
spyOn
(
view
.
model
,
'
sendMessage
'
).
and
.
callThrough
();
await
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
expect
(
view
.
model
.
messages
.
length
,
2
);
expect
(
_converse
.
api
.
trigger
.
calls
.
mostRecent
().
args
,
[
'
messageSend
'
,
message
]);
expect
(
sizzle
(
'
.chat-content .chat-msg:last .chat-msg__text
'
,
view
.
el
).
pop
().
textContent
).
toEqual
(
message
);
done
();
}));
describe
(
"
when sent
"
,
function
()
{
it
(
"
will be trimmed of leading and trailing whitespace
"
,
mock
.
initConverse
(
...
...
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