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.

111 lines
3.3 KiB

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