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.

283 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. describe('should redraw() and then', function () {
  53. it('not be dirty', function() {
  54. var pointItem = new PointItem({start: now.toDate()}, null, {editable: false});
  55. pointItem.setParent(TestSupport.buildMockItemSet());
  56. assert(pointItem.dirty);
  57. pointItem.redraw();
  58. assert(!pointItem.dirty);
  59. });
  60. it('have point attached to its parent', function() {
  61. var pointItem = new PointItem({start: now.toDate()}, null, {editable: false});
  62. var parent = TestSupport.buildMockItemSet();
  63. pointItem.setParent(parent);
  64. assert(!parent.dom.foreground.hasChildNodes());
  65. pointItem.redraw();
  66. assert(parent.dom.foreground.hasChildNodes());
  67. });
  68. describe('have the correct classname for', function() {
  69. it('a non-editable item', function() {
  70. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: false});
  71. var parent = TestSupport.buildMockItemSet();
  72. pointItem.setParent(parent);
  73. pointItem.redraw();
  74. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  75. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  76. });
  77. it('an editable item (with object option)', function() {
  78. var pointItem = new PointItem({start: now.toDate()}, null, {editable: {updateTime: true, updateGroup: false}});
  79. var parent = TestSupport.buildMockItemSet();
  80. pointItem.setParent(parent);
  81. pointItem.redraw();
  82. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  83. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  84. });
  85. it('an editable item (with boolean option)', function() {
  86. var pointItem = new PointItem({start: now.toDate()}, null, {editable: true});
  87. var parent = TestSupport.buildMockItemSet();
  88. pointItem.setParent(parent);
  89. pointItem.redraw();
  90. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  91. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  92. });
  93. it('an editable:false override item (with boolean option)', function() {
  94. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: true});
  95. var parent = TestSupport.buildMockItemSet();
  96. pointItem.setParent(parent);
  97. pointItem.redraw();
  98. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  99. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  100. });
  101. it('an editable:true override item (with boolean option)', function() {
  102. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: false});
  103. var parent = TestSupport.buildMockItemSet();
  104. pointItem.setParent(parent);
  105. pointItem.redraw();
  106. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  107. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  108. });
  109. it('an editable:false override item (with object option)', function() {
  110. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: true, updateGroup: false}});
  111. var parent = TestSupport.buildMockItemSet();
  112. pointItem.setParent(parent);
  113. pointItem.redraw();
  114. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  115. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  116. });
  117. it('an editable:false override item (with object option for group change)', function() {
  118. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: false, updateGroup: true}});
  119. var parent = TestSupport.buildMockItemSet();
  120. pointItem.setParent(parent);
  121. pointItem.redraw();
  122. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  123. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  124. });
  125. it('an editable:true override item (with object option)', function() {
  126. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: {updateTime: false, updateGroup: false}});
  127. var parent = TestSupport.buildMockItemSet();
  128. pointItem.setParent(parent);
  129. pointItem.redraw();
  130. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  131. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  132. });
  133. it('an editable:true non-override item (with object option)', function() {
  134. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: {updateTime: false, updateGroup: false, overrideItems: true}});
  135. var parent = TestSupport.buildMockItemSet();
  136. pointItem.setParent(parent);
  137. pointItem.redraw();
  138. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  139. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  140. });
  141. it('an editable:false non-override item (with object option)', function() {
  142. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: true, updateGroup: false, overrideItems: true}});
  143. var parent = TestSupport.buildMockItemSet();
  144. pointItem.setParent(parent);
  145. pointItem.redraw();
  146. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  147. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  148. });
  149. it('an editable: {updateTime} override item (with boolean option)', function() {
  150. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true}}, null, {editable: true});
  151. var parent = TestSupport.buildMockItemSet();
  152. pointItem.setParent(parent);
  153. pointItem.redraw();
  154. assert.equal(pointItem.editable.updateTime, true);
  155. assert.equal(pointItem.editable.updateGroup, undefined);
  156. assert.equal(pointItem.editable.remove, undefined);
  157. });
  158. it('an editable: {updateTime} override item (with boolean option false)', function() {
  159. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true}}, null, {editable: false});
  160. var parent = TestSupport.buildMockItemSet();
  161. pointItem.setParent(parent);
  162. pointItem.redraw();
  163. assert.equal(pointItem.editable.updateTime, true);
  164. assert.equal(pointItem.editable.updateGroup, undefined);
  165. assert.equal(pointItem.editable.remove, undefined);
  166. });
  167. it('an editable: {updateGroup} override item (with boolean option)', function() {
  168. var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: true});
  169. var parent = TestSupport.buildMockItemSet();
  170. pointItem.setParent(parent);
  171. pointItem.redraw();
  172. assert.equal(pointItem.editable.updateTime, undefined);
  173. assert.equal(pointItem.editable.updateGroup, true);
  174. assert.equal(pointItem.editable.remove, undefined);
  175. });
  176. }); // have the correct classname for
  177. describe('have the correct property for', function() {
  178. it('an editable: {updateGroup} override item (with boolean option false)', function() {
  179. var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: false});
  180. var parent = TestSupport.buildMockItemSet();
  181. pointItem.setParent(parent);
  182. pointItem.redraw();
  183. assert.equal(pointItem.editable.updateTime, undefined);
  184. assert.equal(pointItem.editable.updateGroup, true);
  185. assert.equal(pointItem.editable.remove, undefined);
  186. });
  187. it('an editable: {remove} override item (with boolean option)', function() {
  188. var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: true});
  189. var parent = TestSupport.buildMockItemSet();
  190. pointItem.setParent(parent);
  191. pointItem.redraw();
  192. assert.equal(pointItem.editable.updateTime, undefined);
  193. assert.equal(pointItem.editable.updateGroup, undefined);
  194. assert.equal(pointItem.editable.remove, true);
  195. });
  196. it('an editable: {remove} override item (with boolean option false)', function() {
  197. var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: false});
  198. var parent = TestSupport.buildMockItemSet();
  199. pointItem.setParent(parent);
  200. pointItem.redraw();
  201. assert.equal(pointItem.editable.updateTime, undefined);
  202. assert.equal(pointItem.editable.updateGroup, undefined);
  203. assert.equal(pointItem.editable.remove, true);
  204. });
  205. it('an editable: {updateTime, remove} override item (with boolean option)', function() {
  206. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: true});
  207. var parent = TestSupport.buildMockItemSet();
  208. pointItem.setParent(parent);
  209. pointItem.redraw();
  210. assert.equal(pointItem.editable.updateTime, true);
  211. assert.equal(pointItem.editable.updateGroup, undefined);
  212. assert.equal(pointItem.editable.remove, true);
  213. });
  214. it('an editable: {updateTime, remove} override item (with boolean option false)', function() {
  215. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: false});
  216. var parent = TestSupport.buildMockItemSet();
  217. pointItem.setParent(parent);
  218. pointItem.redraw();
  219. assert.equal(pointItem.editable.updateTime, true);
  220. assert.equal(pointItem.editable.updateGroup, undefined);
  221. assert.equal(pointItem.editable.remove, true);
  222. });
  223. it('an editable: {updateTime, updateGroup, remove} override item (with boolean option)', function() {
  224. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: true});
  225. var parent = TestSupport.buildMockItemSet();
  226. pointItem.setParent(parent);
  227. pointItem.redraw();
  228. assert.equal(pointItem.editable.updateTime, true);
  229. assert.equal(pointItem.editable.updateGroup, true);
  230. assert.equal(pointItem.editable.remove, true);
  231. });
  232. it('an editable: {updateTime, updateGroup, remove} override item (with boolean option false)', function() {
  233. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: false});
  234. var parent = TestSupport.buildMockItemSet();
  235. pointItem.setParent(parent);
  236. pointItem.redraw();
  237. assert.equal(pointItem.editable.updateTime, true);
  238. assert.equal(pointItem.editable.updateGroup, true);
  239. assert.equal(pointItem.editable.remove, true);
  240. });
  241. }); // have the correct property for
  242. }); // should redraw() and then
  243. }); // Timeline PointItem