Unverified Commit 266f85b8 authored by Hannah Stepanek's avatar Hannah Stepanek Committed by GitHub

Merge pull request #1106 from hypothesis/fix-dup-group

Fix bug where direct linked group is duplicated
parents e25c5101 a57a0e69
...@@ -213,9 +213,11 @@ function groups( ...@@ -213,9 +213,11 @@ function groups(
} }
return Promise.all(groupApiRequests).then( return Promise.all(groupApiRequests).then(
([myGroups, featuredGroups, token, selectedGroup]) => [ ([myGroups, featuredGroups, token, selectedGroup]) => [
// Don't add the selectedGroup if it's already in the featuredGroups.
combineGroups( combineGroups(
myGroups, myGroups,
selectedGroup !== undefined selectedGroup !== undefined &&
!featuredGroups.some(g => g.id === selectedGroup.id)
? featuredGroups.concat([selectedGroup]) ? featuredGroups.concat([selectedGroup])
: featuredGroups, : featuredGroups,
documentUri documentUri
......
...@@ -230,6 +230,25 @@ describe('groups', function() { ...@@ -230,6 +230,25 @@ describe('groups', function() {
}); });
}); });
// TODO: Add a de-dup test for the direct-linked annotation.
it('does not duplicate groups if the direct-linked group is also a featured group', () => {
const svc = service();
// Set the direct-linked group to dummyGroups[0].
fakeSettings.group = dummyGroups[0].id;
fakeApi.group.read.returns(Promise.resolve(dummyGroups[0]));
// Include the dummyGroups[0] in the featured groups.
fakeApi.profile.groups.read.returns(Promise.resolve([]));
fakeApi.groups.list.returns(Promise.resolve([dummyGroups[0]]));
return svc.load().then(groups => {
const groupIds = groups.map(g => g.id);
assert.deepEqual(groupIds, [fakeSettings.group]);
});
});
it('combines groups from all 3 endpoints if there is a selectedGroup', () => { it('combines groups from all 3 endpoints if there is a selectedGroup', () => {
const svc = service(); const svc = service();
......
...@@ -5,11 +5,11 @@ const escapeStringRegexp = require('escape-string-regexp'); ...@@ -5,11 +5,11 @@ const escapeStringRegexp = require('escape-string-regexp');
/** /**
* Combine groups from multiple api calls together to form a unique list of groups. * Combine groups from multiple api calls together to form a unique list of groups.
* Add an isMember property to each group indicating whether the logged in user is a member. * Add an isMember property to each group indicating whether the logged in user is a member.
* Add an isScopedToUri property to each group indicating whether the group can be annotated * Add an isScopedToUri property to each group indicating whether the uri matches the group's
* in based on group scoping and the uri of the current page. * uri patterns. If no uri patterns are specified, defaults to True.
* *
* @param {Group[]} userGroups - groups the user is a member of * @param {Group[]} userGroups - groups the user is a member of
* @param {Group[]} featuredGroups - groups scoped to the particular uri, authority, and user * @param {Group[]} featuredGroups - all other groups, may include some duplicates from the userGroups
* @param {string} uri - uri of the current page * @param {string} uri - uri of the current page
*/ */
function combineGroups(userGroups, featuredGroups, uri) { function combineGroups(userGroups, featuredGroups, uri) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment