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
035f5d68
Commit
035f5d68
authored
Dec 08, 2016
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for how the affiliations delta is computed.
parent
e0b1d1d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
spec/chatroom.js
spec/chatroom.js
+60
-0
No files found.
spec/chatroom.js
View file @
035f5d68
...
...
@@ -1601,5 +1601,65 @@
);
}));
});
describe
(
"
The affiliations delta
"
,
function
()
{
it
(
"
can be computed in various ways
"
,
mock
.
initConverse
(
function
(
converse
)
{
test_utils
.
openChatRoom
(
converse
,
'
coven
'
,
'
chat.shakespeare.lit
'
,
'
dummy
'
);
var
roomview
=
converse
.
chatboxviews
.
get
(
'
coven@chat.shakespeare.lit
'
);
var
exclude_existing
=
false
;
var
remove_absentees
=
false
;
var
new_list
=
[];
var
old_list
=
[];
var
delta
=
roomview
.
computeAffiliationsDelta
(
exclude_existing
,
remove_absentees
,
new_list
,
old_list
);
expect
(
delta
.
length
).
toBe
(
0
);
new_list
=
[{
'
jid
'
:
'
wiccarocks@shakespeare.lit
'
,
'
affiliation
'
:
'
member
'
}];
old_list
=
[{
'
jid
'
:
'
wiccarocks@shakespeare.lit
'
,
'
affiliation
'
:
'
member
'
}];
delta
=
roomview
.
computeAffiliationsDelta
(
exclude_existing
,
remove_absentees
,
new_list
,
old_list
);
expect
(
delta
.
length
).
toBe
(
0
);
// When remove_absentees is false, then affiliations in the old
// list which are not in the new one won't be removed.
old_list
=
[{
'
jid
'
:
'
oldhag666@shakespeare.lit
'
,
'
affiliation
'
:
'
owner
'
},
{
'
jid
'
:
'
wiccarocks@shakespeare.lit
'
,
'
affiliation
'
:
'
member
'
}];
delta
=
roomview
.
computeAffiliationsDelta
(
exclude_existing
,
remove_absentees
,
new_list
,
old_list
);
expect
(
delta
.
length
).
toBe
(
0
);
// With exclude_existing set to false, any changed affiliations
// will be included in the delta (i.e. existing affiliations
// are included in the comparison).
old_list
=
[{
'
jid
'
:
'
wiccarocks@shakespeare.lit
'
,
'
affiliation
'
:
'
owner
'
}];
delta
=
roomview
.
computeAffiliationsDelta
(
exclude_existing
,
remove_absentees
,
new_list
,
old_list
);
expect
(
delta
.
length
).
toBe
(
1
);
expect
(
delta
[
0
].
jid
).
toBe
(
'
wiccarocks@shakespeare.lit
'
);
expect
(
delta
[
0
].
affiliation
).
toBe
(
'
member
'
);
// To also remove affiliations from the old list which are not
// in the new list, we set remove_absentees to true
remove_absentees
=
true
;
old_list
=
[{
'
jid
'
:
'
oldhag666@shakespeare.lit
'
,
'
affiliation
'
:
'
owner
'
},
{
'
jid
'
:
'
wiccarocks@shakespeare.lit
'
,
'
affiliation
'
:
'
member
'
}];
delta
=
roomview
.
computeAffiliationsDelta
(
exclude_existing
,
remove_absentees
,
new_list
,
old_list
);
expect
(
delta
.
length
).
toBe
(
1
);
expect
(
delta
[
0
].
jid
).
toBe
(
'
oldhag666@shakespeare.lit
'
);
expect
(
delta
[
0
].
affiliation
).
toBe
(
'
none
'
);
delta
=
roomview
.
computeAffiliationsDelta
(
exclude_existing
,
remove_absentees
,
[],
old_list
);
expect
(
delta
.
length
).
toBe
(
2
);
expect
(
delta
[
0
].
jid
).
toBe
(
'
oldhag666@shakespeare.lit
'
);
expect
(
delta
[
0
].
affiliation
).
toBe
(
'
none
'
);
expect
(
delta
[
1
].
jid
).
toBe
(
'
wiccarocks@shakespeare.lit
'
);
expect
(
delta
[
1
].
affiliation
).
toBe
(
'
none
'
);
// To only add a user if they don't already have an
// affiliation, we set 'exclude_existing' to true
exclude_existing
=
true
;
old_list
=
[{
'
jid
'
:
'
wiccarocks@shakespeare.lit
'
,
'
affiliation
'
:
'
owner
'
}];
delta
=
roomview
.
computeAffiliationsDelta
(
exclude_existing
,
remove_absentees
,
new_list
,
old_list
);
expect
(
delta
.
length
).
toBe
(
0
);
}));
});
});
}));
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