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(
streamFilter
) {
const self = this;
this.directLinkedGroupFetchFailed =
!!settings.group && settings.group !== store.focusedGroup().id;
function thread() {
return rootThread.thread(store.getState());
......@@ -311,7 +309,7 @@ function SidebarContentController(
this.scrollTo = scrollToAnnotation;
this.areAllAnnotationsVisible = function() {
if (this.directLinkedGroupFetchFailed) {
if (store.getState().directLinkedGroupFetchFailed) {
return true;
}
const selection = store.getState().selectedAnnotationMap;
......@@ -322,7 +320,7 @@ function SidebarContentController(
};
this.selectedGroupUnavailable = function() {
return !this.isLoading() && this.directLinkedGroupFetchFailed;
return !this.isLoading() && store.getState().directLinkedGroupFetchFailed;
};
this.selectedAnnotationUnavailable = function() {
......@@ -387,8 +385,7 @@ function SidebarContentController(
store.clearSelectedAnnotations();
store.selectTab(selectedTab);
// Clear direct-linked group fetch failed state.
this.directLinkedGroupFetchFailed = false;
store.clearDirectLinkedGroupFetchFailed();
};
}
......
......@@ -213,11 +213,11 @@ describe('sidebar.components.sidebar-content', function() {
});
it('clears the directLinkedGroupFetchFailed state', () => {
ctrl.directLinkedGroupFetchFailed = true;
store.setDirectLinkedGroupFetchFailed();
ctrl.clearSelection();
assert.isFalse(ctrl.directLinkedGroupFetchFailed);
assert.isFalse(store.getState().directLinkedGroupFetchFailed);
});
});
......@@ -234,12 +234,8 @@ describe('sidebar.components.sidebar-content', function() {
it('returns false if selected group is unavailable', () => {
fakeSettings.group = 'group-id';
store.loadGroups([{ id: 'default-id' }]);
store.focusGroup('default-id');
fakeGroups.focused.returns({ id: 'default-id' });
store.setDirectLinkedGroupFetchFailed();
$scope.$digest();
// Re-construct the controller after the environment setup.
makeSidebarContentController();
assert.isFalse(ctrl.showSelectedTabs());
});
......@@ -343,12 +339,8 @@ describe('sidebar.components.sidebar-content', function() {
beforeEach(() => {
setFrames([{ uri: 'http://www.example.com' }]);
fakeSettings.group = 'group-id';
store.loadGroups([{ id: 'default-id' }]);
store.focusGroup('default-id');
fakeGroups.focused.returns({ id: 'default-id' });
store.setDirectLinkedGroupFetchFailed();
$scope.$digest();
// Re-construct the controller after the environment setup.
makeSidebarContentController();
});
[null, 'acct:person@example.com'].forEach(userid => {
......@@ -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', () => {
assert.isTrue(ctrl.areAllAnnotationsVisible());
});
......@@ -387,10 +375,6 @@ describe('sidebar.components.sidebar-content', function() {
$scope.$digest();
});
it('sets directLinkedGroupFetchFailed to false', () => {
assert.isFalse(ctrl.directLinkedGroupFetchFailed);
});
it('areAllAnnotationsVisible returns false since group has no annotations', () => {
assert.isFalse(ctrl.areAllAnnotationsVisible());
});
......
......@@ -77,7 +77,8 @@ function groups(
directLinkedGroup.scopes.enforced
) {
groups = groups.filter(g => g.id !== directLinkedGroupId);
directLinkedGroupId = undefined;
store.setDirectLinkedGroupFetchFailed();
directLinkedGroupId = null;
}
}
......@@ -213,6 +214,14 @@ function groups(
selectedGroupApi = fetchGroup({
id: directLinkedGroupId,
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);
......
......@@ -85,6 +85,8 @@ describe('groups', function() {
const group = this.getState().focusedGroup;
return group ? group.id : null;
},
setDirectLinkedGroupFetchFailed: sinon.stub(),
clearDirectLinkedGroupFetchFailed: sinon.stub(),
}
);
fakeSession = sessionWithThreeGroups();
......@@ -191,6 +193,8 @@ describe('groups', function() {
fakeSettings.group = outOfScopeEnforcedGroup.id;
fakeApi.group.read.returns(Promise.resolve(outOfScopeEnforcedGroup));
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.
assert.calledWith(fakeStore.focusGroup, dummyGroups[0].id);
// The direct-linked group is not in the list of groups.
......@@ -211,6 +215,8 @@ describe('groups', function() {
)
);
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.
assert.calledWith(fakeStore.focusGroup, dummyGroups[0].id);
});
......@@ -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 => {
it('does not set the focused group if not present in the groups list', () => {
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