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.

108 lines
3.4 KiB

  1. var assert = require('assert');
  2. describe('Timeline ItemSet', function () {
  3. before(function () {
  4. delete require.cache[require.resolve('../dist/vis')]
  5. this.jsdom = require('jsdom-global')();
  6. this.vis = require('../dist/vis');
  7. var TestSupport = require('./TestSupport');
  8. var rangeBody = TestSupport.buildSimpleTimelineRangeBody();
  9. this.testrange = new this.vis.timeline.Range(rangeBody);
  10. this.testrange.setRange(new Date(2017, 1, 26, 13, 26, 3, 320), new Date(2017, 1, 26, 13, 26, 4, 320), false, false, null);
  11. this.testitems = new this.vis.DataSet({
  12. type: {
  13. start: 'Date',
  14. end: 'Date'
  15. }
  16. });
  17. // add single items with different date types
  18. this.testitems.add({id: 1, content: 'Item 1', start: new Date(2017, 1, 26, 13, 26, 3, 600), type: 'point'});
  19. this.testitems.add({id: 2, content: 'Item 2', start: new Date(2017, 1, 26, 13, 26, 5, 600), type: 'point'});
  20. })
  21. after(function () {
  22. this.jsdom();
  23. })
  24. var getBasicBody = function() {
  25. var body = {
  26. dom: {
  27. container: document.createElement('div'),
  28. leftContainer: document.createElement('div'),
  29. centerContainer: document.createElement('div'),
  30. top: document.createElement('div'),
  31. left: document.createElement('div'),
  32. center: document.createElement('div'),
  33. backgroundVertical: document.createElement('div')
  34. },
  35. domProps: {
  36. root: {},
  37. background: {},
  38. centerContainer: {},
  39. leftContainer: {},
  40. rightContainer: {},
  41. center: {},
  42. left: {},
  43. right: {},
  44. top: {},
  45. bottom: {},
  46. border: {},
  47. scrollTop: 0,
  48. scrollTopMin: 0
  49. },
  50. emitter: {
  51. on: function() {return {};},
  52. emit: function() {}
  53. },
  54. util: {
  55. }
  56. }
  57. return body;
  58. };
  59. it('should initialise with minimal data', function () {
  60. var body = getBasicBody();
  61. var itemset = new this.vis.timeline.components.ItemSet(body, {});
  62. assert(itemset);
  63. });
  64. it('should redraw() and have the right classNames', function () {
  65. var body = getBasicBody();
  66. body.range = this.testrange;
  67. var itemset = new this.vis.timeline.components.ItemSet(body, {});
  68. itemset.redraw();
  69. assert.equal(itemset.dom.frame.className, 'vis-itemset');
  70. assert.equal(itemset.dom.background.className, 'vis-background');
  71. assert.equal(itemset.dom.foreground.className, 'vis-foreground');
  72. assert.equal(itemset.dom.axis.className, 'vis-axis');
  73. assert.equal(itemset.dom.labelSet.className, 'vis-labelset');
  74. });
  75. it('should start with no items', function () {
  76. var body = getBasicBody();
  77. var itemset = new this.vis.timeline.components.ItemSet(body, {});
  78. assert.equal(itemset.getItems(), null);
  79. });
  80. it('should store items correctly', function() {
  81. var body = getBasicBody();
  82. body.range = this.testrange;
  83. var DateUtil = this.vis.timeline.DateUtil;
  84. body.util.toScreen = function(time) {
  85. return DateUtil.toScreen({
  86. body: {
  87. hiddenDates: []
  88. },
  89. range: {
  90. conversion: function() {
  91. return {offset: 0, scale: 100};
  92. }
  93. }
  94. }, time, 900)
  95. };
  96. var itemset = new this.vis.timeline.components.ItemSet(body, {});
  97. itemset.setItems(this.testitems);
  98. assert.equal(itemset.getItems().length, 2);
  99. assert.deepEqual(itemset.getItems(), this.testitems);
  100. });
  101. });