Lint annotation-sync-test.js

Just the minimal changes necessary to stop `make lint` from complaining,
while still having `make test` pass.

Some code can be deleted because (eslint informs us) it was unused.
parent d0749759
// Generated by CoffeeScript 1.10.0 'use strict';
var AnnotationSync, EventEmitter,
slice = [].slice; var AnnotationSync;
var EventEmitter;
var slice = [].slice;
EventEmitter = require('tiny-emitter'); EventEmitter = require('tiny-emitter');
AnnotationSync = require('../annotation-sync'); AnnotationSync = require('../annotation-sync');
describe('AnnotationSync', function() { describe('AnnotationSync', function() {
var PARENT_WINDOW, createAnnotationSync, createChannel, fakeBridge, options, publish, sandbox; var createAnnotationSync;
var fakeBridge;
var options;
var publish;
var sandbox;
sandbox = sinon.sandbox.create(); sandbox = sinon.sandbox.create();
publish = null; publish = null;
fakeBridge = null; fakeBridge = null;
createAnnotationSync = null; createAnnotationSync = null;
createChannel = function() {
return {
call: sandbox.stub()
};
};
options = null; options = null;
PARENT_WINDOW = 'PARENT_WINDOW';
beforeEach(function() { beforeEach(function() {
var emitter, fakeWindow, listeners; var emitter;
var listeners;
listeners = {}; listeners = {};
publish = function() { publish = function() {
var args, method; var method = arguments[0];
method = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; var args = slice.call(arguments, 1);
return listeners[method].apply(listeners, args); return listeners[method].apply(listeners, args);
}; };
fakeWindow = {
parent: PARENT_WINDOW
};
fakeBridge = { fakeBridge = {
on: sandbox.spy(function(method, fn) { on: sandbox.spy(function(method, fn) {
return listeners[method] = fn; return listeners[method] = fn;
}), }),
call: sandbox.stub(), call: sandbox.stub(),
onConnect: sandbox.stub(), onConnect: sandbox.stub(),
links: [] links: [],
}; };
emitter = new EventEmitter(); emitter = new EventEmitter();
options = { options = {
on: emitter.on.bind(emitter), on: emitter.on.bind(emitter),
emit: emitter.emit.bind(emitter) emit: emitter.emit.bind(emitter),
}; };
return createAnnotationSync = function() { return createAnnotationSync = function() {
return new AnnotationSync(fakeBridge, options); return new AnnotationSync(fakeBridge, options);
}; };
}); });
({
afterEach: function() { afterEach(function() {
return sandbox.restore(); return sandbox.restore();
}
}); });
describe('channel event handlers', function() { describe('channel event handlers', function() {
var assertBroadcast, assertCacheState, assertReturnValue; var assertBroadcast;
var assertReturnValue;
assertBroadcast = function(channelEvent, publishEvent) { assertBroadcast = function(channelEvent, publishEvent) {
return it('broadcasts the "' + publishEvent + '" event over the local event bus', function() { return it('broadcasts the "' + publishEvent + '" event over the local event bus', function() {
var ann, annSync, eventStub; var ann;
var eventStub;
ann = { ann = {
id: 1, id: 1,
$tag: 'tag1' $tag: 'tag1',
}; };
annSync = createAnnotationSync(); createAnnotationSync();
eventStub = sinon.stub(); eventStub = sinon.stub();
options.on(publishEvent, eventStub); options.on(publishEvent, eventStub);
publish(channelEvent, { publish(channelEvent, {
msg: ann msg: ann,
}, function() {}); }, function() {});
return assert.calledWith(eventStub, ann); return assert.calledWith(eventStub, ann);
}); });
}; };
assertReturnValue = function(channelEvent) { assertReturnValue = function(channelEvent) {
return it('calls back with a formatted annotation', function(done) { return it('calls back with a formatted annotation', function(done) {
var ann, annSync, callback; var ann;
var callback;
ann = { ann = {
id: 1, id: 1,
$tag: 'tag1' $tag: 'tag1',
}; };
annSync = createAnnotationSync(); createAnnotationSync();
callback = function(err, ret) { callback = function(err, ret) {
assert.isNull(err); assert.isNull(err);
assert.deepEqual(ret, { assert.deepEqual(ret, {
tag: 'tag1', tag: 'tag1',
msg: ann msg: ann,
}); });
return done(); return done();
}; };
return publish(channelEvent, { return publish(channelEvent, {
msg: ann msg: ann,
}, callback); }, callback);
}); });
}; };
assertCacheState = function(channelEvent) {
it('removes an existing entry from the cache before the event is triggered', function() {
var ann, annSync;
options.emit = function() {
return assert(!annSync.cache['tag1']);
};
ann = {
id: 1,
$tag: 'tag1'
};
annSync = createAnnotationSync();
annSync.cache['tag1'] = ann;
return publish(channelEvent, {
msg: ann
}, function() {});
});
return it('ensures the annotation is inserted in the cache', function() {
var ann, annSync;
ann = {
id: 1,
$tag: 'tag1'
};
annSync = createAnnotationSync();
publish(channelEvent, {
msg: ann
}, function() {});
return assert.equal(annSync.cache['tag1'], ann);
});
};
describe('the "deleteAnnotation" event', function() { describe('the "deleteAnnotation" event', function() {
assertBroadcast('deleteAnnotation', 'annotationDeleted'); assertBroadcast('deleteAnnotation', 'annotationDeleted');
assertReturnValue('deleteAnnotation'); assertReturnValue('deleteAnnotation');
it('removes an existing entry from the cache before the event is triggered', function() { it('removes an existing entry from the cache before the event is triggered', function() {
var ann, annSync; var ann;
var annSync;
options.emit = function() { options.emit = function() {
return assert(!annSync.cache['tag1']); return assert(!annSync.cache.tag1);
}; };
ann = { ann = {
id: 1, id: 1,
$tag: 'tag1' $tag: 'tag1',
}; };
annSync = createAnnotationSync(); annSync = createAnnotationSync();
annSync.cache['tag1'] = ann; annSync.cache.tag1 = ann;
return publish('deleteAnnotation', { return publish('deleteAnnotation', {
msg: ann msg: ann,
}, function() {}); }, function() {});
}); });
return it('removes the annotation from the cache', function() { return it('removes the annotation from the cache', function() {
var ann, annSync; var ann;
var annSync;
ann = { ann = {
id: 1, id: 1,
$tag: 'tag1' $tag: 'tag1',
}; };
annSync = createAnnotationSync(); annSync = createAnnotationSync();
publish('deleteAnnotation', { publish('deleteAnnotation', {
msg: ann msg: ann,
}, function() {}); }, function() {});
return assert(!annSync.cache['tag1']); return assert(!annSync.cache.tag1);
}); });
}); });
return describe('the "loadAnnotations" event', function() { return describe('the "loadAnnotations" event', function() {
return it('publishes the "annotationsLoaded" event', function() { return it('publishes the "annotationsLoaded" event', function() {
var ann, annSync, annotations, bodies, loadedStub; var ann;
var annotations;
var bodies;
var loadedStub;
loadedStub = sinon.stub(); loadedStub = sinon.stub();
options.on('annotationsLoaded', loadedStub); options.on('annotationsLoaded', loadedStub);
annSync = createAnnotationSync(); createAnnotationSync();
annotations = [ annotations = [
{ {
id: 1, id: 1,
$tag: 'tag1' $tag: 'tag1',
}, { }, {
id: 2, id: 2,
$tag: 'tag2' $tag: 'tag2',
}, { }, {
id: 3, id: 3,
$tag: 'tag3' $tag: 'tag3',
} },
]; ];
bodies = (function() { bodies = (function() {
var i, len, results; var i;
var len;
var results;
results = []; results = [];
for (i = 0, len = annotations.length; i < len; i++) { for (i = 0, len = annotations.length; i < len; i++) {
ann = annotations[i]; ann = annotations[i];
results.push({ results.push({
msg: ann, msg: ann,
tag: ann.$tag tag: ann.$tag,
}); });
} }
return results; return results;
...@@ -189,25 +174,25 @@ describe('AnnotationSync', function() { ...@@ -189,25 +174,25 @@ describe('AnnotationSync', function() {
return describe('event handlers', function() { return describe('event handlers', function() {
return describe('the "beforeAnnotationCreated" event', function() { return describe('the "beforeAnnotationCreated" event', function() {
it('proxies the event over the bridge', function() { it('proxies the event over the bridge', function() {
var ann, annSync; var ann;
ann = { ann = {
id: 1 id: 1,
}; };
annSync = createAnnotationSync(); createAnnotationSync();
options.emit('beforeAnnotationCreated', ann); options.emit('beforeAnnotationCreated', ann);
assert.called(fakeBridge.call); assert.called(fakeBridge.call);
return assert.calledWith(fakeBridge.call, 'beforeCreateAnnotation', { return assert.calledWith(fakeBridge.call, 'beforeCreateAnnotation', {
msg: ann, msg: ann,
tag: ann.$tag tag: ann.$tag,
}, sinon.match.func); }, sinon.match.func);
}); });
return it('returns early if the annotation has a tag', function() { return it('returns early if the annotation has a tag', function() {
var ann, annSync; var ann;
ann = { ann = {
id: 1, id: 1,
$tag: 'tag1' $tag: 'tag1',
}; };
annSync = createAnnotationSync(); createAnnotationSync();
options.emit('beforeAnnotationCreated', ann); options.emit('beforeAnnotationCreated', ann);
return assert.notCalled(fakeBridge.call); return 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