vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.8 KiB

  1. var assert = require('assert');
  2. var sinon = require('sinon');
  3. var jsdom_global = require('jsdom-global');
  4. var canvasMockify = require('./canvas-mock');
  5. var Activator = require('../lib/shared/Activator');
  6. describe('Activator', function () {
  7. beforeEach(function() {
  8. this.jsdom_global = jsdom_global(
  9. "<div id='mynetwork'></div>",
  10. { skipWindowCheck: true}
  11. );
  12. canvasMockify(window);
  13. this.container = document.getElementById('mynetwork');
  14. });
  15. afterEach(function() {
  16. this.jsdom_global();
  17. this.container.remove();
  18. this.container = undefined;
  19. });
  20. describe('constructor', function () {
  21. it('sets defaults', function () {
  22. var activator = new Activator(this.container);
  23. assert.equal(activator.active, false);
  24. });
  25. it('creates overlay', function () {
  26. var activator = new Activator(this.container);
  27. assert.equal(activator.dom.container.children[0].className, 'vis-overlay');
  28. });
  29. });
  30. describe('activate', function () {
  31. it('emits an `activate` event', function () {
  32. var eventSpy = sinon.spy();
  33. var activator = new Activator(this.container);
  34. activator.on('activate', eventSpy);
  35. activator.activate();
  36. assert.equal(activator.active, true);
  37. assert(eventSpy.called, 'Event did not fire.');
  38. assert(eventSpy.calledOnce, 'Event fired more than once');
  39. });
  40. it('emits a `change` event', function () {
  41. var eventSpy = sinon.spy();
  42. var activator = new Activator(this.container);
  43. activator.on('change', eventSpy);
  44. activator.activate();
  45. assert.equal(activator.active, true);
  46. assert(eventSpy.called, 'Event did not fire.');
  47. assert(eventSpy.calledOnce, 'Event fired more than once');
  48. });
  49. });
  50. describe('deactivate', function () {
  51. it('emits a `deactivate` event', function () {
  52. var eventSpy = sinon.spy();
  53. var activator = new Activator(this.container);
  54. activator.on('deactivate', eventSpy);
  55. activator.deactivate();
  56. assert.equal(activator.active, false);
  57. assert(eventSpy.called, 'Event did not fire.');
  58. assert(eventSpy.calledOnce, 'Event fired more than once');
  59. });
  60. it('emits a `change` event', function () {
  61. var eventSpy = sinon.spy();
  62. var activator = new Activator(this.container);
  63. activator.on('change', eventSpy);
  64. activator.deactivate();
  65. assert.equal(activator.active, false);
  66. assert(eventSpy.called, 'Event did not fire.');
  67. assert(eventSpy.calledOnce, 'Event fired more than once');
  68. });
  69. });
  70. describe('destroy', function () {
  71. it('sets inactive, removes keycharm, and removes hammer', function () {
  72. var activator = new Activator(this.container);
  73. activator.destroy();
  74. assert.equal(activator.active, false);
  75. assert.equal(activator.keycharm, null);
  76. assert.equal(activator.hammer, null);
  77. });
  78. });
  79. });