Commit cd7dbf51 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Clarify `focusMode` in `selection` module

- Rename `enabled` to `configured`
parent 1bcc0b06
......@@ -32,7 +32,7 @@ function SidebarContent({
// Store state values
const focusedGroupId = useStore(store => store.focusedGroupId());
const hasAppliedFilter = useStore(store => store.hasAppliedFilter());
const isFocusedMode = useStore(store => store.focusModeEnabled());
const isFocusedMode = useStore(store => store.focusModeConfigured());
const isLoading = useStore(store => store.isLoading());
const isLoggedIn = useStore(store => store.isLoggedIn());
const linkedAnnotationId = useStore(store =>
......
......@@ -52,7 +52,7 @@ describe('SidebarContent', () => {
directLinkedGroupFetchFailed: sinon.stub(),
findAnnotationByID: sinon.stub(),
focusedGroupId: sinon.stub(),
focusModeEnabled: sinon.stub(),
focusModeConfigured: sinon.stub(),
hasAppliedFilter: sinon.stub(),
hasFetchedAnnotations: sinon.stub(),
hasSidebarOpened: sinon.stub(),
......@@ -226,7 +226,7 @@ describe('SidebarContent', () => {
});
it('renders a focused header if in focused mode', () => {
fakeStore.focusModeEnabled.returns(true);
fakeStore.focusModeConfigured.returns(true);
const wrapper = createComponent();
assert.isTrue(wrapper.find('FocusedModeHeader').exists());
......
......@@ -60,6 +60,23 @@ function initialSelection(settings) {
return selection;
}
// function initialFocus(settings) {
// const focusConfig = {
// configured: false,
// active: false,
// user: undefined,
// };
//
// if (settings.hasOwnProperty('user')) {
// const focusedUser = {...settings.user};
// if (focusedUser.username && focusedUser.authority) {
// focusConfig.configured = true;
// focusConfig.user = focusedUser;
// }
// }
// return focusConfig;
// }
function init(settings) {
return {
/**
......@@ -96,7 +113,7 @@ function init(settings) {
filterQuery: settings.query || null,
focusMode: {
enabled: settings.hasOwnProperty('focus'),
configured: settings.hasOwnProperty('focus'),
focused: true,
// Copy over the focus confg from settings object
config: { ...(settings.focus ? settings.focus : {}) },
......@@ -163,7 +180,7 @@ const update = {
return {
focusMode: {
...state.focusMode,
enabled: false,
configured: false,
focused: false,
},
};
......@@ -171,7 +188,7 @@ const update = {
return {
focusMode: {
...state.focusMode,
enabled: true,
configured: true,
focused: true,
config: {
user: { ...action.user },
......@@ -464,21 +481,21 @@ function filterQuery(state) {
}
/**
* Do the config settings indicate that the client should be in a focused mode?
* Does the configuration used by the app contain valid focus-mode configuration?
*
* @return {boolean}
*/
function focusModeEnabled(state) {
return state.selection.focusMode.enabled;
function focusModeConfigured(state) {
return state.selection.focusMode.configured;
}
/**
* Is a focus mode enabled, and is it presently applied?
* Is a focus mode configured, and is it presently applied?
*
* @return {boolean}
*/
function focusModeFocused(state) {
return focusModeEnabled(state) && state.selection.focusMode.focused;
return focusModeConfigured(state) && state.selection.focusMode.focused;
}
/**
......@@ -507,7 +524,7 @@ function focusModeUserId(state) {
* @return {boolean}
*/
function focusModeHasUser(state) {
return focusModeEnabled(state) && !!focusModeUserId(state);
return focusModeConfigured(state) && !!focusModeUserId(state);
}
/**
......@@ -592,7 +609,7 @@ export default {
expandedMap,
filterQuery,
focusModeFocused,
focusModeEnabled,
focusModeConfigured,
focusModeHasUser,
focusModeUserId,
focusModeUserPrettyName,
......
......@@ -226,7 +226,7 @@ describe('sidebar/store/modules/selection', () => {
assert.equal(store.focusModeUserId(), 'testuser');
assert.equal(store.focusModeUserPrettyName(), 'Test User');
assert.equal(store.focusModeFocused(), true);
assert.equal(store.focusModeEnabled(), true);
assert.equal(store.focusModeConfigured(), true);
});
// When the LMS app wants the client to disable focus mode it sends a
......@@ -243,7 +243,7 @@ describe('sidebar/store/modules/selection', () => {
displayName: undefined,
});
assert.equal(store.focusModeFocused(), false);
assert.equal(store.focusModeEnabled(), false);
assert.equal(store.focusModeConfigured(), false);
});
it('clears other applied selections', () => {
......@@ -261,51 +261,51 @@ describe('sidebar/store/modules/selection', () => {
});
describe('setFocusModeFocused()', function () {
it('sets the focus mode to enabled', function () {
it('sets the focus mode to focused', function () {
store.setFocusModeFocused(true);
assert.equal(getSelectionState().focusMode.focused, true);
});
it('sets the focus mode to not enabled', function () {
it('sets the focus mode to not focused', function () {
store = createStore([selection], [{ focus: { user: {} } }]);
store.setFocusModeFocused(false);
assert.equal(getSelectionState().focusMode.focused, false);
});
});
describe('focusModeEnabled()', function () {
describe('focusModeConfigured', function () {
it('should be true when the focus setting is present', function () {
store = createStore([selection], [{ focus: { user: {} } }]);
assert.equal(store.focusModeEnabled(), true);
assert.equal(store.focusModeConfigured(), true);
});
it('should be false when the focus setting is not present', function () {
assert.equal(store.focusModeEnabled(), false);
assert.equal(store.focusModeConfigured(), false);
});
});
describe('focusModeFocused()', function () {
it('should return true by default when focus mode is enabled', function () {
describe('focusModeFocused', function () {
it('should return true by default when focus mode is focused', function () {
store = createStore([selection], [{ focus: { user: {} } }]);
assert.equal(getSelectionState().focusMode.enabled, true);
assert.equal(getSelectionState().focusMode.configured, true);
assert.equal(getSelectionState().focusMode.focused, true);
assert.equal(store.focusModeFocused(), true);
});
it('should return false by default when focus mode is not enabled', function () {
assert.equal(getSelectionState().focusMode.enabled, false);
it('should return false by default when focus mode is not focused', function () {
assert.equal(getSelectionState().focusMode.configured, false);
assert.equal(getSelectionState().focusMode.focused, true);
assert.equal(store.focusModeFocused(), false);
});
});
describe('focusModeHasUser()', () => {
it('should return `true` if focus enabled and valid `user` object present', () => {
it('should return `true` if focus configured and valid `user` object present', () => {
store = createStore(
[selection],
[{ focus: { user: { userid: 'acct:userid@authority' } } }]
);
assert.isTrue(store.focusModeHasUser());
});
it('should return `false` if focus enabled but `user` object invalid', () => {
it('should return `false` if focus configured but `user` object invalid', () => {
store = createStore(
[selection],
[{ focus: { user: { displayName: 'FakeDisplayName' } } }] // `userid` is required
......@@ -319,7 +319,7 @@ describe('sidebar/store/modules/selection', () => {
});
describe('focusModeUserPrettyName()', function () {
it('returns false by default when focus mode is not enabled', function () {
it('returns false by default when focus mode is not configured', function () {
store = createStore(
[selection],
[{ focus: { user: { displayName: 'FakeDisplayName' } } }]
......
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