Commit 80057535 authored by Robert Knight's avatar Robert Knight

Update moderation flag count after moderator flags an annotation

Flagging or unflagging an annotation previously updated the status
flag indicating whether an annotation had been flagged by the current
user but did not update the flag count if the user was also a moderator.

This needs to be done to make the moderation banner's state update when
a user who is also a moderator flags an annotation.
parent efd5ea3f
......@@ -150,9 +150,20 @@ var update = {
var annotations = state.annotations.map(function (annot) {
var match = (annot.id && annot.id === action.id);
if (match) {
return Object.assign({}, annot, {
if (annot.flagged === action.isFlagged) {
return annot;
}
var newAnn = Object.assign({}, annot, {
flagged: action.isFlagged,
});
if (newAnn.moderation) {
var countDelta = action.isFlagged ? 1 : -1;
newAnn.moderation = Object.assign(annot.moderation, {
flagCount: annot.moderation.flagCount + countDelta,
});
}
return newAnn;
} else {
return annot;
}
......
......@@ -60,8 +60,10 @@ describe('annotations reducer', function () {
it('sets the `hidden` state to `true`', function () {
var store = createStore();
var ann = fixtures.moderatedAnnotation({ hidden: false });
store.dispatch(actions.addAnnotations([ann]));
store.dispatch(actions.hideAnnotation(ann.id));
var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id);
assert.equal(storeAnn.hidden, true);
});
......@@ -71,8 +73,10 @@ describe('annotations reducer', function () {
it('sets the `hidden` state to `false`', function () {
var store = createStore();
var ann = fixtures.moderatedAnnotation({ hidden: true });
store.dispatch(actions.addAnnotations([ann]));
store.dispatch(actions.unhideAnnotation(ann.id));
var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id);
assert.equal(storeAnn.hidden, false);
});
......@@ -90,5 +94,27 @@ describe('annotations reducer', function () {
var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id);
assert.equal(storeAnn.flagged, testCase.flagged);
}, [{ flagged: true}, { flagged: false }]);
it('does not add moderation info if not present', function () {
var store = createStore();
var ann = fixtures.defaultAnnotation();
store.dispatch(actions.addAnnotations([ann]));
store.dispatch(actions.updateFlagStatus(ann.id, true));
var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id);
assert.notOk(storeAnn.moderation);
});
it('increments the flag count if moderation info is present', function () {
var store = createStore();
var ann = fixtures.moderatedAnnotation({ flagCount: 0 });
store.dispatch(actions.addAnnotations([ann]));
store.dispatch(actions.updateFlagStatus(ann.id, true));
var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id);
assert.equal(storeAnn.moderation.flagCount, 1);
});
});
});
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