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.

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