Commit 9e34daac authored by Hannah Stepanek's avatar Hannah Stepanek

Cleanup list-group tests

- Add group const which will be used in the current and new tests.
- Remove group links and reference the links through the new group
  const instead.
- Fix incorrect usage of groups and overriding of `fakeGroups.all`:
  `groups` is a const defined for all tests but some tests where
  making a new groups const or overriding the `fakeGroups.all` when
  they should have overridden the value of the `groups` const.
parent deed240c
...@@ -10,9 +10,65 @@ const groupFixtures = require('../../test/group-fixtures'); ...@@ -10,9 +10,65 @@ const groupFixtures = require('../../test/group-fixtures');
describe('groupList', function() { describe('groupList', function() {
let $window; let $window;
const PRIVATE_GROUP_LINK = 'https://hypothes.is/groups/hdevs'; const PRIVATE_GROUP = {
const OPEN_GROUP_LINK = 'https://hypothes.is/groups/pub'; id: 'private',
const RESTRICTED_GROUP_LINK = 'https://hypothes.is/groups/restricto'; links: {
html: 'https://hypothes.is/groups/hdevs',
},
name: 'Private',
organization: groupFixtures.defaultOrganization(),
type: 'private',
isMember: true,
isScopedToUri: true,
};
const RESTRICTED_GROUP = {
id: 'restricted',
links: {
html: 'https://hypothes.is/groups/restricto',
},
name: 'Restricted',
organization: groupFixtures.defaultOrganization(),
type: 'restricted',
isMember: false,
isScopedToUri: true,
};
const RESTRICTED_UNSCOPED_GROUP = {
id: 'restricted',
links: {
html: 'https://hypothes.is/groups/restricto',
},
name: 'Restricted',
organization: groupFixtures.defaultOrganization(),
type: 'restricted',
isMember: false,
isScopedToUri: false,
};
const OPEN_GROUP = {
id: 'open',
links: {
html: 'https://hypothes.is/groups/pub',
},
name: 'Open',
organization: groupFixtures.defaultOrganization(),
type: 'open',
isMember: false,
isScopedToUri: true,
};
const PUBLIC_GROUP = {
id: '__world__',
links: {
html: 'https://hypothes.is/groups/__world__/public',
},
name: 'Public',
organization: groupFixtures.defaultOrganization(),
type: 'open',
isMember: true,
isScopedToUri: true,
};
let groups; let groups;
let fakeGroups; let fakeGroups;
...@@ -55,35 +111,7 @@ describe('groupList', function() { ...@@ -55,35 +111,7 @@ describe('groupList', function() {
angular.mock.inject(function(_$window_) { angular.mock.inject(function(_$window_) {
$window = _$window_; $window = _$window_;
groups = [ groups = [PUBLIC_GROUP, PRIVATE_GROUP, RESTRICTED_GROUP];
{
id: 'public',
links: {
html: OPEN_GROUP_LINK,
},
name: 'Public Group',
organization: groupFixtures.defaultOrganization(),
type: 'open',
},
{
id: 'h-devs',
links: {
html: PRIVATE_GROUP_LINK,
},
name: 'Hypothesis Developers',
organization: groupFixtures.defaultOrganization(),
type: 'private',
},
{
id: 'restricto',
links: {
html: RESTRICTED_GROUP_LINK,
},
name: 'Hello Restricted',
organization: groupFixtures.defaultOrganization(),
type: 'restricted',
},
];
fakeGroups = { fakeGroups = {
all: function() { all: function() {
...@@ -240,9 +268,9 @@ describe('groupList', function() { ...@@ -240,9 +268,9 @@ describe('groupList', function() {
const link = element.find('.share-link'); const link = element.find('.share-link');
assert.equal(link.length, groups.length); assert.equal(link.length, groups.length);
assert.equal(link[0].href, OPEN_GROUP_LINK); assert.equal(link[0].href, PUBLIC_GROUP.links.html);
assert.equal(link[1].href, PRIVATE_GROUP_LINK); assert.equal(link[1].href, PRIVATE_GROUP.links.html);
assert.equal(link[2].href, RESTRICTED_GROUP_LINK); assert.equal(link[2].href, RESTRICTED_GROUP.links.html);
}); });
it('should not render share links if they are not present', function() { it('should not render share links if they are not present', function() {
...@@ -313,7 +341,7 @@ describe('groupList', function() { ...@@ -313,7 +341,7 @@ describe('groupList', function() {
it('should leave group when the leave icon is clicked', function() { it('should leave group when the leave icon is clicked', function() {
const element = createGroupList(); const element = createGroupList();
clickLeaveIcon(element, true); clickLeaveIcon(element, true);
assert.ok(fakeGroups.leave.calledWith('h-devs')); assert.ok(fakeGroups.leave.calledWith(PRIVATE_GROUP.id));
assert.calledWith(fakeAnalytics.track, fakeAnalytics.events.GROUP_LEAVE); assert.calledWith(fakeAnalytics.track, fakeAnalytics.events.GROUP_LEAVE);
}); });
...@@ -369,20 +397,7 @@ describe('groupList', function() { ...@@ -369,20 +397,7 @@ describe('groupList', function() {
]; ];
// Configure only one group. // Configure only one group.
const groups = [ groups = [PRIVATE_GROUP];
{
id: 'h-devs',
links: {
html: PRIVATE_GROUP_LINK,
},
name: 'Hypothesis Developers',
organization: groupFixtures.defaultOrganization(),
type: 'private',
},
];
fakeGroups.all = () => {
return groups;
};
const element = createGroupList(); const element = createGroupList();
...@@ -425,20 +440,7 @@ describe('groupList', function() { ...@@ -425,20 +440,7 @@ describe('groupList', function() {
it('is shown when it is not a third party service', function() { it('is shown when it is not a third party service', function() {
// Configure only one group. // Configure only one group.
const groups = [ groups = [PRIVATE_GROUP];
{
id: 'h-devs',
links: {
html: PRIVATE_GROUP_LINK,
},
name: 'Hypothesis Developers',
organization: groupFixtures.defaultOrganization(),
type: 'private',
},
];
fakeGroups.all = () => {
return groups;
};
const element = createGroupList(); const element = createGroupList();
......
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