Commit 91f96795 authored by Robert Knight's avatar Robert Knight

Add tests for adder toolbar callbacks in Guest

Add tests for the main code paths in `Guest` that call `createAnnotation`.
parent 5300b58c
...@@ -122,13 +122,13 @@ export default class Guest extends Delegator { ...@@ -122,13 +122,13 @@ export default class Guest extends Delegator {
this.element.appendChild(this.adderToolbar); this.element.appendChild(this.adderToolbar);
this.adderCtrl = new Adder(this.adderToolbar, { this.adderCtrl = new Adder(this.adderToolbar, {
onAnnotate: () => { onAnnotate: async () => {
this.createAnnotation(); await this.createAnnotation();
/** @type {Selection} */ (document.getSelection()).removeAllRanges(); /** @type {Selection} */ (document.getSelection()).removeAllRanges();
}, },
onHighlight: () => { onHighlight: async () => {
this.setVisibleHighlights(true); this.setVisibleHighlights(true);
this.createHighlight(); await this.createHighlight();
/** @type {Selection} */ (document.getSelection()).removeAllRanges(); /** @type {Selection} */ (document.getSelection()).removeAllRanges();
}, },
onShowAnnotations: anns => { onShowAnnotations: anns => {
...@@ -572,6 +572,8 @@ export default class Guest extends Delegator { ...@@ -572,6 +572,8 @@ export default class Guest extends Delegator {
* *
* This flag indicates that the sidebar should save the new annotation * This flag indicates that the sidebar should save the new annotation
* automatically and not show a form for the user to enter a comment about it. * automatically and not show a form for the user to enter a comment about it.
*
* @return {Promise<AnnotationData>}
*/ */
createHighlight() { createHighlight() {
return this.createAnnotation({ $highlight: true }); return this.createAnnotation({ $highlight: true });
......
...@@ -570,8 +570,28 @@ describe('Guest', () => { ...@@ -570,8 +570,28 @@ describe('Guest', () => {
}); });
}); });
describe('when adder toolbar buttons are clicked', () => describe('when adder toolbar buttons are clicked', () => {
// TODO - Add tests for "Annotate" and "Highlight" buttons. // nb. Detailed tests for properties of new annotations are in the
// `createAnnotation` tests.
it('creates a new annotation if "Annotate" is clicked', async () => {
const guest = createGuest();
const callback = sinon.stub();
guest.subscribe('beforeAnnotationCreated', callback);
await FakeAdder.instance.options.onAnnotate();
assert.called(callback);
});
it('creates a new highlight if "Highlight" is clicked', async () => {
const guest = createGuest();
const callback = sinon.stub();
guest.subscribe('beforeAnnotationCreated', callback);
await FakeAdder.instance.options.onHighlight();
assert.calledWith(callback, sinon.match({ $highlight: true }));
});
it('shows annotations if "Show" is clicked', () => { it('shows annotations if "Show" is clicked', () => {
createGuest(); createGuest();
...@@ -580,7 +600,8 @@ describe('Guest', () => { ...@@ -580,7 +600,8 @@ describe('Guest', () => {
assert.calledWith(fakeCrossFrame.call, 'openSidebar'); assert.calledWith(fakeCrossFrame.call, 'openSidebar');
assert.calledWith(fakeCrossFrame.call, 'showAnnotations', ['ann1']); assert.calledWith(fakeCrossFrame.call, 'showAnnotations', ['ann1']);
})); });
});
describe('#getDocumentInfo', () => { describe('#getDocumentInfo', () => {
let guest; let guest;
......
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