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
0edc5710
Commit
0edc5710
authored
Dec 08, 2012
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec dir with jasmine.js test for ClientStorage
parent
1cdf82c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
125 additions
and
0 deletions
+125
-0
spec/StorageSpec.js
spec/StorageSpec.js
+125
-0
No files found.
spec/StorageSpec.js
0 → 100644
View file @
0edc5710
(
function
(
root
,
factory
)
{
define
([
"
converse
"
],
function
(
xmppchat
)
{
return
factory
(
xmppchat
);
}
);
}
(
this
,
function
(
xmppchat
)
{
String
.
prototype
.
repeat
=
function
(
times
)
{
return
(
new
Array
(
times
+
1
)).
join
(
this
+
'
'
).
replace
(
/
\s
$/
,
''
);
};
return
describe
(
"
xmppchat.ClientStorage
"
,
function
()
{
beforeEach
(
function
()
{
this
.
storage
=
new
xmppchat
.
ClientStorage
(
'
dummy@localhost
'
);
});
describe
(
"
storing open chats
"
,
function
()
{
beforeEach
(
function
()
{
// Removes all stored items
this
.
storage
.
flush
();
});
it
(
"
should by default not have any chats
"
,
function
()
{
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([]);
});
it
(
"
should be able to add chats
"
,
function
()
{
this
.
storage
.
addOpenChat
(
'
chat1@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([
'
chat1@localhost
'
]);
this
.
storage
.
addOpenChat
(
'
chat2@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([
'
chat1@localhost
'
,
'
chat2@localhost
'
]);
this
.
storage
.
addOpenChat
(
'
chat3@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([
'
chat1@localhost
'
,
'
chat2@localhost
'
,
'
chat3@localhost
'
]);
});
it
(
"
should be able to remove chats
"
,
function
()
{
this
.
storage
.
removeOpenChat
(
'
non-existing@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([]);
this
.
storage
.
addOpenChat
(
'
chat1@localhost
'
);
this
.
storage
.
addOpenChat
(
'
chat2@localhost
'
);
this
.
storage
.
addOpenChat
(
'
chat3@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([
'
chat1@localhost
'
,
'
chat2@localhost
'
,
'
chat3@localhost
'
]);
this
.
storage
.
removeOpenChat
(
'
chat2@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([
'
chat1@localhost
'
,
'
chat3@localhost
'
]);
this
.
storage
.
removeOpenChat
(
'
chat1@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([
'
chat3@localhost
'
]);
this
.
storage
.
removeOpenChat
(
'
chat3@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([]);
this
.
storage
.
removeOpenChat
(
'
non-existing@localhost
'
);
expect
(
this
.
storage
.
getOpenChats
()).
toEqual
([]);
});
});
describe
(
"
storing messages
"
,
function
()
{
var
iso_regex
=
/
\d{4}
-
[
01
]\d
-
[
0-3
]\d
T
[
0-2
]\d
:
[
0-5
]\d
:
[
0-5
]\d\.\d
+
([
+-
][
0-2
]\d
:
[
0-5
]\d
|Z
)
/
;
it
(
"
should by default not have any messages
"
,
function
()
{
expect
(
this
.
storage
.
getMessages
(
'
chat@localhost
'
)).
toEqual
([]);
});
it
(
"
should be able to add and retrieve messages
"
,
function
()
{
var
i
,
jid
=
'
chat@localhost
'
;
for
(
i
=
0
;
i
<
10
;
i
++
)
{
var
msg
=
'
msg
'
.
repeat
(
i
+
1
);
this
.
storage
.
addMessage
(
jid
,
msg
,
'
to
'
);
// Check that message is returned
var
msgs
=
this
.
storage
.
getMessages
(
jid
);
expect
(
msgs
.
length
).
toEqual
(
i
+
1
);
expect
(
msgs
[
i
]).
toEqual
(
jasmine
.
any
(
String
));
// First two space separated strings are ISO date and direction
var
msg_arr
=
msgs
[
i
].
split
(
'
'
,
2
);
// Check that first string is ISO format
var
match
=
msg_arr
[
0
].
match
(
iso_regex
);
expect
(
match
).
toBeTruthy
();
expect
(
msg_arr
[
0
]).
toEqual
(
jasmine
.
any
(
String
));
expect
(
msg_arr
[
1
]).
toEqual
(
'
to
'
);
expect
(
msgs
[
i
].
replace
(
/
(
.*
?\s
.*
?\s)
/
,
''
)).
toEqual
(
msg
);
}
});
it
(
"
should be able to get last message
"
,
function
()
{
var
msg
=
this
.
storage
.
getLastMessage
(
'
chat@localhost
'
),
msg_arr
=
msg
.
split
(
'
'
,
2
),
match
=
msg_arr
[
0
].
match
(
iso_regex
);
expect
(
match
).
toBeTruthy
();
expect
(
msg_arr
[
0
]).
toEqual
(
jasmine
.
any
(
String
));
expect
(
msg_arr
[
1
]).
toEqual
(
'
to
'
);
expect
(
msg
.
replace
(
/
(
.*
?\s
.*
?\s)
/
,
''
)).
toEqual
(
'
msg
'
.
repeat
(
10
));
});
it
(
"
should be able to clear all messages
"
,
function
()
{
this
.
storage
.
clearMessages
(
'
chat@localhost
'
);
expect
(
this
.
storage
.
getMessages
(
'
chat@localhost
'
)).
toEqual
([]);
});
it
(
"
should not store more than 30 messages
"
,
function
()
{
var
i
,
msgs
;
for
(
i
=
0
;
i
<
100
;
i
++
)
{
this
.
storage
.
addMessage
(
'
chat@localhost
'
,
'
msg
'
,
'
to
'
);
}
msgs
=
this
.
storage
.
getMessages
(
'
chat@localhost
'
);
expect
(
msgs
.
length
).
toEqual
(
30
);
});
});
});
}));
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