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.

288 lines
13 KiB

  1. var assert = require('assert');
  2. var jsdom_global = require('jsdom-global');
  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. var now = moment();
  9. before(function() {
  10. this.jsdom_global = jsdom_global();
  11. });
  12. after(function() {
  13. this.jsdom_global();
  14. });
  15. it('should initialize with minimal data', function() {
  16. var pointItem = new PointItem({start: now.toDate()}, null, null);
  17. assert.equal(pointItem.props.content.height, 0);
  18. assert.deepEqual(pointItem.data.start, now.toDate());
  19. });
  20. it('should have a default width of 0', function() {
  21. var pointItem = new PointItem({start: now}, null, null);
  22. assert.equal(pointItem.getWidthRight(), 0);
  23. assert.equal(pointItem.getWidthLeft(), 0);
  24. });
  25. it('should error if there is missing data', function () {
  26. assert.throws(function () { new PointItem({}, null, null)}, Error);
  27. });
  28. it('should be visible if the range is during', function() {
  29. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  30. range.start = now.clone().add(-1, 'second');
  31. range.end = range.start.clone().add(1, 'hour');
  32. var pointItem = new PointItem({start: now.toDate()}, null, null);
  33. assert(pointItem.isVisible(range));
  34. });
  35. it('should not be visible if the range is after', function() {
  36. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  37. range.start = now.clone().add(1, 'second');
  38. range.end = range.start.clone().add(1, 'hour');
  39. var pointItem = new PointItem({start: now.toDate()}, null, null);
  40. assert(!pointItem.isVisible(range));
  41. });
  42. it('should not be visible if the range is before', function() {
  43. var now = moment();
  44. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  45. range.end = now.clone().add(-1, 'second');
  46. range.start = range.end.clone().add(-1, 'hour');
  47. var pointItem = new PointItem({start: now.toDate()}, null, null);
  48. assert(!pointItem.isVisible(range));
  49. });
  50. it('should be visible for a "now" point with a default range', function() {
  51. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  52. var pointItem = new PointItem({start: now.toDate()}, null, null);
  53. assert(pointItem.isVisible(range));
  54. });
  55. describe('should redraw() and then', function () {
  56. it('not be dirty', function() {
  57. var pointItem = new PointItem({start: now.toDate()}, null, {editable: false});
  58. pointItem.setParent(TestSupport.buildMockItemSet());
  59. assert(pointItem.dirty);
  60. pointItem.redraw();
  61. assert(!pointItem.dirty);
  62. });
  63. it('have point attached to its parent', function() {
  64. var pointItem = new PointItem({start: now.toDate()}, null, {editable: false});
  65. var parent = TestSupport.buildMockItemSet();
  66. pointItem.setParent(parent);
  67. assert(!parent.dom.foreground.hasChildNodes());
  68. pointItem.redraw();
  69. assert(parent.dom.foreground.hasChildNodes());
  70. });
  71. describe('have the correct classname for', function() {
  72. it('a non-editable item', function() {
  73. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: false});
  74. var parent = TestSupport.buildMockItemSet();
  75. pointItem.setParent(parent);
  76. pointItem.redraw();
  77. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  78. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  79. });
  80. it('an editable item (with object option)', function() {
  81. var pointItem = new PointItem({start: now.toDate()}, null, {editable: {updateTime: true, updateGroup: false}});
  82. var parent = TestSupport.buildMockItemSet();
  83. pointItem.setParent(parent);
  84. pointItem.redraw();
  85. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  86. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  87. });
  88. it('an editable item (with boolean option)', function() {
  89. var pointItem = new PointItem({start: now.toDate()}, null, {editable: true});
  90. var parent = TestSupport.buildMockItemSet();
  91. pointItem.setParent(parent);
  92. pointItem.redraw();
  93. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  94. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  95. });
  96. it('an editable:false override item (with boolean option)', function() {
  97. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: true});
  98. var parent = TestSupport.buildMockItemSet();
  99. pointItem.setParent(parent);
  100. pointItem.redraw();
  101. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  102. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  103. });
  104. it('an editable:true override item (with boolean option)', function() {
  105. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: false});
  106. var parent = TestSupport.buildMockItemSet();
  107. pointItem.setParent(parent);
  108. pointItem.redraw();
  109. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  110. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  111. });
  112. it('an editable:false override item (with object option)', function() {
  113. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: true, updateGroup: false}});
  114. var parent = TestSupport.buildMockItemSet();
  115. pointItem.setParent(parent);
  116. pointItem.redraw();
  117. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  118. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  119. });
  120. it('an editable:false override item (with object option for group change)', function() {
  121. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: false, updateGroup: true}});
  122. var parent = TestSupport.buildMockItemSet();
  123. pointItem.setParent(parent);
  124. pointItem.redraw();
  125. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  126. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  127. });
  128. it('an editable:true override item (with object option)', function() {
  129. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: {updateTime: false, updateGroup: false}});
  130. var parent = TestSupport.buildMockItemSet();
  131. pointItem.setParent(parent);
  132. pointItem.redraw();
  133. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  134. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  135. });
  136. it('an editable:true non-override item (with object option)', function() {
  137. var pointItem = new PointItem({start: now.toDate(), editable: true}, null, {editable: {updateTime: false, updateGroup: false, overrideItems: true}});
  138. var parent = TestSupport.buildMockItemSet();
  139. pointItem.setParent(parent);
  140. pointItem.redraw();
  141. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-readonly");
  142. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-readonly");
  143. });
  144. it('an editable:false non-override item (with object option)', function() {
  145. var pointItem = new PointItem({start: now.toDate(), editable: false}, null, {editable: {updateTime: true, updateGroup: false, overrideItems: true}});
  146. var parent = TestSupport.buildMockItemSet();
  147. pointItem.setParent(parent);
  148. pointItem.redraw();
  149. assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable");
  150. assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable");
  151. });
  152. it('an editable: {updateTime} override item (with boolean option)', function() {
  153. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true}}, null, {editable: true});
  154. var parent = TestSupport.buildMockItemSet();
  155. pointItem.setParent(parent);
  156. pointItem.redraw();
  157. assert.equal(pointItem.editable.updateTime, true);
  158. assert.equal(pointItem.editable.updateGroup, undefined);
  159. assert.equal(pointItem.editable.remove, undefined);
  160. });
  161. it('an editable: {updateTime} override item (with boolean option false)', function() {
  162. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true}}, null, {editable: false});
  163. var parent = TestSupport.buildMockItemSet();
  164. pointItem.setParent(parent);
  165. pointItem.redraw();
  166. assert.equal(pointItem.editable.updateTime, true);
  167. assert.equal(pointItem.editable.updateGroup, undefined);
  168. assert.equal(pointItem.editable.remove, undefined);
  169. });
  170. it('an editable: {updateGroup} override item (with boolean option)', function() {
  171. var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: true});
  172. var parent = TestSupport.buildMockItemSet();
  173. pointItem.setParent(parent);
  174. pointItem.redraw();
  175. assert.equal(pointItem.editable.updateTime, undefined);
  176. assert.equal(pointItem.editable.updateGroup, true);
  177. assert.equal(pointItem.editable.remove, undefined);
  178. });
  179. }); // have the correct classname for
  180. describe('have the correct property for', function() {
  181. it('an editable: {updateGroup} override item (with boolean option false)', function() {
  182. var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: false});
  183. var parent = TestSupport.buildMockItemSet();
  184. pointItem.setParent(parent);
  185. pointItem.redraw();
  186. assert.equal(pointItem.editable.updateTime, undefined);
  187. assert.equal(pointItem.editable.updateGroup, true);
  188. assert.equal(pointItem.editable.remove, undefined);
  189. });
  190. it('an editable: {remove} override item (with boolean option)', function() {
  191. var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: true});
  192. var parent = TestSupport.buildMockItemSet();
  193. pointItem.setParent(parent);
  194. pointItem.redraw();
  195. assert.equal(pointItem.editable.updateTime, undefined);
  196. assert.equal(pointItem.editable.updateGroup, undefined);
  197. assert.equal(pointItem.editable.remove, true);
  198. });
  199. it('an editable: {remove} override item (with boolean option false)', function() {
  200. var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: false});
  201. var parent = TestSupport.buildMockItemSet();
  202. pointItem.setParent(parent);
  203. pointItem.redraw();
  204. assert.equal(pointItem.editable.updateTime, undefined);
  205. assert.equal(pointItem.editable.updateGroup, undefined);
  206. assert.equal(pointItem.editable.remove, true);
  207. });
  208. it('an editable: {updateTime, remove} override item (with boolean option)', function() {
  209. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: true});
  210. var parent = TestSupport.buildMockItemSet();
  211. pointItem.setParent(parent);
  212. pointItem.redraw();
  213. assert.equal(pointItem.editable.updateTime, true);
  214. assert.equal(pointItem.editable.updateGroup, undefined);
  215. assert.equal(pointItem.editable.remove, true);
  216. });
  217. it('an editable: {updateTime, remove} override item (with boolean option false)', function() {
  218. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: false});
  219. var parent = TestSupport.buildMockItemSet();
  220. pointItem.setParent(parent);
  221. pointItem.redraw();
  222. assert.equal(pointItem.editable.updateTime, true);
  223. assert.equal(pointItem.editable.updateGroup, undefined);
  224. assert.equal(pointItem.editable.remove, true);
  225. });
  226. it('an editable: {updateTime, updateGroup, remove} override item (with boolean option)', function() {
  227. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: true});
  228. var parent = TestSupport.buildMockItemSet();
  229. pointItem.setParent(parent);
  230. pointItem.redraw();
  231. assert.equal(pointItem.editable.updateTime, true);
  232. assert.equal(pointItem.editable.updateGroup, true);
  233. assert.equal(pointItem.editable.remove, true);
  234. });
  235. it('an editable: {updateTime, updateGroup, remove} override item (with boolean option false)', function() {
  236. var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: false});
  237. var parent = TestSupport.buildMockItemSet();
  238. pointItem.setParent(parent);
  239. pointItem.redraw();
  240. assert.equal(pointItem.editable.updateTime, true);
  241. assert.equal(pointItem.editable.updateGroup, true);
  242. assert.equal(pointItem.editable.remove, true);
  243. });
  244. }); // have the correct property for
  245. }); // should redraw() and then
  246. }); // Timeline PointItem