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.

64 lines
2.4 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. it('should initialize with minimal data', function() {
  12. var now = moment().toDate();
  13. var pointItem = new PointItem({start: now}, null, null);
  14. assert.equal(pointItem.props.content.height, 0);
  15. assert.equal(pointItem.data.start, now);
  16. });
  17. it('should have a default width of 0', function() {
  18. var now = moment().toDate();
  19. var pointItem = new PointItem({start: now}, null, null);
  20. assert.equal(pointItem.getWidthRight(), 0);
  21. assert.equal(pointItem.getWidthLeft(), 0);
  22. });
  23. it('should error if there is missing data', function () {
  24. assert.throws(function () { new PointItem({}, null, null)}, Error);
  25. });
  26. it('should be visible if the range is during', function() {
  27. var now = moment();
  28. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  29. range.start = now.clone().add(-1, 'second');
  30. range.end = range.start.clone().add(1, 'hour');
  31. var pointItem = new PointItem({start: now.toDate()}, null, null);
  32. assert(pointItem.isVisible(range));
  33. });
  34. it('should not be visible if the range is after', function() {
  35. var now = moment();
  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 now = moment().toDate();
  53. var pointItem = new PointItem({start: now}, null, null);
  54. assert(pointItem.isVisible(range));
  55. });
  56. });