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