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
6c31f764
Commit
6c31f764
authored
Mar 01, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor other tests. All tests pass now again. updates #307
parent
40535105
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
24 deletions
+58
-24
converse.js
converse.js
+5
-4
spec/chatroom.js
spec/chatroom.js
+44
-20
tests/mock.js
tests/mock.js
+9
-0
No files found.
converse.js
View file @
6c31f764
...
...
@@ -2523,9 +2523,10 @@
},
leave
:
function
(
exit_msg
)
{
var
presenceid
=
converse
.
connection
.
getUniqueId
();
var
presence
=
$pres
({
type
:
"
unavailable
"
,
id
:
converse
.
connection
.
getUniqueId
()
,
id
:
presenceid
,
from
:
converse
.
connection
.
jid
,
to
:
this
.
getRoomJID
()
});
...
...
@@ -2772,10 +2773,10 @@
return
this
.
scrollDown
();
},
showErrorMessage
:
function
(
$error
,
room
)
{
showErrorMessage
:
function
(
$error
)
{
// We didn't enter the room, so we must remove it from the MUC
// add-on
delete
converse
.
connection
.
muc
[
room
.
name
];
delete
converse
.
connection
.
muc
[
this
.
model
.
get
(
'
jid
'
)];
// XXX: Still needed?
if
(
$error
.
attr
(
'
type
'
)
==
'
auth
'
)
{
if
(
$error
.
find
(
'
not-authorized
'
).
length
)
{
this
.
renderPasswordForm
();
...
...
@@ -2810,7 +2811,7 @@
var
nick
=
this
.
model
.
get
(
'
nick
'
);
if
(
$presence
.
attr
(
'
type
'
)
===
'
error
'
)
{
this
.
model
.
set
(
'
connected
'
,
false
);
this
.
showErrorMessage
(
$presence
.
find
(
'
error
'
)
,
room
);
this
.
showErrorMessage
(
$presence
.
find
(
'
error
'
));
}
else
{
is_self
=
(
$presence
.
find
(
"
status[code='110']
"
).
length
)
||
(
$presence
.
attr
(
'
from
'
)
==
this
.
model
.
get
(
'
id
'
)
+
'
/
'
+
Strophe
.
escapeNode
(
nick
));
...
...
spec/chatroom.js
View file @
6c31f764
...
...
@@ -23,30 +23,54 @@
it
(
"
shows users currently present in the room
"
,
$
.
proxy
(
function
()
{
test_utils
.
openChatRoom
(
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
var
chatroomview
=
this
.
chatboxviews
.
get
(
'
lounge@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
);
$participant_list
=
chatroomview
.
$el
.
find
(
'
.participant-list
'
);
expect
(
$participant_list
.
find
(
'
li
'
).
length
).
toBe
(
1
+
i
);
expect
(
$
(
$participant_list
.
find
(
'
li
'
)[
i
]).
text
()).
toBe
(
mock
.
chatroom_names
[
i
]);
var
name
;
var
view
=
this
.
chatboxviews
.
get
(
'
lounge@localhost
'
),
$participants
=
view
.
$
(
'
.participant-list
'
);
spyOn
(
view
,
'
onChatRoomPresence
'
).
andCallThrough
();
var
room
=
{},
i
,
role
;
for
(
i
=
0
;
i
<
mock
.
chatroom_names
.
length
;
i
++
)
{
name
=
mock
.
chatroom_names
[
i
];
console
.
log
(
name
);
role
=
mock
.
chatroom_roles
[
name
].
role
;
// See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
var
presence
=
$pres
({
to
:
'
dummy@localhost/pda
'
,
from
:
'
lounge@localhost/
'
+
name
}).
c
(
'
x
'
).
attrs
({
xmlns
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
item
'
).
attrs
({
affiliation
:
mock
.
chatroom_roles
[
name
].
affiliation
,
jid
:
'
dummy@localhost/pda
'
,
role
:
role
}).
up
()
.
c
(
'
status
'
).
attrs
({
code
:
'
110
'
}).
nodeTree
;
this
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
presence
));
expect
(
view
.
onChatRoomPresence
).
toHaveBeenCalled
();
expect
(
$participants
.
find
(
'
li
'
).
length
).
toBe
(
1
+
i
);
expect
(
$
(
$participants
.
find
(
'
li
'
)[
i
]).
text
()).
toBe
(
mock
.
chatroom_names
[
i
]);
expect
(
$
(
$participants
.
find
(
'
li
'
)[
i
]).
hasClass
(
'
moderator
'
)).
toBe
(
role
===
"
moderator
"
);
}
roster
[
converse
.
bare_jid
]
=
{};
chatroomview
.
onChatRoomRoster
(
roster
,
room
);
},
converse
));
it
(
"
indicates moderators by means of a special css class and tooltip
"
,
$
.
proxy
(
function
()
{
test_utils
.
openChatRoom
(
'
lounge
'
,
'
localhost
'
,
'
dummy
'
);
var
chatroomview
=
this
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
var
roster
=
{},
idx
=
mock
.
chatroom_names
.
length
-
1
;
roster
[
mock
.
chatroom_names
[
idx
]]
=
{};
roster
[
mock
.
chatroom_names
[
idx
]].
role
=
'
moderator
'
;
chatroomview
.
onChatRoomRoster
(
roster
,
{});
var
occupant
=
chatroomview
.
$el
.
find
(
'
.participant-list
'
).
find
(
'
li
'
);
var
view
=
this
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
var
presence
=
$pres
({
to
:
'
dummy@localhost/pda
'
,
from
:
'
lounge@localhost/moderatorman
'
}).
c
(
'
x
'
).
attrs
({
xmlns
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
item
'
).
attrs
({
affiliation
:
'
admin
'
,
jid
:
'
dummy@localhost/pda
'
,
role
:
'
moderator
'
,
}).
up
()
.
c
(
'
status
'
).
attrs
({
code
:
'
110
'
}).
nodeTree
;
this
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
presence
));
var
occupant
=
view
.
$el
.
find
(
'
.participant-list
'
).
find
(
'
li
'
);
expect
(
occupant
.
length
).
toBe
(
1
);
expect
(
$
(
occupant
).
text
()).
toBe
(
mock
.
chatroom_names
[
idx
]
);
expect
(
$
(
occupant
).
text
()).
toBe
(
"
moderatorman
"
);
expect
(
$
(
occupant
).
attr
(
'
class
'
)).
toBe
(
'
moderator
'
);
expect
(
$
(
occupant
).
attr
(
'
title
'
)).
toBe
(
'
This user is a moderator
'
);
},
converse
));
...
...
@@ -371,7 +395,7 @@
var
view
=
this
.
chatboxviews
.
get
(
'
lounge@localhost
'
),
chatroom
=
view
.
model
,
$el
;
spyOn
(
view
,
'
close
'
).
andCallThrough
();
spyOn
(
converse
,
'
emit
'
);
spyOn
(
converse
.
connection
.
muc
,
'
leave
'
);
spyOn
(
view
,
'
leave
'
);
view
.
delegateEvents
();
// We need to rebind all events otherwise our spy won't be called
runs
(
function
()
{
view
.
$el
.
find
(
'
.close-chatbox-button
'
).
click
();
...
...
@@ -379,7 +403,7 @@
waits
(
50
);
runs
(
function
()
{
expect
(
view
.
close
).
toHaveBeenCalled
();
expect
(
this
.
connection
.
muc
.
leave
).
toHaveBeenCalled
();
expect
(
view
.
leave
).
toHaveBeenCalled
();
expect
(
this
.
emit
).
toHaveBeenCalledWith
(
'
chatBoxClosed
'
,
jasmine
.
any
(
Object
));
}.
bind
(
converse
));
},
converse
));
...
...
tests/mock.js
View file @
6c31f764
...
...
@@ -33,6 +33,15 @@
mock
.
chatroom_names
=
[
'
Dyon van de Wege
'
,
'
Thomas Kalb
'
,
'
Dirk Theissen
'
,
'
Felix Hofmann
'
,
'
Ka Lek
'
,
'
Anne Ebersbacher
'
];
// TODO: need to also test other roles and affiliations
mock
.
chatroom_roles
=
{
'
Anne Ebersbacher
'
:
{
affiliation
:
"
owner
"
,
role
:
"
moderator
"
},
'
Dirk Theissen
'
:
{
affiliation
:
"
admin
"
,
role
:
"
moderator
"
},
'
Dyon van de Wege
'
:
{
affiliation
:
"
member
"
,
role
:
"
participant
"
},
'
Felix Hofmann
'
:
{
affiliation
:
"
member
"
,
role
:
"
participant
"
},
'
Ka Lek
'
:
{
affiliation
:
"
member
"
,
role
:
"
participant
"
},
'
Thomas Kalb
'
:
{
affiliation
:
"
member
"
,
role
:
"
participant
"
}
};
mock
.
event
=
{
'
preventDefault
'
:
function
()
{}
...
...
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