Commit 05d47eff authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Rename `beforeCreateAnnotation` to `createAnnotation`

This is the event that creates the annotation, so it is better to name
it in a more obvious way.

Context:
https://github.com/hypothesis/client/pull/3829#discussion_r726880585
parent 57078625
......@@ -72,7 +72,7 @@ export class AnnotationSync {
if (annotation.$tag) {
return;
}
this._sidebar.call('beforeCreateAnnotation', this._format(annotation));
this._sidebar.call('createAnnotation', this._format(annotation));
});
}
......
......@@ -108,7 +108,7 @@ describe('AnnotationSync', () => {
describe('handling events from the annotator', () => {
describe('on "beforeAnnotationCreated" event', () => {
it('calls "beforeCreateAnnotation" RPC method in the sidebar', () => {
it('calls "createAnnotation" RPC method in the sidebar', () => {
// nb. Setting an empty `$tag` here matches what `Guest#createAnnotation`
// does.
const ann = { id: 1, $tag: '' };
......@@ -117,7 +117,7 @@ describe('AnnotationSync', () => {
emitter.publish('beforeAnnotationCreated', ann);
assert.called(fakeBridge.call);
assert.calledWith(fakeBridge.call, 'beforeCreateAnnotation', {
assert.calledWith(fakeBridge.call, 'createAnnotation', {
msg: ann,
tag: ann.$tag,
});
......
......@@ -147,7 +147,7 @@ export class FrameSyncService {
*/
this._setupSyncFromGuests = () => {
// A new annotation, note or highlight was created in the frame
this._guestRPC.on('beforeCreateAnnotation', event => {
this._guestRPC.on('createAnnotation', event => {
const annot = Object.assign({}, event.msg, { $tag: event.tag });
// If user is not logged in, we can't really create a meaningful highlight
// or annotation. Instead, we need to open the sidebar, show an error,
......
......@@ -315,7 +315,7 @@ describe('FrameSyncService', () => {
fakeStore.isLoggedIn.returns(true);
const ann = { target: [] };
guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });
assert.calledWith(hostBridge().call, 'showHighlights');
});
......@@ -326,7 +326,7 @@ describe('FrameSyncService', () => {
fakeStore.isLoggedIn.returns(true);
const ann = { target: [] };
guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });
assert.calledWith(
fakeAnnotationsService.create,
......@@ -342,7 +342,7 @@ describe('FrameSyncService', () => {
fakeStore.isLoggedIn.returns(true);
const ann = { target: [] };
guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });
assert.calledWith(hostBridge().call, 'openSidebar');
});
......@@ -352,7 +352,7 @@ describe('FrameSyncService', () => {
fakeStore.isLoggedIn.returns(true);
const ann = { $highlight: true, target: [] };
guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });
assert.neverCalledWith(hostBridge().call, 'openSidebar');
});
......@@ -367,28 +367,28 @@ describe('FrameSyncService', () => {
it('should not create an annotation in the sidebar', () => {
const ann = { target: [] };
guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });
assert.notCalled(fakeAnnotationsService.create);
});
it('should open the sidebar', () => {
const ann = { target: [] };
guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });
assert.calledWith(hostBridge().call, 'openSidebar');
});
it('should open the login prompt panel', () => {
const ann = { target: [] };
guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });
assert.calledWith(fakeStore.openSidebarPanel, 'loginPrompt');
});
it('should send a "deleteAnnotation" message to the frame', () => {
const ann = { target: [] };
guestBridge().emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
guestBridge().emit('createAnnotation', { tag: 't1', msg: ann });
assert.calledWith(guestBridge().call, 'deleteAnnotation');
});
......
......@@ -29,7 +29,7 @@ export type GuestToSidebarEvent =
/**
* The guest is asking the sidebar to create an annotation.
*/
| 'beforeCreateAnnotation'
| 'createAnnotation'
/**
* The guest is asking the sidebar to relay the message to the host to close the sidebar.
......
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