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 {
this.element.appendChild(this.adderToolbar);
this.adderCtrl = new Adder(this.adderToolbar, {
onAnnotate: () => {
this.createAnnotation();
onAnnotate: async () => {
await this.createAnnotation();
/** @type {Selection} */ (document.getSelection()).removeAllRanges();
},
onHighlight: () => {
onHighlight: async () => {
this.setVisibleHighlights(true);
this.createHighlight();
await this.createHighlight();
/** @type {Selection} */ (document.getSelection()).removeAllRanges();
},
onShowAnnotations: anns => {
......@@ -572,6 +572,8 @@ export default class Guest extends Delegator {
*
* 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.
*
* @return {Promise<AnnotationData>}
*/
createHighlight() {
return this.createAnnotation({ $highlight: true });
......
......@@ -570,8 +570,28 @@ describe('Guest', () => {
});
});
describe('when adder toolbar buttons are clicked', () =>
// TODO - Add tests for "Annotate" and "Highlight" buttons.
describe('when adder toolbar buttons are clicked', () => {
// 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', () => {
createGuest();
......@@ -580,7 +600,8 @@ describe('Guest', () => {
assert.calledWith(fakeCrossFrame.call, 'openSidebar');
assert.calledWith(fakeCrossFrame.call, 'showAnnotations', ['ann1']);
}));
});
});
describe('#getDocumentInfo', () => {
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