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