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.

281 lines
12 KiB

  1. var assert = require('assert');
  2. var jsdom = require('mocha-jsdom');
  3. var moment = require('../lib/module/moment');
  4. var PointItem = require("../lib/timeline/component/item/PointItem");
  5. var Range = require('../lib/timeline/Range');
  6. var TestSupport = require('./TestSupport');
  7. describe('Timeline PointItem', function () {
  8. jsdom();
  9. var now = moment();
  10. it('should initialize with minimal data', function() {
  11. var pointItem = new PointItem({start: now.toDate()}, null, null);
  12. assert.equal(pointItem.props.content.height, 0);
  13. assert.deepEqual(pointItem.data.start, now.toDate());
  14. });
  15. it('should have a default width of 0', function() {
  16. var pointItem = new PointItem({start: now}, null, null);
  17. assert.equal(pointItem.getWidthRight(), 0);
  18. assert.equal(pointItem.getWidthLeft(), 0);
  19. });
  20. it('should error if there is missing data', function () {
  21. assert.throws(function () { new PointItem({}, null, null)}, Error);
  22. });
  23. it('should be visible if the range is during', function() {
  24. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  25. range.start = now.clone().add(-1, 'second');
  26. range.end = range.start.clone().add(1, 'hour');
  27. var pointItem = new PointItem({start: now.toDate()}, null, null);
  28. assert(pointItem.isVisible(range));
  29. });
  30. it('should not be visible if the range is after', function() {
  31. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  32. range.start = now.clone().add(1, 'second');
  33. range.end = range.start.clone().add(1, 'hour');
  34. var pointItem = new PointItem({start: now.toDate()}, null, null);
  35. assert(!pointItem.isVisible(range));
  36. });
  37. it('should not be visible if the range is before', function() {
  38. var now = moment();
  39. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  40. range.end = now.clone().add(-1, 'second');
  41. range.start = range.end.clone().add(-1, 'hour');
  42. var pointItem = new PointItem({start: now.toDate()}, null, null);
  43. assert(!pointItem.isVisible(range));
  44. });
  45. it('should be visible for a "now" point with a default range', function() {
  46. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  47. var pointItem = new PointItem({start: now.toDate()}, null, null);
  48. assert(pointItem.isVisible(range));
  49. });
  50. describe('should redraw() and then', function () {
  51. it('not be dirty', function() {
  52. var pointItem = new PointItem({start: now.toDate()}, null, {editable: false});
  53. pointItem.setParent(TestSupport.buildMockItemSet());
  54. assert(pointItem.dirty);
  55. pointItem.redraw();
  56. assert(!pointItem.dirty);
  57. });
  58. it('have point attached to its parent', function() {
  59. var pointItem = new PointItem({start: now.toDate()}, null, {editable: false});
  60. var parent = TestSupport.buildMockItemSet();
  61. pointItem.setParent(parent);
  62. assert(!parent.dom.foreground.hasChildNodes());
  63. pointItem.redraw();
  64. assert(parent.dom.foreground.hasChildNodes());
  65. });
  66. describe('have the correct classname for', function() {
  67. it('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('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('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('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('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('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('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('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('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('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('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('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('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. }); // have the correct classname for
  175. describe('have the correct property for', function() {
  176. it('an editable: {updateGroup} override item (with boolean option false)', function() {
  177. var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: false});
  178. var parent = TestSupport.buildMockItemSet();
  179. pointItem.setParent(parent);
  180. pointItem.redraw();
  181. assert.equal(pointItem.editable.updateTime, undefined);
  182. assert.equal(pointItem.editable.updateGroup, true);
  183. assert.equal(pointItem.editable.remove, undefined);
  184. });
  185. it('an editable: {remove} override item (with boolean option)', function() {
  186. var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: true});
  187. var parent = TestSupport.buildMockItemSet();
  188. pointItem.setParent(parent);
  189. pointItem.redraw();
  190. assert.equal(pointItem.editable.updateTime, undefined);
  191. assert.equal(pointItem.editable.updateGroup, undefined);
  192. assert.equal(pointItem.editable.remove, true);
  193. });
  194. it('an editable: {remove} override item (with boolean option false)', function() {
  195. var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: false});
  196. var parent = TestSupport.buildMockItemSet();
  197. pointItem.setParent(parent);
  198. pointItem.redraw();
  199. assert.equal(pointItem.editable.updateTime, undefined);
  200. assert.equal(pointItem.editable.updateGroup, undefined);
  201. assert.equal(pointItem.editable.remove, true);
  202. });
  203. it('an editable: {updateTime, remove} override item (with boolean option)', function() {
  204. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: true});
  205. var parent = TestSupport.buildMockItemSet();
  206. pointItem.setParent(parent);
  207. pointItem.redraw();
  208. assert.equal(pointItem.editable.updateTime, true);
  209. assert.equal(pointItem.editable.updateGroup, undefined);
  210. assert.equal(pointItem.editable.remove, true);
  211. });
  212. it('an editable: {updateTime, remove} override item (with boolean option false)', function() {
  213. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: false});
  214. var parent = TestSupport.buildMockItemSet();
  215. pointItem.setParent(parent);
  216. pointItem.redraw();
  217. assert.equal(pointItem.editable.updateTime, true);
  218. assert.equal(pointItem.editable.updateGroup, undefined);
  219. assert.equal(pointItem.editable.remove, true);
  220. });
  221. it('an editable: {updateTime, updateGroup, remove} override item (with boolean option)', function() {
  222. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: true});
  223. var parent = TestSupport.buildMockItemSet();
  224. pointItem.setParent(parent);
  225. pointItem.redraw();
  226. assert.equal(pointItem.editable.updateTime, true);
  227. assert.equal(pointItem.editable.updateGroup, true);
  228. assert.equal(pointItem.editable.remove, true);
  229. });
  230. it('an editable: {updateTime, updateGroup, remove} override item (with boolean option false)', function() {
  231. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: false});
  232. var parent = TestSupport.buildMockItemSet();
  233. pointItem.setParent(parent);
  234. pointItem.redraw();
  235. assert.equal(pointItem.editable.updateTime, true);
  236. assert.equal(pointItem.editable.updateGroup, true);
  237. assert.equal(pointItem.editable.remove, true);
  238. });
  239. }); // have the correct property for
  240. }); // should redraw() and then
  241. }); // Timeline PointItem