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.

168 lines
8.0 KiB

  1. var assert = require('assert');
  2. var vis = require('../dist/vis');
  3. var jsdom = require('mocha-jsdom');
  4. var moment = vis.moment;
  5. var timeline = vis.timeline;
  6. var PointItem = require("../lib/timeline/component/item/PointItem");
  7. var Range = timeline.Range;
  8. var TestSupport = require('./TestSupport');
  9. describe('Timeline PointItem', function () {
  10. jsdom();
  11. var now = moment();
  12. it('should initialize with minimal data', function() {
  13. var pointItem = new PointItem({start: now.toDate()}, null, null);
  14. assert.equal(pointItem.props.content.height, 0);
  15. assert.deepEqual(pointItem.data.start, now.toDate());
  16. });
  17. it('should have a default width of 0', function() {
  18. var pointItem = new PointItem({start: now}, null, null);
  19. assert.equal(pointItem.getWidthRight(), 0);
  20. assert.equal(pointItem.getWidthLeft(), 0);
  21. });
  22. it('should error if there is missing data', function () {
  23. assert.throws(function () { new PointItem({}, null, null)}, Error);
  24. });
  25. it('should be visible if the range is during', function() {
  26. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  27. range.start = now.clone().add(-1, 'second');
  28. range.end = range.start.clone().add(1, 'hour');
  29. var pointItem = new PointItem({start: now.toDate()}, null, null);
  30. assert(pointItem.isVisible(range));
  31. });
  32. it('should not be visible if the range is after', function() {
  33. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  34. range.start = now.clone().add(1, 'second');
  35. range.end = range.start.clone().add(1, 'hour');
  36. var pointItem = new PointItem({start: now.toDate()}, null, null);
  37. assert(!pointItem.isVisible(range));
  38. });
  39. it('should not be visible if the range is before', function() {
  40. var now = moment();
  41. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  42. range.end = now.clone().add(-1, 'second');
  43. range.start = range.end.clone().add(-1, 'hour');
  44. var pointItem = new PointItem({start: now.toDate()}, null, null);
  45. assert(!pointItem.isVisible(range));
  46. });
  47. it('should be visible for a "now" point with a default range', function() {
  48. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  49. var pointItem = new PointItem({start: now.toDate()}, null, null);
  50. assert(pointItem.isVisible(range));
  51. });
  52. it('should redraw() and then not be dirty', function() {
  53. var pointItem = new PointItem({start: now.toDate()}, null, {editable: false});
  54. pointItem.setParent(TestSupport.buildMockItemSet());
  55. assert(pointItem.dirty);
  56. pointItem.redraw();
  57. assert(!pointItem.dirty);
  58. });
  59. it('should redraw() and then have point attached to its parent', function() {
  60. var pointItem = new PointItem({start: now.toDate()}, null, {editable: false});
  61. var parent = TestSupport.buildMockItemSet();
  62. pointItem.setParent(parent);
  63. assert(!parent.dom.foreground.hasChildNodes());
  64. pointItem.redraw();
  65. assert(parent.dom.foreground.hasChildNodes());
  66. });
  67. it('should redraw() and then have the correct classname for a non-editable item', function() {
  68. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: false});
  69. var parent = TestSupport.buildMockItemSet();
  70. pointItem.setParent(parent);
  71. pointItem.redraw();
  72. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  73. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  74. });
  75. it('should redraw() and then have the correct classname for an editable item (with object option)', function() {
  76. var pointItem = new PointItem({start: now.toDate()}, null, {editable: {updateTime: true, updateGroup: false}});
  77. var parent = TestSupport.buildMockItemSet();
  78. pointItem.setParent(parent);
  79. pointItem.redraw();
  80. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  81. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  82. });
  83. it('should redraw() and then have the correct classname for an editable item (with boolean option)', function() {
  84. var pointItem = new PointItem({start: now.toDate()}, null, {editable: true});
  85. var parent = TestSupport.buildMockItemSet();
  86. pointItem.setParent(parent);
  87. pointItem.redraw();
  88. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  89. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  90. });
  91. it('should redraw() and then have the correct classname for an editable:false override item (with boolean option)', function() {
  92. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: true});
  93. var parent = TestSupport.buildMockItemSet();
  94. pointItem.setParent(parent);
  95. pointItem.redraw();
  96. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  97. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  98. });
  99. it('should redraw() and then have the correct classname for an editable:true override item (with boolean option)', function() {
  100. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: false});
  101. var parent = TestSupport.buildMockItemSet();
  102. pointItem.setParent(parent);
  103. pointItem.redraw();
  104. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  105. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  106. });
  107. it('should redraw() and then have the correct classname for an editable:false override item (with object option)', function() {
  108. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: true, updateGroup: false}});
  109. var parent = TestSupport.buildMockItemSet();
  110. pointItem.setParent(parent);
  111. pointItem.redraw();
  112. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  113. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  114. });
  115. it('should redraw() and then have the correct classname for an editable:false override item (with object option for group change)', function() {
  116. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: false, updateGroup: true}});
  117. var parent = TestSupport.buildMockItemSet();
  118. pointItem.setParent(parent);
  119. pointItem.redraw();
  120. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  121. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  122. });
  123. it('should redraw() and then have the correct classname for an editable:true override item (with object option)', function() {
  124. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: {updateTime: false, updateGroup: false}});
  125. var parent = TestSupport.buildMockItemSet();
  126. pointItem.setParent(parent);
  127. pointItem.redraw();
  128. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  129. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  130. });
  131. it('should redraw() and then have the correct classname for an editable:true non-override item (with object option)', function() {
  132. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: {updateTime: false, updateGroup: false, overrideItems: true}});
  133. var parent = TestSupport.buildMockItemSet();
  134. pointItem.setParent(parent);
  135. pointItem.redraw();
  136. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  137. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  138. });
  139. it('should redraw() and then have the correct classname for an editable:false non-override item (with object option)', function() {
  140. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: true, updateGroup: false, overrideItems: true}});
  141. var parent = TestSupport.buildMockItemSet();
  142. pointItem.setParent(parent);
  143. pointItem.redraw();
  144. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  145. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  146. });
  147. });