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.

39 lines
1.8 KiB

  1. var assert = require('assert');
  2. var jsdom = require('mocha-jsdom');
  3. var moment = require('../lib/module/moment');
  4. var Range = require('../lib/timeline/Range');
  5. var TestSupport = require('./TestSupport');
  6. describe('Timeline Range', function () {
  7. jsdom();
  8. it('should have start default before now', function () {
  9. var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0).valueOf();
  10. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  11. assert(range.start < now, "Default start is before now");
  12. });
  13. it('should have end default after now', function () {
  14. var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0).valueOf();
  15. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  16. assert(range.end > now, "Default end is after now");
  17. });
  18. it('should support custom start and end dates', function () {
  19. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  20. range.setRange(new Date(2017, 0, 26, 13, 26, 3, 320), new Date(2017, 3, 11, 0, 23, 35, 0), false, false, null);
  21. assert.equal(range.start, new Date(2017, 0, 26, 13, 26, 3, 320).valueOf(), "start is as expected");
  22. assert.equal(range.end, new Date(2017, 3, 11, 0, 23, 35, 0).valueOf(), "end is as expected");
  23. });
  24. it('should calculate milliseconds per pixel', function () {
  25. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  26. assert(range.getMillisecondsPerPixel() > 0, "positive value for milliseconds per pixel");
  27. });
  28. it('should calculate 1 millisecond per pixel for simple range', function () {
  29. var range = new Range(TestSupport.buildSimpleTimelineRangeBody());
  30. range.setRange(new Date(2017, 0, 26, 13, 26, 3, 320), new Date(2017, 0, 26, 13, 26, 4, 320), false, false, null);
  31. assert.equal(range.getMillisecondsPerPixel(), 1, "one second over 1000 pixels");
  32. });
  33. });