Skip to content
This repository was archived by the owner on Jul 29, 2019. It is now read-only.

Commit 8f6ff36

Browse files
committed
Initial tests for timeline ItemSet.
Somewhat more complicated setup, associated with the need for a real window.
1 parent e51b996 commit 8f6ff36

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"gulp-rename": "^1.2.2",
5757
"gulp-util": "^3.0.8",
5858
"jsdom": "9.9.1",
59+
"jsdom-global": "^2.1.1",
5960
"mocha": "^3.2.0",
6061
"mocha-jsdom": "^1.1.0",
6162
"rimraf": "^2.5.4",

test/TestSupport.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ module.exports = {
77
clientWidth: 1000
88
}
99
},
10-
domProps: this.props,
10+
domProps: {
11+
centerContainer: {
12+
width: 900,
13+
height: 600
14+
}
15+
},
1116
emitter: {
1217
on: function () {},
1318
off: function () {},

test/TimelineItemSet.test.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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

Comments
 (0)