Commit 8da798c8 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Update `AnnotationHeader` to use util for `isHighlight`

parent 591c2338
const propTypes = require('prop-types'); const propTypes = require('prop-types');
const { createElement } = require('preact'); const { createElement } = require('preact');
const { isHighlight } = require('../util/annotation-metadata');
const AnnotationDocumentInfo = require('./annotation-document-info'); const AnnotationDocumentInfo = require('./annotation-document-info');
const AnnotationShareInfo = require('./annotation-share-info'); const AnnotationShareInfo = require('./annotation-share-info');
const AnnotationUser = require('./annotation-user'); const AnnotationUser = require('./annotation-user');
...@@ -15,7 +17,6 @@ const Timestamp = require('./timestamp'); ...@@ -15,7 +17,6 @@ const Timestamp = require('./timestamp');
function AnnotationHeader({ function AnnotationHeader({
annotation, annotation,
isEditing, isEditing,
isHighlight,
onReplyCountClick, onReplyCountClick,
replyCount, replyCount,
showDocumentInfo, showDocumentInfo,
...@@ -60,7 +61,7 @@ function AnnotationHeader({ ...@@ -60,7 +61,7 @@ function AnnotationHeader({
<div className="annotation-header__row"> <div className="annotation-header__row">
<AnnotationShareInfo annotation={annotation} /> <AnnotationShareInfo annotation={annotation} />
{!isEditing && isHighlight && ( {!isEditing && isHighlight(annotation) && (
<div className="annotation-header__highlight"> <div className="annotation-header__highlight">
<SvgIcon <SvgIcon
name="highlight" name="highlight"
...@@ -81,8 +82,6 @@ AnnotationHeader.propTypes = { ...@@ -81,8 +82,6 @@ AnnotationHeader.propTypes = {
annotation: propTypes.object.isRequired, annotation: propTypes.object.isRequired,
/* Whether the annotation is actively being edited */ /* Whether the annotation is actively being edited */
isEditing: propTypes.bool, isEditing: propTypes.bool,
/* Whether the annotation is a highlight */
isHighlight: propTypes.bool,
/* Callback for when the toggle-replies element is clicked */ /* Callback for when the toggle-replies element is clicked */
onReplyCountClick: propTypes.func.isRequired, onReplyCountClick: propTypes.func.isRequired,
/* How many replies this annotation currently has */ /* How many replies this annotation currently has */
......
...@@ -8,12 +8,13 @@ const { $imports } = require('../annotation-header'); ...@@ -8,12 +8,13 @@ const { $imports } = require('../annotation-header');
const mockImportedComponents = require('./mock-imported-components'); const mockImportedComponents = require('./mock-imported-components');
describe('AnnotationHeader', () => { describe('AnnotationHeader', () => {
let fakeIsHighlight;
const createAnnotationHeader = props => { const createAnnotationHeader = props => {
return mount( return mount(
<AnnotationHeader <AnnotationHeader
annotation={fixtures.defaultAnnotation()} annotation={fixtures.defaultAnnotation()}
isEditing={false} isEditing={false}
isHighlight={false}
onReplyCountClick={sinon.stub()} onReplyCountClick={sinon.stub()}
replyCount={0} replyCount={0}
showDocumentInfo={false} showDocumentInfo={false}
...@@ -23,7 +24,14 @@ describe('AnnotationHeader', () => { ...@@ -23,7 +24,14 @@ describe('AnnotationHeader', () => {
}; };
beforeEach(() => { beforeEach(() => {
fakeIsHighlight = sinon.stub().returns(false);
$imports.$mock(mockImportedComponents()); $imports.$mock(mockImportedComponents());
$imports.$mock({
'../util/annotation-metadata': {
isHighlight: fakeIsHighlight,
},
});
}); });
afterEach(() => { afterEach(() => {
...@@ -111,9 +119,9 @@ describe('AnnotationHeader', () => { ...@@ -111,9 +119,9 @@ describe('AnnotationHeader', () => {
describe('annotation is-highlight icon', () => { describe('annotation is-highlight icon', () => {
it('should display is-highlight icon if annotation is a highlight', () => { it('should display is-highlight icon if annotation is a highlight', () => {
fakeIsHighlight.returns(true);
const wrapper = createAnnotationHeader({ const wrapper = createAnnotationHeader({
isEditing: false, isEditing: false,
isHighlight: true,
}); });
const highlightIcon = wrapper.find('.annotation-header__highlight'); const highlightIcon = wrapper.find('.annotation-header__highlight');
...@@ -121,9 +129,9 @@ describe('AnnotationHeader', () => { ...@@ -121,9 +129,9 @@ describe('AnnotationHeader', () => {
}); });
it('should not display the is-highlight icon if annotation is not a highlight', () => { it('should not display the is-highlight icon if annotation is not a highlight', () => {
fakeIsHighlight.returns(false);
const wrapper = createAnnotationHeader({ const wrapper = createAnnotationHeader({
isEditing: false, isEditing: false,
isHighlight: false,
}); });
const highlightIcon = wrapper.find('.annotation-header__highlight'); const highlightIcon = wrapper.find('.annotation-header__highlight');
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
<annotation-header annotation="vm.annotation" <annotation-header annotation="vm.annotation"
is-editing="vm.editing()" is-editing="vm.editing()"
is-highlight="vm.isHighlight()"
on-reply-count-click="vm.onReplyCountClick()" on-reply-count-click="vm.onReplyCountClick()"
reply-count="vm.replyCount" reply-count="vm.replyCount"
show-document-info="vm.showDocumentInfo"> show-document-info="vm.showDocumentInfo">
......
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