Commit 3ab1445d authored by Hannah Stepanek's avatar Hannah Stepanek

Set/get direct-linked group error state from store

- Fix minor mistake in filterGroups where directLinkedGroupId should be
set to null rather than undefined.
parent c23ceaa8
...@@ -49,8 +49,6 @@ function SidebarContentController( ...@@ -49,8 +49,6 @@ function SidebarContentController(
streamFilter streamFilter
) { ) {
const self = this; const self = this;
this.directLinkedGroupFetchFailed =
!!settings.group && settings.group !== store.focusedGroup().id;
function thread() { function thread() {
return rootThread.thread(store.getState()); return rootThread.thread(store.getState());
...@@ -311,7 +309,7 @@ function SidebarContentController( ...@@ -311,7 +309,7 @@ function SidebarContentController(
this.scrollTo = scrollToAnnotation; this.scrollTo = scrollToAnnotation;
this.areAllAnnotationsVisible = function() { this.areAllAnnotationsVisible = function() {
if (this.directLinkedGroupFetchFailed) { if (store.getState().directLinkedGroupFetchFailed) {
return true; return true;
} }
const selection = store.getState().selectedAnnotationMap; const selection = store.getState().selectedAnnotationMap;
...@@ -322,7 +320,7 @@ function SidebarContentController( ...@@ -322,7 +320,7 @@ function SidebarContentController(
}; };
this.selectedGroupUnavailable = function() { this.selectedGroupUnavailable = function() {
return !this.isLoading() && this.directLinkedGroupFetchFailed; return !this.isLoading() && store.getState().directLinkedGroupFetchFailed;
}; };
this.selectedAnnotationUnavailable = function() { this.selectedAnnotationUnavailable = function() {
...@@ -387,8 +385,7 @@ function SidebarContentController( ...@@ -387,8 +385,7 @@ function SidebarContentController(
store.clearSelectedAnnotations(); store.clearSelectedAnnotations();
store.selectTab(selectedTab); store.selectTab(selectedTab);
// Clear direct-linked group fetch failed state. store.clearDirectLinkedGroupFetchFailed();
this.directLinkedGroupFetchFailed = false;
}; };
} }
......
...@@ -213,11 +213,11 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -213,11 +213,11 @@ describe('sidebar.components.sidebar-content', function() {
}); });
it('clears the directLinkedGroupFetchFailed state', () => { it('clears the directLinkedGroupFetchFailed state', () => {
ctrl.directLinkedGroupFetchFailed = true; store.setDirectLinkedGroupFetchFailed();
ctrl.clearSelection(); ctrl.clearSelection();
assert.isFalse(ctrl.directLinkedGroupFetchFailed); assert.isFalse(store.getState().directLinkedGroupFetchFailed);
}); });
}); });
...@@ -234,12 +234,8 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -234,12 +234,8 @@ describe('sidebar.components.sidebar-content', function() {
it('returns false if selected group is unavailable', () => { it('returns false if selected group is unavailable', () => {
fakeSettings.group = 'group-id'; fakeSettings.group = 'group-id';
store.loadGroups([{ id: 'default-id' }]); store.setDirectLinkedGroupFetchFailed();
store.focusGroup('default-id');
fakeGroups.focused.returns({ id: 'default-id' });
$scope.$digest(); $scope.$digest();
// Re-construct the controller after the environment setup.
makeSidebarContentController();
assert.isFalse(ctrl.showSelectedTabs()); assert.isFalse(ctrl.showSelectedTabs());
}); });
...@@ -343,12 +339,8 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -343,12 +339,8 @@ describe('sidebar.components.sidebar-content', function() {
beforeEach(() => { beforeEach(() => {
setFrames([{ uri: 'http://www.example.com' }]); setFrames([{ uri: 'http://www.example.com' }]);
fakeSettings.group = 'group-id'; fakeSettings.group = 'group-id';
store.loadGroups([{ id: 'default-id' }]); store.setDirectLinkedGroupFetchFailed();
store.focusGroup('default-id');
fakeGroups.focused.returns({ id: 'default-id' });
$scope.$digest(); $scope.$digest();
// Re-construct the controller after the environment setup.
makeSidebarContentController();
}); });
[null, 'acct:person@example.com'].forEach(userid => { [null, 'acct:person@example.com'].forEach(userid => {
...@@ -364,10 +356,6 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -364,10 +356,6 @@ describe('sidebar.components.sidebar-content', function() {
}); });
}); });
it('sets directLinkedGroupFetchFailed to true', () => {
assert.isTrue(ctrl.directLinkedGroupFetchFailed);
});
it('areAllAnnotationsVisible returns true since there is an error message', () => { it('areAllAnnotationsVisible returns true since there is an error message', () => {
assert.isTrue(ctrl.areAllAnnotationsVisible()); assert.isTrue(ctrl.areAllAnnotationsVisible());
}); });
...@@ -387,10 +375,6 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -387,10 +375,6 @@ describe('sidebar.components.sidebar-content', function() {
$scope.$digest(); $scope.$digest();
}); });
it('sets directLinkedGroupFetchFailed to false', () => {
assert.isFalse(ctrl.directLinkedGroupFetchFailed);
});
it('areAllAnnotationsVisible returns false since group has no annotations', () => { it('areAllAnnotationsVisible returns false since group has no annotations', () => {
assert.isFalse(ctrl.areAllAnnotationsVisible()); assert.isFalse(ctrl.areAllAnnotationsVisible());
}); });
......
...@@ -77,7 +77,8 @@ function groups( ...@@ -77,7 +77,8 @@ function groups(
directLinkedGroup.scopes.enforced directLinkedGroup.scopes.enforced
) { ) {
groups = groups.filter(g => g.id !== directLinkedGroupId); groups = groups.filter(g => g.id !== directLinkedGroupId);
directLinkedGroupId = undefined; store.setDirectLinkedGroupFetchFailed();
directLinkedGroupId = null;
} }
} }
...@@ -213,6 +214,14 @@ function groups( ...@@ -213,6 +214,14 @@ function groups(
selectedGroupApi = fetchGroup({ selectedGroupApi = fetchGroup({
id: directLinkedGroupId, id: directLinkedGroupId,
expand: params.expand, expand: params.expand,
}).then(group => {
// If the group does not exist or the user doesn't have permission.
if (group === null) {
store.setDirectLinkedGroupFetchFailed();
} else {
store.clearDirectLinkedGroupFetchFailed();
}
return group;
}); });
} }
groupApiRequests = groupApiRequests.concat(selectedGroupApi); groupApiRequests = groupApiRequests.concat(selectedGroupApi);
......
...@@ -85,6 +85,8 @@ describe('groups', function() { ...@@ -85,6 +85,8 @@ describe('groups', function() {
const group = this.getState().focusedGroup; const group = this.getState().focusedGroup;
return group ? group.id : null; return group ? group.id : null;
}, },
setDirectLinkedGroupFetchFailed: sinon.stub(),
clearDirectLinkedGroupFetchFailed: sinon.stub(),
} }
); );
fakeSession = sessionWithThreeGroups(); fakeSession = sessionWithThreeGroups();
...@@ -191,6 +193,8 @@ describe('groups', function() { ...@@ -191,6 +193,8 @@ describe('groups', function() {
fakeSettings.group = outOfScopeEnforcedGroup.id; fakeSettings.group = outOfScopeEnforcedGroup.id;
fakeApi.group.read.returns(Promise.resolve(outOfScopeEnforcedGroup)); fakeApi.group.read.returns(Promise.resolve(outOfScopeEnforcedGroup));
return svc.load().then(groups => { return svc.load().then(groups => {
// The failure state is captured in the store.
assert.called(fakeStore.setDirectLinkedGroupFetchFailed);
// The focus group is not set to the direct-linked group. // The focus group is not set to the direct-linked group.
assert.calledWith(fakeStore.focusGroup, dummyGroups[0].id); assert.calledWith(fakeStore.focusGroup, dummyGroups[0].id);
// The direct-linked group is not in the list of groups. // The direct-linked group is not in the list of groups.
...@@ -211,6 +215,8 @@ describe('groups', function() { ...@@ -211,6 +215,8 @@ describe('groups', function() {
) )
); );
return svc.load().then(() => { return svc.load().then(() => {
// The failure state is captured in the store.
assert.called(fakeStore.setDirectLinkedGroupFetchFailed);
// The focus group is not set to the direct-linked group. // The focus group is not set to the direct-linked group.
assert.calledWith(fakeStore.focusGroup, dummyGroups[0].id); assert.calledWith(fakeStore.focusGroup, dummyGroups[0].id);
}); });
...@@ -381,6 +387,16 @@ describe('groups', function() { ...@@ -381,6 +387,16 @@ describe('groups', function() {
}); });
}); });
it('clears the directLinkedGroupFetchFailed state if loading a direct-linked group', () => {
const svc = service();
fakeSettings.group = dummyGroups[1].id;
fakeApi.groups.list.returns(Promise.resolve(dummyGroups));
return svc.load().then(() => {
assert.called(fakeStore.clearDirectLinkedGroupFetchFailed);
assert.notCalled(fakeStore.setDirectLinkedGroupFetchFailed);
});
});
[null, 'some-group-id'].forEach(groupId => { [null, 'some-group-id'].forEach(groupId => {
it('does not set the focused group if not present in the groups list', () => { it('does not set the focused group if not present in the groups list', () => {
const svc = service(); const svc = service();
......
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