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.

142 lines
4.3 KiB

  1. var assert = require('assert');
  2. var jsdom_global = require('jsdom-global');
  3. var canvasMockify = require('./canvas-mock');
  4. var Popup = require('../lib/shared/Popup').default;
  5. describe('Popup', function () {
  6. beforeEach(function() {
  7. this.jsdom_global = canvasMockify("<div id='mynetwork'></div>");
  8. this.container = document.getElementById('mynetwork');
  9. });
  10. afterEach(function() {
  11. this.jsdom_global();
  12. this.container.remove();
  13. this.container = undefined;
  14. });
  15. describe('constructor', function () {
  16. it('defaults overflowMethod to "cap"', function () {
  17. var popup = new Popup(this.container);
  18. assert.equal(popup.overflowMethod, 'cap');
  19. });
  20. it('defaults hidden to false', function () {
  21. var popup = new Popup(this.container);
  22. assert.equal(popup.hidden, false);
  23. });
  24. });
  25. describe('setPosition', function () {
  26. it('handles ints', function () {
  27. var popup = new Popup(this.container);
  28. popup.setPosition(1, 2);
  29. assert.equal(popup.x, 1);
  30. assert.equal(popup.y, 2);
  31. });
  32. it('handles strings', function () {
  33. var popup = new Popup(this.container);
  34. popup.setPosition('1', '2');
  35. assert.equal(popup.x, 1);
  36. assert.equal(popup.y, 2);
  37. });
  38. it('handles null with NaN', function () {
  39. var popup = new Popup(this.container);
  40. popup.setPosition(null, null);
  41. assert(isNaN(popup.x));
  42. assert(isNaN(popup.y));
  43. });
  44. it('handles undefined with NaN', function () {
  45. var popup = new Popup(this.container);
  46. popup.setPosition(undefined, undefined);
  47. assert(isNaN(popup.x));
  48. assert(isNaN(popup.y));
  49. });
  50. });
  51. describe('setText', function () {
  52. it('using Element replaces innerHTML', function () {
  53. var popup = new Popup(this.container);
  54. popup.frame.innerHTML = '<div>This will get cleared!</div>';
  55. popup.setText(document.createElement('div'));
  56. assert.equal(popup.frame.innerHTML, '<div></div>');
  57. });
  58. it('using string replaces innerHTML', function () {
  59. var popup = new Popup(this.container);
  60. popup.frame.innerHTML = '<div>This will get cleared!</div>';
  61. popup.setText('your text here!');
  62. assert.equal(popup.frame.innerHTML, 'your text here!');
  63. });
  64. });
  65. describe('show', function () {
  66. it('set to undefined will show', function () {
  67. var popup = new Popup(this.container);
  68. popup.show(undefined);
  69. assert.equal(popup.hidden, false);
  70. assert.notEqual(popup.frame.style.left, "0px");
  71. assert.notEqual(popup.frame.style.top, "0px");
  72. assert.equal(popup.frame.style.visibility, "visible");
  73. });
  74. it('set to true will show', function () {
  75. var popup = new Popup(this.container);
  76. popup.show(true);
  77. assert.equal(popup.hidden, false);
  78. assert.notEqual(popup.frame.style.left, "0px");
  79. assert.notEqual(popup.frame.style.top, "0px");
  80. assert.equal(popup.frame.style.visibility, "visible");
  81. });
  82. it('set to true with overflowMethod "flip" will show', function () {
  83. var popup = new Popup(this.container, 'flip');
  84. popup.show(true);
  85. assert.equal(popup.hidden, false);
  86. assert.equal(popup.frame.style.left, "0px");
  87. assert.equal(popup.frame.style.top, "0px");
  88. assert.equal(popup.frame.style.visibility, "visible");
  89. });
  90. it('set to false will hide', function () {
  91. var popup = new Popup(this.container);
  92. popup.show(false);
  93. assert.equal(popup.hidden, true);
  94. assert.equal(popup.frame.style.left, "0px");
  95. assert.equal(popup.frame.style.top, "0px");
  96. assert.equal(popup.frame.style.visibility, "hidden");
  97. });
  98. });
  99. describe('hide', function () {
  100. it('sets hidden to true, frame style to 0,0 and visibility to hidden', function () {
  101. var popup = new Popup(this.container);
  102. popup.hide();
  103. assert.equal(popup.hidden, true);
  104. assert.equal(popup.frame.style.left, "0px");
  105. assert.equal(popup.frame.style.top, "0px");
  106. assert.equal(popup.frame.style.visibility, "hidden");
  107. });
  108. });
  109. describe('destroy', function () {
  110. it('removes frame from container', function () {
  111. assert.equal(this.container.children.length, 0);
  112. var popup = new Popup(this.container);
  113. assert.equal(this.container.children.length, 1);
  114. popup.destroy();
  115. assert.equal(this.container.children.length, 0);
  116. });
  117. });
  118. });