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
20706cb6
Commit
20706cb6
authored
Feb 06, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand the spoiler tests
parent
f6db2a91
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
160 additions
and
38 deletions
+160
-38
spec/spoilers.js
spec/spoilers.js
+121
-12
src/converse-chatboxes.js
src/converse-chatboxes.js
+1
-1
src/converse-chatview.js
src/converse-chatview.js
+22
-15
src/converse-otr.js
src/converse-otr.js
+16
-10
No files found.
spec/spoilers.js
View file @
20706cb6
...
...
@@ -10,6 +10,7 @@
var
_
=
converse
.
env
.
_
;
var
$msg
=
converse
.
env
.
$msg
;
var
u
=
converse
.
env
.
utils
;
return
describe
(
"
A spoiler message
"
,
function
()
{
...
...
@@ -26,8 +27,8 @@
* <spoiler xmlns='urn:xmpp:spoiler:0'>Love story end</spoiler>
* </message>
*/
const
spoiler_hint
=
"
Love story end
"
const
spoiler
=
"
And at the end of the story, both of them die! It is so tragic!
"
;
var
spoiler_hint
=
"
Love story end
"
var
spoiler
=
"
And at the end of the story, both of them die! It is so tragic!
"
;
var
msg
=
$msg
({
'
xmlns
'
:
'
jabber:client
'
,
'
to
'
:
_converse
.
bare_jid
,
...
...
@@ -40,15 +41,46 @@
.
tree
();
_converse
.
chatboxes
.
onMessage
(
msg
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
message_content
=
chatboxview
.
el
.
querySelector
(
'
.chat-message .chat-msg-content
'
);
var
view
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
message_content
=
view
.
el
.
querySelector
(
'
.chat-msg-content
'
);
expect
(
message_content
.
textContent
).
toBe
(
spoiler
);
// TODO add better assertions, currently only checks whether the
// text is in the DOM, not whether the spoiler is shown or
// not. Before updating this the spoiler rendering code needs
// improvement.
expect
(
_
.
includes
(
message_content
.
outerHTML
,
spoiler_hint
)).
toBeTruthy
();
expect
(
_
.
includes
(
message_content
.
outerHTML
,
spoiler
)).
toBeTruthy
();
var
spoiler_hint_el
=
view
.
el
.
querySelector
(
'
.spoiler-hint
'
);
expect
(
spoiler_hint_el
.
textContent
).
toBe
(
spoiler_hint
);
done
();
}));
it
(
"
can be received without a hint
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
/* <message to='romeo@montague.net/orchard' from='juliet@capulet.net/balcony' id='spoiler2'>
* <body>And at the end of the story, both of them die! It is so tragic!</body>
* <spoiler xmlns='urn:xmpp:spoiler:0'>Love story end</spoiler>
* </message>
*/
var
spoiler
=
"
And at the end of the story, both of them die! It is so tragic!
"
;
var
msg
=
$msg
({
'
xmlns
'
:
'
jabber:client
'
,
'
to
'
:
_converse
.
bare_jid
,
'
from
'
:
sender_jid
,
'
type
'
:
'
chat
'
}).
c
(
'
body
'
).
t
(
spoiler
).
up
()
.
c
(
'
spoiler
'
,
{
'
xmlns
'
:
'
urn:xmpp:spoiler:0
'
,
}).
tree
();
_converse
.
chatboxes
.
onMessage
(
msg
);
var
view
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
message_content
=
view
.
el
.
querySelector
(
'
.chat-msg-content
'
);
expect
(
message_content
.
textContent
).
toBe
(
spoiler
);
var
spoiler_hint_el
=
view
.
el
.
querySelector
(
'
.spoiler-hint
'
);
expect
(
spoiler_hint_el
.
textContent
).
toBe
(
''
);
done
();
}));
...
...
@@ -65,6 +97,7 @@
var
view
=
_converse
.
chatboxviews
.
get
(
contact_jid
);
spyOn
(
view
,
'
onMessageSubmitted
'
).
and
.
callThrough
();
spyOn
(
_converse
.
connection
,
'
send
'
);
var
spoiler_toggle
=
view
.
el
.
querySelector
(
'
.toggle-spoiler-edit
'
);
spoiler_toggle
.
click
();
...
...
@@ -77,6 +110,39 @@
keyCode
:
13
});
expect
(
view
.
onMessageSubmitted
).
toHaveBeenCalled
();
/* Test the XML stanza
*
* <message from="dummy@localhost/resource"
* to="max.frankfurter@localhost"
* type="chat"
* id="4547c38b-d98b-45a5-8f44-b4004dbc335e"
* xmlns="jabber:client">
* <body>This is the spoiler</body>
* <active xmlns="http://jabber.org/protocol/chatstates"/>
* <spoiler xmlns="urn:xmpp:spoiler:0"/>
* </message>"
*/
var
stanza
=
_converse
.
connection
.
send
.
calls
.
argsFor
(
0
)[
0
].
tree
();
var
spoiler_el
=
stanza
.
querySelector
(
'
spoiler[xmlns="urn:xmpp:spoiler:0"]
'
);
expect
(
_
.
isNull
(
spoiler_el
)).
toBeFalsy
();
expect
(
spoiler_el
.
textContent
).
toBe
(
''
);
var
body_el
=
stanza
.
querySelector
(
'
body
'
);
expect
(
body_el
.
textContent
).
toBe
(
'
This is the spoiler
'
);
/* Test the HTML spoiler message */
var
spoiler_msg_el
=
view
.
el
.
querySelector
(
'
.chat-msg-content.spoiler
'
);
expect
(
spoiler_msg_el
.
textContent
).
toBe
(
'
This is the spoiler
'
);
expect
(
_
.
includes
(
spoiler_msg_el
.
classList
,
'
collapsed
'
)).
toBeTruthy
();
spoiler_toggle
=
view
.
el
.
querySelector
(
'
.toggle-spoiler
'
);
expect
(
spoiler_toggle
.
textContent
).
toBe
(
'
Show spoiler
'
);
spoiler_toggle
.
click
();
expect
(
_
.
includes
(
spoiler_msg_el
.
classList
,
'
collapsed
'
)).
toBeFalsy
();
expect
(
spoiler_toggle
.
textContent
).
toBe
(
'
Hide spoiler
'
);
spoiler_toggle
.
click
();
expect
(
_
.
includes
(
spoiler_msg_el
.
classList
,
'
collapsed
'
)).
toBeTruthy
();
done
();
}));
...
...
@@ -96,10 +162,53 @@
var
spoiler_toggle
=
view
.
el
.
querySelector
(
'
.toggle-spoiler-edit
'
);
spoiler_toggle
.
click
();
var
hint_input
=
view
.
el
.
querySelector
(
'
.chat-textarea-hint
'
);
spyOn
(
view
,
'
onMessageSubmitted
'
).
and
.
callThrough
();
spyOn
(
_converse
.
connection
,
'
send
'
);
var
textarea
=
view
.
el
.
querySelector
(
'
.chat-textarea
'
);
textarea
.
value
=
'
This is the spoiler
'
;
var
hint_input
=
view
.
el
.
querySelector
(
'
.spoiler-hint
'
);
hint_input
.
value
=
'
This is the hint
'
;
view
.
keyPressed
({
target
:
textarea
,
preventDefault
:
_
.
noop
,
keyCode
:
13
});
expect
(
view
.
onMessageSubmitted
).
toHaveBeenCalled
();
/* Test the XML stanza
*
* <message from="dummy@localhost/resource"
* to="max.frankfurter@localhost"
* type="chat"
* id="4547c38b-d98b-45a5-8f44-b4004dbc335e"
* xmlns="jabber:client">
* <body>This is the spoiler</body>
* <active xmlns="http://jabber.org/protocol/chatstates"/>
* <spoiler xmlns="urn:xmpp:spoiler:0">This is the hint</spoiler>
* </message>"
*/
var
stanza
=
_converse
.
connection
.
send
.
calls
.
argsFor
(
0
)[
0
].
tree
();
var
spoiler_el
=
stanza
.
querySelector
(
'
spoiler[xmlns="urn:xmpp:spoiler:0"]
'
);
expect
(
_
.
isNull
(
spoiler_el
)).
toBeFalsy
();
expect
(
spoiler_el
.
textContent
).
toBe
(
'
This is the hint
'
);
var
body_el
=
stanza
.
querySelector
(
'
body
'
);
expect
(
body_el
.
textContent
).
toBe
(
'
This is the spoiler
'
);
// TODO
/* Test the HTML spoiler message */
var
spoiler_msg_el
=
view
.
el
.
querySelector
(
'
.chat-msg-content.spoiler
'
);
expect
(
spoiler_msg_el
.
textContent
).
toBe
(
'
This is the spoiler
'
);
expect
(
_
.
includes
(
spoiler_msg_el
.
classList
,
'
collapsed
'
)).
toBeTruthy
();
spoiler_toggle
=
view
.
el
.
querySelector
(
'
.toggle-spoiler
'
);
expect
(
spoiler_toggle
.
textContent
).
toBe
(
'
Show spoiler
'
);
spoiler_toggle
.
click
();
expect
(
_
.
includes
(
spoiler_msg_el
.
classList
,
'
collapsed
'
)).
toBeFalsy
();
expect
(
spoiler_toggle
.
textContent
).
toBe
(
'
Hide spoiler
'
);
spoiler_toggle
.
click
();
expect
(
_
.
includes
(
spoiler_msg_el
.
classList
,
'
collapsed
'
)).
toBeTruthy
();
done
();
}));
});
...
...
src/converse-chatboxes.js
View file @
20706cb6
...
...
@@ -171,7 +171,7 @@
'
is_spoiler
'
:
!
_
.
isNull
(
spoiler
)
};
if
(
spoiler
)
{
attrs
.
spoiler_hint
=
spoiler
.
textContent
.
length
>
0
?
spoiler
.
textContent
:
__
(
'
Spoiler
'
)
;
attrs
.
spoiler_hint
=
spoiler
.
textContent
.
length
>
0
?
spoiler
.
textContent
:
''
;
}
return
attrs
;
},
...
...
src/converse-chatview.js
View file @
20706cb6
...
...
@@ -853,6 +853,25 @@
}
},
parseMessageForCommands
(
text
)
{
const
match
=
text
.
replace
(
/^
\s
*/
,
""
).
match
(
/^
\/(
.*
)\s
*$/
);
if
(
match
)
{
if
(
match
[
1
]
===
"
clear
"
)
{
this
.
clearMessages
();
return
true
;
}
else
if
(
match
[
1
]
===
"
help
"
)
{
const
msgs
=
[
`<strong>/clear</strong>:
${
__
(
'
Remove messages
'
)}
`
,
`<strong>/me</strong>:
${
__
(
'
Write in the third person
'
)}
`
,
`<strong>/help</strong>:
${
__
(
'
Show this menu
'
)}
`
];
this
.
showHelpMessages
(
msgs
);
return
true
;
}
}
},
onMessageSubmitted
(
text
,
spoiler_hint
)
{
/* This method gets called once the user has typed a message
* and then pressed enter in a chat box.
...
...
@@ -869,20 +888,8 @@
'
error
'
);
}
const
match
=
text
.
replace
(
/^
\s
*/
,
""
).
match
(
/^
\/(
.*
)\s
*$/
);
if
(
match
)
{
if
(
match
[
1
]
===
"
clear
"
)
{
return
this
.
clearMessages
();
}
else
if
(
match
[
1
]
===
"
help
"
)
{
const
msgs
=
[
`<strong>/clear</strong>:
${
__
(
'
Remove messages
'
)}
`
,
`<strong>/me</strong>:
${
__
(
'
Write in the third person
'
)}
`
,
`<strong>/help</strong>:
${
__
(
'
Show this menu
'
)}
`
];
this
.
showHelpMessages
(
msgs
);
return
;
}
if
(
this
.
parseMessageForCommands
(
text
))
{
return
;
}
const
attrs
=
this
.
getOutgoingMessageAttributes
(
text
,
spoiler_hint
)
const
message
=
this
.
model
.
messages
.
create
(
attrs
);
...
...
@@ -962,7 +969,7 @@
message
=
textarea
.
value
;
let
spoiler_hint
;
if
(
this
.
model
.
get
(
'
sending_spoiler
'
))
{
if
(
this
.
m
essage_form_view
.
m
odel
.
get
(
'
sending_spoiler
'
))
{
const
hint_el
=
this
.
el
.
querySelector
(
'
form.sendXMPPMessage input.spoiler-hint
'
);
spoiler_hint
=
hint_el
.
value
;
hint_el
.
value
=
''
;
...
...
src/converse-otr.js
View file @
20706cb6
...
...
@@ -283,23 +283,29 @@
return
stanza
;
},
onMessageSubmitted
(
text
)
{
parseMessageForCommands
(
text
)
{
const
{
_converse
}
=
this
.
__super__
;
if
(
!
_converse
.
connection
.
authenticated
)
{
return
this
.
showHelpMessages
(
[
'
Sorry, the connection has been lost,
'
+
'
and your message could not be sent
'
],
'
error
'
);
}
const
match
=
text
.
replace
(
/^
\s
*/
,
""
).
match
(
/^
\/(
.*
)\s
*$/
);
if
(
match
)
{
if
((
_converse
.
allow_otr
)
&&
(
match
[
1
]
===
"
endotr
"
))
{
return
this
.
endOTR
();
this
.
endOTR
();
return
true
;
}
else
if
((
_converse
.
allow_otr
)
&&
(
match
[
1
]
===
"
otr
"
))
{
return
this
.
model
.
initiateOTR
();
this
.
model
.
initiateOTR
();
return
true
;
}
}
return
this
.
__super__
.
parseMessageForCommands
.
apply
(
this
,
arguments
);
},
onMessageSubmitted
(
text
,
spoiler_hint
)
{
const
{
_converse
}
=
this
.
__super__
;
if
(
!
_converse
.
connection
.
authenticated
)
{
this
.
__super__
.
onMessageSubmitted
.
apply
(
this
,
arguments
);
}
if
(
this
.
parseMessageForCommands
(
text
))
{
return
;
}
if
(
_
.
includes
([
UNVERIFIED
,
VERIFIED
],
this
.
model
.
get
(
'
otr_status
'
)))
{
// Off-the-record encryption is active
this
.
model
.
otr
.
sendMsg
(
text
);
...
...
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