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
cacba4e6
Commit
cacba4e6
authored
Dec 22, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for contacts changing their `groups`
and fix the resulting fallout
parent
f36b069e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
15 deletions
+62
-15
spec/roster.js
spec/roster.js
+47
-1
src/converse-rosterview.js
src/converse-rosterview.js
+15
-14
No files found.
spec/roster.js
View file @
cacba4e6
...
...
@@ -358,6 +358,52 @@
});
}));
it
(
"
gets created when a contact's
\"
groups
\"
attribute changes
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
_converse
.
roster_groups
=
true
;
spyOn
(
_converse
,
'
emit
'
);
spyOn
(
_converse
.
rosterview
,
'
update
'
).
and
.
callThrough
();
_converse
.
rosterview
.
render
();
test_utils
.
openControlBox
();
_converse
.
roster
.
create
({
jid
:
'
groupchanger@localhost
'
,
subscription
:
'
both
'
,
ask
:
null
,
groups
:
[
'
firstgroup
'
],
fullname
:
'
George Groupchanger
'
});
// Check that the groups appear alphabetically and that
// requesting and pending contacts are last.
test_utils
.
waitUntil
(
function
()
{
return
_converse
.
rosterview
.
$el
.
find
(
'
.roster-group:visible a.group-toggle
'
).
length
;
},
500
).
then
(
function
()
{
var
group_titles
=
$
.
map
(
_converse
.
rosterview
.
$el
.
find
(
'
.roster-group:visible a.group-toggle
'
),
function
(
o
)
{
return
$
(
o
).
text
().
trim
();
}
);
expect
(
group_titles
).
toEqual
([
'
firstgroup
'
]);
var
contact
=
_converse
.
roster
.
get
(
'
groupchanger@localhost
'
);
contact
.
set
({
'
groups
'
:
[
'
secondgroup
'
]});
return
test_utils
.
waitUntil
(
function
()
{
return
_converse
.
rosterview
.
$el
.
find
(
'
.roster-group[data-group="secondgroup"]:visible a.group-toggle
'
).
length
;
},
500
);
}).
then
(
function
()
{
var
group_titles
=
$
.
map
(
_converse
.
rosterview
.
$el
.
find
(
'
.roster-group:visible a.group-toggle
'
),
function
(
o
)
{
return
$
(
o
).
text
().
trim
();
}
);
expect
(
group_titles
).
toEqual
([
'
secondgroup
'
]);
done
();
});
}));
it
(
"
can share contacts with other roster groups
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
...
...
@@ -767,7 +813,7 @@
expect
(
window
.
confirm
).
toHaveBeenCalled
();
expect
(
_converse
.
connection
.
sendIQ
).
toHaveBeenCalled
();
expect
(
contact
.
removeFromRoster
).
toHaveBeenCalled
();
expect
(
_converse
.
rosterview
.
$el
.
find
(
'
.roster-group
'
).
css
(
'
display
'
)).
toEqual
(
'
none
'
);
expect
(
_converse
.
rosterview
.
$el
.
find
(
'
.roster-group
'
).
length
).
toEqual
(
0
);
done
();
});
}));
...
...
src/converse-rosterview.js
View file @
cacba4e6
...
...
@@ -451,7 +451,6 @@
Backbone
.
OrderedListView
.
prototype
.
initialize
.
apply
(
this
,
arguments
);
this
.
model
.
contacts
.
on
(
"
change:subscription
"
,
this
.
onContactSubscriptionChange
,
this
);
this
.
model
.
contacts
.
on
(
"
change:requesting
"
,
this
.
onContactRequestChange
,
this
);
this
.
model
.
contacts
.
on
(
"
destroy
"
,
this
.
onRemove
,
this
);
this
.
model
.
contacts
.
on
(
"
remove
"
,
this
.
onRemove
,
this
);
_converse
.
roster
.
on
(
'
change:groups
'
,
this
.
onContactGroupChange
,
this
);
...
...
@@ -583,36 +582,37 @@
const
cid
=
contact
.
get
(
'
id
'
);
const
in_this_overview
=
!
this
.
get
(
cid
);
if
(
in_this_group
&&
!
in_this_overview
)
{
this
.
model
.
contacts
.
remove
(
cid
);
}
else
if
(
!
in_this_group
&&
in_this_overview
)
{
this
.
items
.
trigger
(
'
add
'
,
contact
);
}
else
if
(
!
in_this_group
)
{
this
.
removeContact
(
contact
);
}
},
onContactSubscriptionChange
(
contact
)
{
if
((
this
.
model
.
get
(
'
name
'
)
===
HEADER_PENDING_CONTACTS
)
&&
contact
.
get
(
'
subscription
'
)
!==
'
from
'
)
{
this
.
model
.
contacts
.
remove
(
contact
.
get
(
'
id
'
)
);
this
.
removeContact
(
contact
);
}
},
onContactRequestChange
(
contact
)
{
if
((
this
.
model
.
get
(
'
name
'
)
===
HEADER_REQUESTING_CONTACTS
)
&&
!
contact
.
get
(
'
requesting
'
))
{
/* We suppress events, otherwise the remove event will
* also cause the contact's view to be removed from the
* "Pending Contacts" group.
*/
this
.
model
.
contacts
.
remove
(
contact
.
get
(
'
id
'
),
{
'
silent
'
:
true
});
// Since we suppress events, we make sure the view and
// contact are removed from this group.
this
.
get
(
contact
.
get
(
'
id
'
)).
remove
();
this
.
onRemove
(
contact
);
this
.
removeContact
(
contact
);
}
},
removeContact
(
contact
)
{
// We suppress events, otherwise the remove event will
// also cause the contact's view to be removed from the
// "Pending Contacts" group.
this
.
model
.
contacts
.
remove
(
contact
,
{
'
silent
'
:
true
});
this
.
onRemove
(
contact
);
},
onRemove
(
contact
)
{
this
.
get
(
contact
.
get
(
'
id
'
)).
remove
();
this
.
remove
(
contact
.
get
(
'
id
'
));
if
(
this
.
model
.
contacts
.
length
===
0
)
{
u
.
hideElement
(
this
.
el
);
this
.
el
.
parentElement
.
removeChild
(
this
.
el
);
}
}
});
...
...
@@ -632,6 +632,7 @@
Backbone
.
OrderedListView
.
prototype
.
initialize
.
apply
(
this
,
arguments
);
_converse
.
roster
.
on
(
"
add
"
,
this
.
onContactAdded
,
this
);
_converse
.
roster
.
on
(
'
change:groups
'
,
this
.
onContactAdded
,
this
);
_converse
.
roster
.
on
(
'
change
'
,
this
.
onContactChange
,
this
);
_converse
.
roster
.
on
(
"
destroy
"
,
this
.
update
,
this
);
_converse
.
roster
.
on
(
"
remove
"
,
this
.
update
,
this
);
...
...
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