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.

268 lines
13 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. it('should redraw() and then have the correct property for an editable: {updateTime} override item (with boolean option)', function() {
  148. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true}}, null, {editable: true});
  149. var parent = TestSupport.buildMockItemSet();
  150. pointItem.setParent(parent);
  151. pointItem.redraw();
  152. assert.equal(pointItem.editable.updateTime, true);
  153. assert.equal(pointItem.editable.updateGroup, undefined);
  154. assert.equal(pointItem.editable.remove, undefined);
  155. });
  156. it('should redraw() and then have the correct property for an editable: {updateTime} override item (with boolean option false)', function() {
  157. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true}}, null, {editable: false});
  158. var parent = TestSupport.buildMockItemSet();
  159. pointItem.setParent(parent);
  160. pointItem.redraw();
  161. assert.equal(pointItem.editable.updateTime, true);
  162. assert.equal(pointItem.editable.updateGroup, undefined);
  163. assert.equal(pointItem.editable.remove, undefined);
  164. });
  165. it('should redraw() and then have the correct property for an editable: {updateGroup} override item (with boolean option)', function() {
  166. var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: true});
  167. var parent = TestSupport.buildMockItemSet();
  168. pointItem.setParent(parent);
  169. pointItem.redraw();
  170. assert.equal(pointItem.editable.updateTime, undefined);
  171. assert.equal(pointItem.editable.updateGroup, true);
  172. assert.equal(pointItem.editable.remove, undefined);
  173. });
  174. it('should redraw() and then have the correct property for an editable: {updateGroup} override item (with boolean option false)', function() {
  175. var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: false});
  176. var parent = TestSupport.buildMockItemSet();
  177. pointItem.setParent(parent);
  178. pointItem.redraw();
  179. assert.equal(pointItem.editable.updateTime, undefined);
  180. assert.equal(pointItem.editable.updateGroup, true);
  181. assert.equal(pointItem.editable.remove, undefined);
  182. });
  183. it('should redraw() and then have the correct property for an editable: {remove} override item (with boolean option)', function() {
  184. var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: true});
  185. var parent = TestSupport.buildMockItemSet();
  186. pointItem.setParent(parent);
  187. pointItem.redraw();
  188. assert.equal(pointItem.editable.updateTime, undefined);
  189. assert.equal(pointItem.editable.updateGroup, undefined);
  190. assert.equal(pointItem.editable.remove, true);
  191. });
  192. it('should redraw() and then have the correct property for an editable: {remove} override item (with boolean option false)', function() {
  193. var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: false});
  194. var parent = TestSupport.buildMockItemSet();
  195. pointItem.setParent(parent);
  196. pointItem.redraw();
  197. assert.equal(pointItem.editable.updateTime, undefined);
  198. assert.equal(pointItem.editable.updateGroup, undefined);
  199. assert.equal(pointItem.editable.remove, true);
  200. });
  201. it('should redraw() and then have the correct property for an editable: {updateTime, remove} override item (with boolean option)', function() {
  202. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: true});
  203. var parent = TestSupport.buildMockItemSet();
  204. pointItem.setParent(parent);
  205. pointItem.redraw();
  206. assert.equal(pointItem.editable.updateTime, true);
  207. assert.equal(pointItem.editable.updateGroup, undefined);
  208. assert.equal(pointItem.editable.remove, true);
  209. });
  210. it('should redraw() and then have the correct property for an editable: {updateTime, remove} override item (with boolean option false)', function() {
  211. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: false});
  212. var parent = TestSupport.buildMockItemSet();
  213. pointItem.setParent(parent);
  214. pointItem.redraw();
  215. assert.equal(pointItem.editable.updateTime, true);
  216. assert.equal(pointItem.editable.updateGroup, undefined);
  217. assert.equal(pointItem.editable.remove, true);
  218. });
  219. it('should redraw() and then have the correct property for an editable: {updateTime, updateGroup, remove} override item (with boolean option)', function() {
  220. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: true});
  221. var parent = TestSupport.buildMockItemSet();
  222. pointItem.setParent(parent);
  223. pointItem.redraw();
  224. assert.equal(pointItem.editable.updateTime, true);
  225. assert.equal(pointItem.editable.updateGroup, true);
  226. assert.equal(pointItem.editable.remove, true);
  227. });
  228. it('should redraw() and then have the correct property for an editable: {updateTime, updateGroup, remove} override item (with boolean option false)', function() {
  229. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: false});
  230. var parent = TestSupport.buildMockItemSet();
  231. pointItem.setParent(parent);
  232. pointItem.redraw();
  233. assert.equal(pointItem.editable.updateTime, true);
  234. assert.equal(pointItem.editable.updateGroup, true);
  235. assert.equal(pointItem.editable.remove, true);
  236. });
  237. });