Commit 375d83d1 authored by Kyle Keating's avatar Kyle Keating Committed by Kyle Keating

Use directLinkedGroupId when loading groups

Change loadServiceSpecifiedGroups() so that it can pass along an optional group ID setting value from the `directLinkedGroupId` selector to be an initially focused group.

When loading groups from a service e.g. `loadServiceSpecifiedGroups`, previously it assumed that the `directLinkedGroupId` value would never be used in this context. Since the introduction of the Notebook and specifically in the context of LMS, we have both a service setting which contains the groups  (`settings.services[0].groups <Promise>`) and a top level group to set focus too. (`settings.group`).
parent 5f3f5421
......@@ -366,7 +366,10 @@ export default function groups(
g => g !== null
);
addGroupsToStore(groups);
// Optional direct linked group id. This is used in the Notebook context.
const focusedGroupId = store.directLinkedGroupId();
addGroupsToStore(groups, focusedGroupId);
if (error) {
// @ts-ignore - TS can't track the type of `error` here.
......
......@@ -37,7 +37,7 @@ const dummyGroups = [
{ name: 'Group 3', id: 'id3' },
];
describe('groups', function () {
describe('sidebar/services/groups', function () {
let fakeAuth;
let fakeStore;
let fakeSession;
......@@ -813,6 +813,28 @@ describe('groups', function () {
);
assert.deepEqual(groups, []);
});
it('initially sets the focused group to the `directLinkedGroupId`', async () => {
setServiceConfigGroups(Promise.resolve(['id-a', 'id-b', 'id-c']));
fakeApi.profile.groups.read.resolves([groupA, groupB, groupC]);
fakeStore.directLinkedGroupId.returns('id-c');
const svc = service();
await svc.load();
assert.calledWith(fakeStore.focusGroup, 'id-c');
});
it('does not set the focused group if no `directLinkedGroupId`', async () => {
setServiceConfigGroups(Promise.resolve(['id-a', 'id-b', 'id-c']));
fakeApi.profile.groups.read.resolves([groupA, groupB, groupC]);
fakeStore.directLinkedGroupId.returns(null);
const svc = service();
await svc.load();
assert.notCalled(fakeStore.focusGroup);
});
});
});
......
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