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.

90 lines
2.8 KiB

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