Commit e2c6f1df authored by Hannah Stepanek's avatar Hannah Stepanek Committed by Robert Knight

Make direct-linked-group store module more generic

- Rename direct-linked-group store module to direct-linked so that it
may track the state of all direct-linked related items.
- Add directLinkedAnnotationsId and directLinkedGroupId to direct-linked
store module. This provides an official location to track/change the
state of the settings.annotations and settings.group rather than
modifying them directly.
parent 6e0969f8
......@@ -36,7 +36,7 @@ const debugMiddleware = require('./debug-middleware');
const activity = require('./modules/activity');
const annotations = require('./modules/annotations');
const directLinkedGroup = require('./modules/direct-linked-group');
const directLinked = require('./modules/direct-linked');
const frames = require('./modules/frames');
const links = require('./modules/links');
const groups = require('./modules/groups');
......@@ -87,7 +87,7 @@ function store($rootScope, settings) {
const modules = [
activity,
annotations,
directLinkedGroup,
directLinked,
frames,
links,
groups,
......
......@@ -2,8 +2,20 @@
const util = require('../util');
function init() {
function init(settings) {
return {
/**
* The id of the direct-linked group.
* @type {string}
*/
directLinkedGroupId: settings.group || null,
/**
* The id of the direct-linked annotation's group.
* @type {string}
*/
directLinkedAnnotationsId: settings.annotations || null,
/**
* Indicates that an error occured in retrieving/showing the direct linked group.
* This could be because:
......@@ -22,10 +34,46 @@ const update = {
directLinkedGroupFetchFailed: action.directLinkedGroupFetchFailed,
};
},
UPDATE_DIRECT_LINKED_GROUP_ID(state, action) {
return {
directLinkedGroupId: action.directLinkedGroupId,
};
},
UPDATE_DIRECT_LINKED_ANNOTATIONS_ID(state, action) {
return {
directLinkedAnnotationsId: action.directLinkedAnnotationsId,
};
},
CLEAR_DIRECT_LINKED_IDS() {
return {
directLinkedAnnotationsId: null,
directLinkedGroupId: null,
};
},
};
const actions = util.actionTypes(update);
/**
* Set the direct linked group id.
*/
function setDirectLinkedGroupId(groupId) {
return {
type: actions.UPDATE_DIRECT_LINKED_GROUP_ID,
directLinkedGroupId: groupId,
};
}
/**
* Set the direct linked annotation's id.
*/
function setDirectLinkedAnnotationsId(annId) {
return {
type: actions.UPDATE_DIRECT_LINKED_ANNOTATIONS_ID,
directLinkedAnnotationsId: annId,
};
}
/**
* Set the direct linked group fetch failure to true.
*/
......@@ -46,12 +94,24 @@ function clearDirectLinkedGroupFetchFailed() {
};
}
/**
* Clear the direct linked annotations and group id's.
*/
function clearDirectLinkedIds() {
return {
type: actions.CLEAR_DIRECT_LINKED_IDS,
};
}
module.exports = {
init,
update,
actions: {
setDirectLinkedGroupFetchFailed,
setDirectLinkedGroupId,
setDirectLinkedAnnotationsId,
clearDirectLinkedGroupFetchFailed,
clearDirectLinkedIds,
},
selectors: {},
};
'use strict';
const createStore = require('../../create-store');
const directLinkedGroup = require('../direct-linked-group');
describe('sidebar/store/modules/direct-linked-group', () => {
let store;
beforeEach(() => {
store = createStore([directLinkedGroup]);
});
it('sets directLinkedGroupFetchFailed to true', () => {
store.setDirectLinkedGroupFetchFailed();
assert.isTrue(store.getState().directLinkedGroupFetchFailed);
});
it('sets directLinkedGroupFetchFailed to false', () => {
store.setDirectLinkedGroupFetchFailed();
store.clearDirectLinkedGroupFetchFailed();
assert.isFalse(store.getState().directLinkedGroupFetchFailed);
});
});
'use strict';
const createStore = require('../../create-store');
const directLinked = require('../direct-linked');
describe('sidebar/store/modules/direct-linked', () => {
let store;
let fakeSettings = {};
beforeEach(() => {
store = createStore([directLinked], [fakeSettings]);
});
it('sets directLinkedGroupFetchFailed to true', () => {
store.setDirectLinkedGroupFetchFailed();
assert.isTrue(store.getState().directLinkedGroupFetchFailed);
});
it('sets directLinkedGroupFetchFailed to false', () => {
store.setDirectLinkedGroupFetchFailed();
store.clearDirectLinkedGroupFetchFailed();
assert.isFalse(store.getState().directLinkedGroupFetchFailed);
});
it('sets directLinkedAnnotationsId to settings.annotations during store init', () => {
fakeSettings.annotations = 'ann-id';
store = createStore([directLinked], [fakeSettings]);
assert.equal(store.getState().directLinkedAnnotationsId, 'ann-id');
});
it('sets directLinkedAnnotationsId to the specified annotation id', () => {
store.setDirectLinkedAnnotationsId('ann-id');
assert.equal(store.getState().directLinkedAnnotationsId, 'ann-id');
});
it('sets directLinkedGroupId to settings.group during store init', () => {
fakeSettings.group = 'group-id';
store = createStore([directLinked], [fakeSettings]);
assert.equal(store.getState().directLinkedGroupId, 'group-id');
});
it('sets directLinkedGroupId to the specified group id', () => {
store.setDirectLinkedGroupId('group-id');
assert.equal(store.getState().directLinkedGroupId, 'group-id');
});
it('sets direct-link annotations and group ids to null', () => {
store.setDirectLinkedGroupId('ann-id');
store.setDirectLinkedGroupId('group-id');
store.clearDirectLinkedIds();
assert.equal(store.getState().directLinkedAnnotationsId, null);
assert.equal(store.getState().directLinkedGroupId, null);
});
});
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