Commit ce2509ba authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #310 from hypothesis/reorganise-annotation-sync-tests

Reorganize annotation sync tests
parents 6a8af948 877fb348
...@@ -45,9 +45,9 @@ describe('AnnotationSync', function() { ...@@ -45,9 +45,9 @@ describe('AnnotationSync', function() {
sandbox.restore(); sandbox.restore();
}); });
describe('channel event handlers', function() { describe('#constructor', function() {
describe('the "deleteAnnotation" event', function() { context('when "deleteAnnotation" is published', function() {
it('broadcasts the "annotationDeleted" event over the local event bus', function() { it('calls emit("annotationDeleted")', function() {
var ann = {id: 1, $tag: 'tag1'}; var ann = {id: 1, $tag: 'tag1'};
var eventStub = sinon.stub(); var eventStub = sinon.stub();
options.on('annotationDeleted', eventStub); options.on('annotationDeleted', eventStub);
...@@ -58,7 +58,7 @@ describe('AnnotationSync', function() { ...@@ -58,7 +58,7 @@ describe('AnnotationSync', function() {
assert.calledWith(eventStub, ann); assert.calledWith(eventStub, ann);
}); });
it('calls back with a formatted annotation', function(done) { it("calls the 'deleteAnnotation' event's callback function", function(done) {
var ann = {id: 1, $tag: 'tag1'}; var ann = {id: 1, $tag: 'tag1'};
var callback = function(err, ret) { var callback = function(err, ret) {
assert.isNull(err); assert.isNull(err);
...@@ -70,7 +70,7 @@ describe('AnnotationSync', function() { ...@@ -70,7 +70,7 @@ describe('AnnotationSync', function() {
publish('deleteAnnotation', {msg: ann}, callback); publish('deleteAnnotation', {msg: ann}, callback);
}); });
it('removes an existing entry from the cache before the event is triggered', function() { it('deletes any existing annotation from its cache before calling emit', function() {
var ann = {id: 1, $tag: 'tag1'}; var ann = {id: 1, $tag: 'tag1'};
var annSync = createAnnotationSync(); var annSync = createAnnotationSync();
annSync.cache.tag1 = ann; annSync.cache.tag1 = ann;
...@@ -79,7 +79,7 @@ describe('AnnotationSync', function() { ...@@ -79,7 +79,7 @@ describe('AnnotationSync', function() {
publish('deleteAnnotation', {msg: ann}, function() {}); publish('deleteAnnotation', {msg: ann}, function() {});
}); });
it('removes the annotation from the cache', function() { it('deletes any existing annotation from its cache', function() {
var ann = {id: 1, $tag: 'tag1'}; var ann = {id: 1, $tag: 'tag1'};
var annSync = createAnnotationSync(); var annSync = createAnnotationSync();
annSync.cache.tag1 = ann; annSync.cache.tag1 = ann;
...@@ -90,8 +90,8 @@ describe('AnnotationSync', function() { ...@@ -90,8 +90,8 @@ describe('AnnotationSync', function() {
}); });
}); });
describe('the "loadAnnotations" event', function() { context('when "loadAnnotations" is published', function() {
it('publishes the "annotationsLoaded" event', function() { it('calls emit("annotationsLoaded")', function() {
var annotations = [ var annotations = [
{id: 1, $tag: 'tag1'}, {id: 1, $tag: 'tag1'},
{id: 2, $tag: 'tag2'}, {id: 2, $tag: 'tag2'},
...@@ -111,11 +111,9 @@ describe('AnnotationSync', function() { ...@@ -111,11 +111,9 @@ describe('AnnotationSync', function() {
assert.calledWith(loadedStub, annotations); assert.calledWith(loadedStub, annotations);
}); });
}); });
});
describe('event handlers', function() { context('when "beforeAnnotationCreated" is emitted', function() {
describe('the "beforeAnnotationCreated" event', function() { it('calls bridge.call() passing the event', function() {
it('proxies the event over the bridge', function() {
var ann = {id: 1}; var ann = {id: 1};
createAnnotationSync(); createAnnotationSync();
...@@ -127,13 +125,15 @@ describe('AnnotationSync', function() { ...@@ -127,13 +125,15 @@ describe('AnnotationSync', function() {
sinon.match.func); sinon.match.func);
}); });
it('returns early if the annotation has a tag', function() { context('if the annotation has a $tag', function() {
var ann = {id: 1, $tag: 'tag1'}; it('does not call bridge.call()', function() {
createAnnotationSync(); var ann = {id: 1, $tag: 'tag1'};
createAnnotationSync();
options.emit('beforeAnnotationCreated', ann); options.emit('beforeAnnotationCreated', ann);
assert.notCalled(fakeBridge.call); assert.notCalled(fakeBridge.call);
});
}); });
}); });
}); });
......
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