Commit fe502753 authored by Robert Knight's avatar Robert Knight

Add more complete tests for `updateFlagStatus` action

parent 80057535
...@@ -86,35 +86,51 @@ describe('annotations reducer', function () { ...@@ -86,35 +86,51 @@ describe('annotations reducer', function () {
unroll('updates the flagged status of an annotation', function (testCase) { unroll('updates the flagged status of an annotation', function (testCase) {
var store = createStore(); var store = createStore();
var ann = fixtures.defaultAnnotation(); var ann = fixtures.defaultAnnotation();
ann.flagged = !testCase.flagged; ann.flagged = testCase.wasFlagged;
ann.moderation = testCase.oldModeration;
store.dispatch(actions.addAnnotations([ann])); store.dispatch(actions.addAnnotations([ann]));
store.dispatch(actions.updateFlagStatus(ann.id, testCase.flagged)); store.dispatch(actions.updateFlagStatus(ann.id, testCase.nowFlagged));
var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id); var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id);
assert.equal(storeAnn.flagged, testCase.flagged); assert.equal(storeAnn.flagged, testCase.nowFlagged);
}, [{ flagged: true}, { flagged: false }]); assert.deepEqual(storeAnn.moderation, testCase.newModeration);
}, [{
it('does not add moderation info if not present', function () { // Non-moderator flags annotation
var store = createStore(); wasFlagged: false,
var ann = fixtures.defaultAnnotation(); nowFlagged: true,
oldModeration: undefined,
store.dispatch(actions.addAnnotations([ann])); newModeration: undefined,
store.dispatch(actions.updateFlagStatus(ann.id, true)); }, {
// Non-moderator un-flags annotation
var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id); wasFlagged: true,
assert.notOk(storeAnn.moderation); nowFlagged: false,
}); oldModeration: undefined,
newModeration: undefined,
it('increments the flag count if moderation info is present', function () { },{
var store = createStore(); // Moderator un-flags an already unflagged annotation
var ann = fixtures.moderatedAnnotation({ flagCount: 0 }); wasFlagged: false,
nowFlagged: false,
store.dispatch(actions.addAnnotations([ann])); oldModeration: { flagCount: 1 },
store.dispatch(actions.updateFlagStatus(ann.id, true)); newModeration: { flagCount: 1 },
},{
var storeAnn = annotations.findAnnotationByID(store.getState(), ann.id); // Moderator flags an already flagged annotation
assert.equal(storeAnn.moderation.flagCount, 1); wasFlagged: true,
}); nowFlagged: true,
oldModeration: { flagCount: 1 },
newModeration: { flagCount: 1 },
},{
// Moderator flags annotation
wasFlagged: false,
nowFlagged: true,
oldModeration: { flagCount: 0 },
newModeration: { flagCount: 1 },
},{
// Moderator un-flags annotation
wasFlagged: true,
nowFlagged: false,
oldModeration: { flagCount: 1 },
newModeration: { flagCount: 0 },
}]);
}); });
}); });
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