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
d1bf5b84
Commit
d1bf5b84
authored
Dec 16, 2013
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add event emitter tests for chatrooms. Updates #48
parent
603087c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
10 deletions
+43
-10
converse.js
converse.js
+12
-7
spec/ChatRoomSpec.js
spec/ChatRoomSpec.js
+29
-2
tests/mock.js
tests/mock.js
+2
-1
No files found.
converse.js
View file @
d1bf5b84
...
...
@@ -942,7 +942,6 @@
},
sendMessage
:
function
(
text
)
{
converse
.
emit
(
'
onMessageSend
'
,
text
);
var
match
=
text
.
replace
(
/^
\s
*/
,
""
).
match
(
/^
\/(
.*
)\s
*$/
),
msgs
;
if
(
match
)
{
if
(
match
[
1
]
===
"
clear
"
)
{
...
...
@@ -995,6 +994,7 @@
}
else
{
this
.
sendMessage
(
message
);
}
converse
.
emit
(
'
onMessageSend
'
,
message
);
}
this
.
$el
.
data
(
'
composing
'
,
false
);
}
else
if
(
!
this
.
model
.
get
(
'
chatroom
'
))
{
...
...
@@ -2241,12 +2241,17 @@
}));
}
if
(
!
body
)
{
return
true
;
}
this
.
showMessage
(
$chat_content
,
{
'
message
'
:
body
,
'
sender
'
:
sender
===
this
.
model
.
get
(
'
nick
'
)
&&
'
me
'
||
'
room
'
,
'
fullname
'
:
sender
,
'
time
'
:
converse
.
toISOString
(
message_datetime
)
});
var
display_sender
=
sender
===
this
.
model
.
get
(
'
nick
'
)
&&
'
me
'
||
'
room
'
;
this
.
showMessage
(
$chat_content
,
{
'
message
'
:
body
,
'
sender
'
:
display_sender
,
'
fullname
'
:
sender
,
'
time
'
:
converse
.
toISOString
(
message_datetime
)
});
if
(
display_sender
===
'
room
'
)
{
// We only emit an event if it's not our own message
converse
.
emit
(
'
onMessage
'
,
message
);
}
return
true
;
},
...
...
spec/ChatRoomSpec.js
View file @
d1bf5b84
...
...
@@ -18,7 +18,6 @@
var
chatroomview
=
this
.
chatboxesview
.
views
[
'
lounge@muc.localhost
'
],
$participant_list
;
var
roster
=
{},
room
=
{},
i
;
for
(
i
=
0
;
i
<
mock
.
chatroom_names
.
length
-
1
;
i
++
)
{
roster
[
mock
.
chatroom_names
[
i
]]
=
{};
chatroomview
.
onChatRoomRoster
(
roster
,
room
);
...
...
@@ -43,7 +42,8 @@
expect
(
$
(
occupant
).
attr
(
'
title
'
)).
toBe
(
'
This user is a moderator
'
);
},
converse
));
it
(
"
shows received and sent groupchat messages
"
,
$
.
proxy
(
function
()
{
it
(
"
shows received groupchat messages
"
,
$
.
proxy
(
function
()
{
spyOn
(
converse
,
'
emit
'
);
var
view
=
this
.
chatboxesview
.
views
[
'
lounge@muc.localhost
'
];
if
(
!
view
.
$el
.
find
(
'
.chat-area
'
).
length
)
{
view
.
renderChatArea
();
}
var
nick
=
mock
.
chatroom_names
[
0
];
...
...
@@ -58,6 +58,31 @@
var
$chat_content
=
view
.
$el
.
find
(
'
.chat-content
'
);
expect
(
$chat_content
.
find
(
'
.chat-message
'
).
length
).
toBe
(
1
);
expect
(
$chat_content
.
find
(
'
.chat-message-content
'
).
text
()).
toBe
(
text
);
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
onMessage
'
,
message
.
nodeTree
);
},
converse
));
it
(
"
shows sent groupchat messages
"
,
$
.
proxy
(
function
()
{
spyOn
(
converse
,
'
emit
'
);
var
view
=
this
.
chatboxesview
.
views
[
'
lounge@muc.localhost
'
];
if
(
!
view
.
$el
.
find
(
'
.chat-area
'
).
length
)
{
view
.
renderChatArea
();
}
var
nick
=
mock
.
chatroom_names
[
0
];
var
text
=
'
This is a sent message
'
;
view
.
$el
.
find
(
'
.chat-textarea
'
).
text
(
text
);
view
.
$el
.
find
(
'
textarea.chat-textarea
'
).
trigger
(
$
.
Event
(
'
keypress
'
,
{
keyCode
:
13
}));
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
onMessageSend
'
,
text
);
var
message
=
$msg
({
from
:
'
lounge@muc.localhost/dummy
'
,
id
:
'
2
'
,
to
:
'
dummy@localhost.com
'
,
type
:
'
groupchat
'
}).
c
(
'
body
'
).
t
(
text
);
view
.
onChatRoomMessage
(
message
.
nodeTree
);
var
$chat_content
=
view
.
$el
.
find
(
'
.chat-content
'
);
expect
(
$chat_content
.
find
(
'
.chat-message
'
).
length
).
toBe
(
1
);
expect
(
$chat_content
.
find
(
'
.chat-message-content
'
).
last
().
text
()).
toBe
(
text
);
// We don't emit an event if it's our own message
expect
(
converse
.
emit
.
callCount
,
1
);
},
converse
));
it
(
"
can be saved to, and retrieved from, localStorage
"
,
$
.
proxy
(
function
()
{
...
...
@@ -83,11 +108,13 @@
it
(
"
can be closed again by clicking a DOM element with class 'close-chatbox-button'
"
,
$
.
proxy
(
function
()
{
var
view
=
this
.
chatboxesview
.
views
[
'
lounge@muc.localhost
'
],
chatroom
=
view
.
model
,
$el
;
spyOn
(
view
,
'
closeChat
'
).
andCallThrough
();
spyOn
(
converse
,
'
emit
'
);
spyOn
(
converse
.
connection
.
muc
,
'
leave
'
);
view
.
delegateEvents
();
// We need to rebind all events otherwise our spy won't be called
view
.
$el
.
find
(
'
.close-chatbox-button
'
).
click
();
expect
(
view
.
closeChat
).
toHaveBeenCalled
();
expect
(
converse
.
connection
.
muc
.
leave
).
toHaveBeenCalled
();
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
onChatBoxClosed
'
,
jasmine
.
any
(
Object
));
},
converse
));
},
converse
));
...
...
tests/mock.js
View file @
d1bf5b84
...
...
@@ -34,7 +34,8 @@
'
listRooms
'
:
function
()
{},
'
join
'
:
function
()
{},
'
leave
'
:
function
()
{},
'
rooms
'
:
{}
'
rooms
'
:
{},
'
groupchat
'
:
function
()
{}
},
'
service
'
:
'
jasmine tests
'
,
'
jid
'
:
'
dummy@localhost
'
,
...
...
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