Unverified Commit 396b9d16 authored by Robert Knight's avatar Robert Knight Committed by Sean Hammond

Read hidden state of annotations from `annotation.hidden`

The `hidden` state has been moved from the `annotation.moderation` key
to a top-level property of the annotation.
parent 8d745a50
......@@ -479,10 +479,7 @@ function AnnotationController(
};
vm.isHiddenByModerator = function () {
if (!vm.annotation.moderation) {
return false;
}
return vm.annotation.moderation.is_hidden;
return vm.annotation.hidden;
};
vm.isFlagged = function() {
......
......@@ -15,11 +15,7 @@ function ModerationBannerController(annotationUI, flash, store) {
};
this.isHidden = function () {
var moderation = self.annotation.moderation;
if (!moderation) {
return false;
}
return moderation.is_hidden;
return self.annotation.hidden;
};
this.isReply = function () {
......
......@@ -998,7 +998,7 @@ describe('annotation', function() {
});
it('renders hidden annotations with a custom text class', function () {
var ann = fixtures.moderatedAnnotation({ is_hidden: true });
var ann = fixtures.moderatedAnnotation({ hidden: true });
var el = createDirective(ann).element;
assert.deepEqual(el.find('markdown').controller('markdown'), {
customTextClass: {
......
......@@ -183,7 +183,7 @@ describe('annotationThread', function () {
});
it('renders the moderation banner', function () {
var ann = fixtures.moderatedAnnotation({ flag_count: 1 });
var ann = fixtures.moderatedAnnotation({ flagCount: 1 });
var thread = {
annotation: ann,
id: '123',
......
......@@ -58,11 +58,7 @@ describe('moderationBanner', function () {
});
it('displays the number of flags the annotation has received', function () {
var ann = Object.assign(fixtures.defaultAnnotation(), {
moderation: {
flag_count: 10,
},
});
var ann = fixtures.moderatedAnnotation({ flagCount: 10 });
var banner = createBanner({ annotation: ann });
assert.include(banner.textContent, 'Flagged for review x10');
});
......@@ -78,20 +74,20 @@ describe('moderationBanner', function () {
});
it('reports if the annotation was hidden', function () {
var ann = moderatedAnnotation({ is_hidden: true });
var ann = moderatedAnnotation({ hidden: true });
var banner = createBanner({ annotation: ann });
assert.include(banner.textContent, 'Hidden from users');
});
it('hides the annotation if "Hide" is clicked', function () {
var ann = moderatedAnnotation({ flag_count: 10 });
var ann = moderatedAnnotation({ flagCount: 10 });
var banner = createBanner({ annotation: ann });
banner.querySelector('button').click();
assert.calledWith(fakeStore.annotation.hide, {id: 'ann-id'});
});
it('reports an error if hiding the annotation fails', function (done) {
var ann = moderatedAnnotation({ flag_count: 10 });
var ann = moderatedAnnotation({ flagCount: 10 });
var banner = createBanner({ annotation: ann });
fakeStore.annotation.hide.returns(Promise.reject(new Error('Network Error')));
......@@ -104,7 +100,7 @@ describe('moderationBanner', function () {
});
it('unhides the annotation if "Unhide" is clicked', function () {
var ann = moderatedAnnotation({ is_hidden: true });
var ann = moderatedAnnotation({ hidden: true });
var banner = createBanner({ annotation: ann });
banner.querySelector('button').click();
......@@ -113,7 +109,7 @@ describe('moderationBanner', function () {
});
it('reports an error if unhiding the annotation fails', function (done) {
var ann = moderatedAnnotation({ is_hidden: true });
var ann = moderatedAnnotation({ hidden: true });
var banner = createBanner({ annotation: ann });
fakeStore.annotation.unhide.returns(Promise.reject(new Error('Network Error')));
......
......@@ -182,12 +182,7 @@ var update = {
if (ann.id !== action.id) {
return ann;
}
var moderation = Object.assign({}, ann.moderation, {
is_hidden: true,
});
return Object.assign({}, ann, {
moderation: moderation,
});
return Object.assign({}, ann, { hidden: true });
});
return {annotations: anns};
},
......@@ -197,12 +192,7 @@ var update = {
if (ann.id !== action.id) {
return ann;
}
var moderation = Object.assign({}, ann.moderation, {
is_hidden: false,
});
return Object.assign({}, ann, {
moderation: moderation,
});
return Object.assign({}, ann, { hidden: false });
});
return {annotations: anns};
},
......
......@@ -56,24 +56,24 @@ describe('annotations reducer', function () {
});
describe('#hideAnnotation', function () {
it('sets the moderation/is_hidden state to `true`', function () {
it('sets the `hidden` state to `true`', function () {
var store = createStore();
var ann = fixtures.moderatedAnnotation({ is_hidden: false });
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.moderation.is_hidden, true);
assert.equal(storeAnn.hidden, true);
});
});
describe('#unhideAnnotation', function () {
it('sets the moderation/is_hidden state to `false`', function () {
it('sets the `hidden` state to `false`', function () {
var store = createStore();
var ann = fixtures.moderatedAnnotation({ is_hidden: true });
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.moderation.is_hidden, false);
assert.equal(storeAnn.hidden, false);
});
});
});
......@@ -139,8 +139,8 @@ function oldReply() {
/**
* @typedef ModerationState
* @property {boolean} is_hidden
* @property {number} flag_count
* @property {boolean} hidden
* @property {number} flagCount
*/
/**
......@@ -151,7 +151,10 @@ function oldReply() {
function moderatedAnnotation(modInfo) {
return Object.assign(defaultAnnotation(), {
id: 'ann-id',
moderation: modInfo,
hidden: !!modInfo.hidden,
moderation: {
flag_count: modInfo.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