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
13babe4f
Commit
13babe4f
authored
Nov 03, 2013
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored chatbox tests to be run independently
parent
d4fa4310
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
11 deletions
+53
-11
spec/ChatBoxSpec.js
spec/ChatBoxSpec.js
+21
-11
tests/utils.js
tests/utils.js
+29
-0
tests_main.js
tests_main.js
+3
-0
No files found.
spec/ChatBoxSpec.js
View file @
13babe4f
...
@@ -8,22 +8,22 @@
...
@@ -8,22 +8,22 @@
);
);
}
(
this
,
function
(
mock
,
utils
)
{
}
(
this
,
function
(
mock
,
utils
)
{
return
describe
(
"
Chatboxes
"
,
$
.
proxy
(
function
(
mock
,
utils
)
{
return
describe
(
"
Chatboxes
"
,
$
.
proxy
(
function
(
mock
,
utils
)
{
window
.
localStorage
.
clear
();
describe
(
"
A Chatbox
"
,
$
.
proxy
(
function
()
{
describe
(
"
A Chatbox
"
,
$
.
proxy
(
function
()
{
beforeEach
(
$
.
proxy
(
function
()
{
beforeEach
(
function
()
{
//utils.initRoster();
utils
.
closeAllChatBoxes
();
//utils.createCurrentContacts();
utils
.
removeControlBox
();
//utils.closeAllChatBoxes();
converse
.
roster
.
localStorage
.
_clear
();
utils
.
initConverse
();
utils
.
createCurrentContacts
();
utils
.
openControlBox
();
utils
.
openControlBox
();
utils
.
openContactsPanel
();
utils
.
openContactsPanel
();
}
,
converse
)
);
});
it
(
"
is created when you click on a roster item
"
,
$
.
proxy
(
function
()
{
it
(
"
is created when you click on a roster item
"
,
$
.
proxy
(
function
()
{
var
i
,
$el
,
click
,
jid
,
view
;
var
i
,
$el
,
click
,
jid
,
view
;
//
show
ControlBox was called earlier, so the controlbox is
//
open
ControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created.
// visible, but no other chat boxes have been created.
expect
(
this
.
chatboxes
.
length
).
toEqual
(
2
);
expect
(
this
.
chatboxes
.
length
).
toEqual
(
1
);
var
online_contacts
=
this
.
rosterview
.
$el
.
find
(
'
dt#xmpp-contacts
'
).
siblings
(
'
dd.current-xmpp-contact.online
'
).
find
(
'
a.open-chat
'
);
var
online_contacts
=
this
.
rosterview
.
$el
.
find
(
'
dt#xmpp-contacts
'
).
siblings
(
'
dd.current-xmpp-contact.online
'
).
find
(
'
a.open-chat
'
);
for
(
i
=
0
;
i
<
online_contacts
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
online_contacts
.
length
;
i
++
)
{
...
@@ -34,11 +34,14 @@
...
@@ -34,11 +34,14 @@
view
.
delegateEvents
();
// We need to rebind all events otherwise our spy won't be called
view
.
delegateEvents
();
// We need to rebind all events otherwise our spy won't be called
$el
.
click
();
$el
.
click
();
expect
(
view
.
openChat
).
toHaveBeenCalled
();
expect
(
view
.
openChat
).
toHaveBeenCalled
();
expect
(
this
.
chatboxes
.
length
).
toEqual
(
i
+
3
);
expect
(
this
.
chatboxes
.
length
).
toEqual
(
i
+
2
);
}
}
},
converse
));
},
converse
));
it
(
"
can be saved to, and retrieved from, localStorage
"
,
$
.
proxy
(
function
()
{
it
(
"
can be saved to, and retrieved from, localStorage
"
,
$
.
proxy
(
function
()
{
utils
.
closeControlBox
();
// First, we open 6 more chatboxes (controlbox is already open)
utils
.
openChatBoxes
(
6
);
// We instantiate a new ChatBoxes collection, which by default
// We instantiate a new ChatBoxes collection, which by default
// will be empty.
// will be empty.
var
newchatboxes
=
new
this
.
ChatBoxes
();
var
newchatboxes
=
new
this
.
ChatBoxes
();
...
@@ -46,7 +49,7 @@
...
@@ -46,7 +49,7 @@
// The chatboxes will then be fetched from localStorage inside the
// The chatboxes will then be fetched from localStorage inside the
// onConnected method
// onConnected method
newchatboxes
.
onConnected
();
newchatboxes
.
onConnected
();
expect
(
newchatboxes
.
length
).
toEqual
(
7
);
expect
(
newchatboxes
.
length
).
toEqual
(
6
);
// Check that the chatboxes items retrieved from localStorage
// Check that the chatboxes items retrieved from localStorage
// have the same attributes values as the original ones.
// have the same attributes values as the original ones.
attrs
=
[
'
id
'
,
'
box_id
'
,
'
visible
'
];
attrs
=
[
'
id
'
,
'
box_id
'
,
'
visible
'
];
...
@@ -73,6 +76,12 @@
...
@@ -73,6 +76,12 @@
it
(
"
will be removed from localStorage when closed
"
,
$
.
proxy
(
function
()
{
it
(
"
will be removed from localStorage when closed
"
,
$
.
proxy
(
function
()
{
this
.
chatboxes
.
localStorage
.
_clear
();
this
.
chatboxes
.
localStorage
.
_clear
();
utils
.
closeControlBox
();
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
0
);
utils
.
openChatBoxes
(
6
);
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
6
);
utils
.
closeAllChatBoxes
();
expect
(
converse
.
chatboxes
.
length
).
toEqual
(
0
);
var
newchatboxes
=
new
this
.
ChatBoxes
();
var
newchatboxes
=
new
this
.
ChatBoxes
();
expect
(
newchatboxes
.
length
).
toEqual
(
0
);
expect
(
newchatboxes
.
length
).
toEqual
(
0
);
// onConnected will fetch chatboxes in localStorage, but
// onConnected will fetch chatboxes in localStorage, but
...
@@ -131,6 +140,7 @@
...
@@ -131,6 +140,7 @@
it
(
"
can be sent from a chatbox, and will appear inside it
"
,
$
.
proxy
(
function
()
{
it
(
"
can be sent from a chatbox, and will appear inside it
"
,
$
.
proxy
(
function
()
{
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
'
'
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
'
'
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
utils
.
openChatBoxFor
(
contact_jid
);
var
view
=
this
.
chatboxesview
.
views
[
contact_jid
];
var
view
=
this
.
chatboxesview
.
views
[
contact_jid
];
var
message
=
'
This message is sent from this chatbox
'
;
var
message
=
'
This message is sent from this chatbox
'
;
spyOn
(
view
,
'
sendMessage
'
).
andCallThrough
();
spyOn
(
view
,
'
sendMessage
'
).
andCallThrough
();
...
...
tests/utils.js
View file @
13babe4f
...
@@ -30,6 +30,12 @@
...
@@ -30,6 +30,12 @@
return
this
;
return
this
;
};
};
utils
.
initConverse
=
function
()
{
converse
.
chatboxes
=
new
converse
.
ChatBoxes
();
converse
.
chatboxesview
=
new
converse
.
ChatBoxesView
({
model
:
converse
.
chatboxes
});
converse
.
onConnected
();
};
utils
.
initRoster
=
function
()
{
utils
.
initRoster
=
function
()
{
converse
.
roster
.
localStorage
.
_clear
();
converse
.
roster
.
localStorage
.
_clear
();
converse
.
initRoster
();
converse
.
initRoster
();
...
@@ -42,6 +48,17 @@
...
@@ -42,6 +48,17 @@
return
this
;
return
this
;
};
};
utils
.
closeControlBox
=
function
()
{
if
(
$
(
"
#controlbox
"
).
is
(
'
:visible
'
))
{
$
(
'
.toggle-online-users
'
).
click
();
}
return
this
;
};
utils
.
removeControlBox
=
function
()
{
$
(
'
#controlbox
'
).
remove
();
};
utils
.
openContactsPanel
=
function
()
{
utils
.
openContactsPanel
=
function
()
{
var
cbview
=
converse
.
chatboxesview
.
views
.
controlbox
;
var
cbview
=
converse
.
chatboxesview
.
views
.
controlbox
;
var
$tabs
=
cbview
.
$el
.
find
(
'
#controlbox-tabs
'
);
var
$tabs
=
cbview
.
$el
.
find
(
'
#controlbox-tabs
'
);
...
@@ -54,6 +71,18 @@
...
@@ -54,6 +71,18 @@
$tabs
.
find
(
'
li
'
).
last
().
find
(
'
a
'
).
click
();
$tabs
.
find
(
'
li
'
).
last
().
find
(
'
a
'
).
click
();
};
};
utils
.
openChatBoxes
=
function
(
amount
)
{
var
i
=
0
,
jid
;
for
(
i
;
i
<
amount
;
i
++
)
{
jid
=
mock
.
cur_names
[
i
].
replace
(
'
'
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
converse
.
rosterview
.
rosteritemviews
[
jid
].
openChat
(
mock
.
event
);
}
};
utils
.
openChatBoxFor
=
function
(
jid
)
{
converse
.
rosterview
.
rosteritemviews
[
jid
].
openChat
(
mock
.
event
);
};
utils
.
createCurrentContacts
=
function
()
{
utils
.
createCurrentContacts
=
function
()
{
// Create current (as opposed to requesting or pending) contacts
// Create current (as opposed to requesting or pending) contacts
// for the user's roster.
// for the user's roster.
...
...
tests_main.js
View file @
13babe4f
...
@@ -106,6 +106,9 @@ require([
...
@@ -106,6 +106,9 @@ require([
"
spec/ChatBoxSpec
"
,
"
spec/ChatBoxSpec
"
,
"
spec/ChatRoomSpec
"
"
spec/ChatRoomSpec
"
],
function
()
{
],
function
()
{
// Make sure this callback is only called once.
delete
converse
.
callback
;
// Jasmine stuff
// Jasmine stuff
var
jasmineEnv
=
jasmine
.
getEnv
();
var
jasmineEnv
=
jasmine
.
getEnv
();
if
(
/PhantomJS/
.
test
(
navigator
.
userAgent
))
{
if
(
/PhantomJS/
.
test
(
navigator
.
userAgent
))
{
...
...
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