-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Adding unit tests for lib/shared #3600
Changes from 21 commits
b450758
b50ddc5
bbcaa78
6c8cf80
294525c
319fced
989bfd2
3aae9fc
a56cd13
4b766a5
e25d2e2
4c68bae
139bc86
429b63c
6288a41
645fc91
c19e524
f81eef5
031d640
0f8455f
8303487
388edb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var jsdom_global = require('jsdom-global'); | ||
|
||
var canvasMockify = require('./canvas-mock'); | ||
var Activator = require('../lib/shared/Activator'); | ||
|
||
|
||
describe('Activator', function () { | ||
beforeEach(function() { | ||
this.jsdom_global = jsdom_global( | ||
"<div id='mynetwork'></div>", | ||
{ skipWindowCheck: true} | ||
); | ||
canvasMockify(window); | ||
this.container = document.getElementById('mynetwork'); | ||
}); | ||
|
||
afterEach(function() { | ||
this.jsdom_global(); | ||
this.container.remove(); | ||
this.container = undefined; | ||
}); | ||
|
||
describe('constructor', function () { | ||
|
||
it('sets defaults', function () { | ||
var activator = new Activator(this.container); | ||
assert.equal(activator.active, false); | ||
}); | ||
|
||
it('creates overlay', function () { | ||
var activator = new Activator(this.container); | ||
assert.equal(activator.dom.container.children[0].className, 'vis-overlay'); | ||
}); | ||
}); | ||
|
||
describe('activate', function () { | ||
it('emits an `activate` event', function () { | ||
var eventSpy = sinon.spy(); | ||
var activator = new Activator(this.container); | ||
activator.on('activate', eventSpy); | ||
activator.activate(); | ||
assert.equal(activator.active, true); | ||
assert(eventSpy.called, 'Event did not fire.'); | ||
assert(eventSpy.calledOnce, 'Event fired more than once'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sort of half understand what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case |
||
}); | ||
|
||
it('emits a `change` event', function () { | ||
var eventSpy = sinon.spy(); | ||
var activator = new Activator(this.container); | ||
activator.on('change', eventSpy); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't help noticing in the code that What about consecutive same calls, e.g. If this is not documented, I would consider this faultly. Please give it some thought. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what to do about this, but would also consider it outside the scope of this particular issue. I agree with you, but don't know the impact of making corrective changes. Would you like me to open an issue to investigate? |
||
activator.activate(); | ||
assert.equal(activator.active, true); | ||
assert(eventSpy.called, 'Event did not fire.'); | ||
assert(eventSpy.calledOnce, 'Event fired more than once'); | ||
}); | ||
}); | ||
|
||
describe('deactivate', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Describe-block is practically identical to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think drying it would muddy the test state, or make the tests more complex. |
||
it('emits a `deactivate` event', function () { | ||
var eventSpy = sinon.spy(); | ||
var activator = new Activator(this.container); | ||
activator.on('deactivate', eventSpy); | ||
activator.deactivate(); | ||
assert.equal(activator.active, false); | ||
assert(eventSpy.called, 'Event did not fire.'); | ||
assert(eventSpy.calledOnce, 'Event fired more than once'); | ||
}); | ||
|
||
it('emits a `change` event', function () { | ||
var eventSpy = sinon.spy(); | ||
var activator = new Activator(this.container); | ||
activator.on('change', eventSpy); | ||
activator.deactivate(); | ||
assert.equal(activator.active, false); | ||
assert(eventSpy.called, 'Event did not fire.'); | ||
assert(eventSpy.calledOnce, 'Event fired more than once'); | ||
}); | ||
}); | ||
|
||
describe('destroy', function () { | ||
|
||
it('sets inactive, removes keycharm, and removes hammer', function () { | ||
var activator = new Activator(this.container); | ||
activator.destroy(); | ||
assert.equal(activator.active, false); | ||
assert.equal(activator.keycharm, null); | ||
assert.equal(activator.hammer, null); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RIP, you useless code!