Browse Source

Remove requirement for dist/vis in TimelineItemSet

mbroad/unittest/lib/shared
MacLeod Broad 7 years ago
parent
commit
6c8cf80f8c
No known key found for this signature in database GPG Key ID: F1B295D13C3CC9CF
1 changed files with 17 additions and 15 deletions
  1. +17
    -15
      test/TimelineItemSet.test.js

+ 17
- 15
test/TimelineItemSet.test.js View File

@ -1,16 +1,19 @@
var assert = require('assert'); var assert = require('assert');
var vis = require('../dist/vis');
var DataSet = require('../lib/DataSet');
var DateUtil = require('../lib/timeline/DateUtil');
var Range = require('../lib/timeline/Range');
var ItemSet = require('../lib/timeline/component/ItemSet');
describe('Timeline ItemSet', function () { describe('Timeline ItemSet', function () {
before(function () { before(function () {
delete require.cache[require.resolve('../dist/vis')]
this.jsdom = require('jsdom-global')(); this.jsdom = require('jsdom-global')();
this.vis = require('../dist/vis');
var TestSupport = require('./TestSupport');
var rangeBody = TestSupport.buildSimpleTimelineRangeBody();
this.testrange = new this.vis.timeline.Range(rangeBody);
this.TestSupport = require('./TestSupport');
var rangeBody = this.TestSupport.buildSimpleTimelineRangeBody();
this.testrange = new Range(rangeBody);
this.testrange.setRange(new Date(2017, 1, 26, 13, 26, 3, 320), new Date(2017, 1, 26, 13, 26, 4, 320), false, false, null); this.testrange.setRange(new Date(2017, 1, 26, 13, 26, 3, 320), new Date(2017, 1, 26, 13, 26, 4, 320), false, false, null);
this.testitems = new this.vis.DataSet({
this.testitems = new DataSet({
type: { type: {
start: 'Date', start: 'Date',
end: 'Date' end: 'Date'
@ -19,11 +22,11 @@ describe('Timeline ItemSet', function () {
// add single items with different date types // add single items with different date types
this.testitems.add({id: 1, content: 'Item 1', start: new Date(2017, 1, 26, 13, 26, 3, 600), type: 'point'}); this.testitems.add({id: 1, content: 'Item 1', start: new Date(2017, 1, 26, 13, 26, 3, 600), type: 'point'});
this.testitems.add({id: 2, content: 'Item 2', start: new Date(2017, 1, 26, 13, 26, 5, 600), type: 'point'}); this.testitems.add({id: 2, content: 'Item 2', start: new Date(2017, 1, 26, 13, 26, 5, 600), type: 'point'});
})
});
after(function () { after(function () {
this.jsdom(); this.jsdom();
})
});
var getBasicBody = function() { var getBasicBody = function() {
var body = { var body = {
@ -57,20 +60,20 @@ describe('Timeline ItemSet', function () {
}, },
util: { util: {
} }
}
};
return body; return body;
}; };
it('should initialise with minimal data', function () { it('should initialise with minimal data', function () {
var body = getBasicBody(); var body = getBasicBody();
var itemset = new this.vis.timeline.components.ItemSet(body, {});
var itemset = new ItemSet(body, {});
assert(itemset); assert(itemset);
}); });
it('should redraw() and have the right classNames', function () { it('should redraw() and have the right classNames', function () {
var body = getBasicBody(); var body = getBasicBody();
body.range = this.testrange; body.range = this.testrange;
var itemset = new this.vis.timeline.components.ItemSet(body, {});
var itemset = new ItemSet(body, {});
itemset.redraw(); itemset.redraw();
assert.equal(itemset.dom.frame.className, 'vis-itemset'); assert.equal(itemset.dom.frame.className, 'vis-itemset');
assert.equal(itemset.dom.background.className, 'vis-background'); assert.equal(itemset.dom.background.className, 'vis-background');
@ -81,14 +84,13 @@ describe('Timeline ItemSet', function () {
it('should start with no items', function () { it('should start with no items', function () {
var body = getBasicBody(); var body = getBasicBody();
var itemset = new this.vis.timeline.components.ItemSet(body, {});
var itemset = new ItemSet(body, {});
assert.equal(itemset.getItems(), null); assert.equal(itemset.getItems(), null);
}); });
it('should store items correctly', function() { it('should store items correctly', function() {
var body = getBasicBody(); var body = getBasicBody();
body.range = this.testrange; body.range = this.testrange;
var DateUtil = this.vis.timeline.DateUtil;
body.util.toScreen = function(time) { body.util.toScreen = function(time) {
return DateUtil.toScreen({ return DateUtil.toScreen({
body: { body: {
@ -101,7 +103,7 @@ describe('Timeline ItemSet', function () {
} }
}, time, 900) }, time, 900)
}; };
var itemset = new this.vis.timeline.components.ItemSet(body, {});
var itemset = new ItemSet(body, {});
itemset.setItems(this.testitems); itemset.setItems(this.testitems);
assert.equal(itemset.getItems().length, 2); assert.equal(itemset.getItems().length, 2);
assert.deepEqual(itemset.getItems(), this.testitems); assert.deepEqual(itemset.getItems(), this.testitems);

Loading…
Cancel
Save