Commit 591c2338 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Update `AnnotationQuote` to use util for `isOrphan`, `quote`

parent 0d93b3a0
...@@ -2,17 +2,22 @@ const classnames = require('classnames'); ...@@ -2,17 +2,22 @@ const classnames = require('classnames');
const { createElement } = require('preact'); const { createElement } = require('preact');
const propTypes = require('prop-types'); const propTypes = require('prop-types');
const { isOrphan, quote } = require('../util/annotation-metadata');
const { withServices } = require('../util/service-context'); const { withServices } = require('../util/service-context');
const { applyTheme } = require('../util/theme'); const { applyTheme } = require('../util/theme');
const Excerpt = require('./excerpt'); const Excerpt = require('./excerpt');
/** /**
* Display the selected text from the document associated with an annotation. * Display the selected text from the document associated with an annotation.
*/ */
function AnnotationQuote({ isOrphan, quote, settings = {} }) { function AnnotationQuote({ annotation, settings = {} }) {
return ( return (
<section <section
className={classnames('annotation-quote', isOrphan && 'is-orphan')} className={classnames(
'annotation-quote',
isOrphan(annotation) && 'is-orphan'
)}
> >
<Excerpt <Excerpt
collapsedHeight={35} collapsedHeight={35}
...@@ -23,7 +28,7 @@ function AnnotationQuote({ isOrphan, quote, settings = {} }) { ...@@ -23,7 +28,7 @@ function AnnotationQuote({ isOrphan, quote, settings = {} }) {
className="annotation-quote__quote" className="annotation-quote__quote"
style={applyTheme(['selectionFontFamily'], settings)} style={applyTheme(['selectionFontFamily'], settings)}
> >
{quote} {quote(annotation)}
</blockquote> </blockquote>
</Excerpt> </Excerpt>
</section> </section>
...@@ -31,17 +36,7 @@ function AnnotationQuote({ isOrphan, quote, settings = {} }) { ...@@ -31,17 +36,7 @@ function AnnotationQuote({ isOrphan, quote, settings = {} }) {
} }
AnnotationQuote.propTypes = { AnnotationQuote.propTypes = {
/** annotation: propTypes.object.isRequired,
* If `true`, display an indicator that the annotated text was not found in
* the current version of the document.
*/
isOrphan: propTypes.bool,
/**
* The text that the annotation refers to. This is rendered as plain text
* (ie. HTML tags are rendered literally).
*/
quote: propTypes.string,
// Used for theming. // Used for theming.
settings: propTypes.object, settings: propTypes.object,
......
...@@ -377,13 +377,6 @@ function AnnotationController( ...@@ -377,13 +377,6 @@ function AnnotationController(
}); });
}; };
this.isOrphan = function() {
if (typeof self.annotation.$orphan === 'undefined') {
return self.annotation.$anchorTimeout;
}
return self.annotation.$orphan;
};
this.user = function() { this.user = function() {
return self.annotation.user; return self.annotation.user;
}; };
......
...@@ -6,14 +6,31 @@ const { $imports } = require('../annotation-quote'); ...@@ -6,14 +6,31 @@ const { $imports } = require('../annotation-quote');
const mockImportedComponents = require('./mock-imported-components'); const mockImportedComponents = require('./mock-imported-components');
describe('AnnotationQuote', () => { describe('AnnotationQuote', () => {
let fakeAnnotation;
let fakeIsOrphan;
let fakeQuote;
function createQuote(props) { function createQuote(props) {
return mount( return mount(
<AnnotationQuote quote="test quote" settings={{}} {...props} /> <AnnotationQuote annotation={fakeAnnotation} settings={{}} {...props} />
); );
} }
beforeEach(() => { beforeEach(() => {
fakeAnnotation = {
target: [],
};
fakeQuote = sinon.stub().returns('test quote');
fakeIsOrphan = sinon.stub();
$imports.$mock(mockImportedComponents()); $imports.$mock(mockImportedComponents());
$imports.$mock({
'../util/annotation-metadata': {
quote: fakeQuote,
isOrphan: fakeIsOrphan,
},
});
}); });
afterEach(() => { afterEach(() => {
......
...@@ -137,8 +137,7 @@ describe('annotation', function() { ...@@ -137,8 +137,7 @@ describe('annotation', function() {
}) })
.component('annotationQuote', { .component('annotationQuote', {
bindings: { bindings: {
isOrphan: '<', annotation: '<',
quote: '<',
}, },
}); });
}); });
...@@ -682,33 +681,6 @@ describe('annotation', function() { ...@@ -682,33 +681,6 @@ describe('annotation', function() {
}); });
}); });
describe('#isOrphan', function() {
it('returns false if the annotation is not an orphan', function() {
const controller = createDirective().controller;
controller.annotation.$orphan = false;
assert.isFalse(controller.isOrphan());
});
it('returns true if the annotation is an orphan', function() {
const controller = createDirective().controller;
controller.annotation.$orphan = true;
assert.isTrue(controller.isOrphan());
});
it('returns true if the anchoring timeout expired', function() {
const controller = createDirective().controller;
controller.annotation.$anchorTimeout = true;
assert.isTrue(controller.isOrphan());
});
it('returns false if the anchoring timeout expired but anchoring did complete', function() {
const controller = createDirective().controller;
controller.annotation.$orphan = false;
controller.annotation.$anchorTimeout = true;
assert.isFalse(controller.isOrphan());
});
});
describe('#shouldShowLicense', function() { describe('#shouldShowLicense', function() {
[ [
{ {
......
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
show-document-info="vm.showDocumentInfo"> show-document-info="vm.showDocumentInfo">
</annotation-header> </annotation-header>
<annotation-quote <annotation-quote annotation="vm.annotation" ng-if="vm.quote()">
quote="vm.quote()"
is-orphan="vm.isOrphan()"
ng-if="vm.quote()">
</annotation-quote> </annotation-quote>
<annotation-body <annotation-body
......
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