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.

89 lines
4.4 KiB

  1. var assert = require('assert');
  2. var vis = require('../dist/vis');
  3. var jsdom = require('mocha-jsdom')
  4. var moment = vis.moment;
  5. var timeline = vis.timeline;
  6. var TimeStep = timeline.TimeStep;
  7. var TestSupport = require('./TestSupport');
  8. describe('TimeStep', function () {
  9. jsdom();
  10. it('should work with just start and end dates', function () {
  11. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5));
  12. assert.equal(timestep.autoScale, true, "should autoscale if scale not specified");
  13. assert.equal(timestep.scale, "day", "should default to day scale if scale not specified");
  14. assert.equal(timestep.step, 1, "should default to 1 day step if scale not specified");
  15. });
  16. it('should work with specified scale (just under 1 second)', function () {
  17. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5), 999);
  18. assert.equal(timestep.scale, "second", "should have right scale");
  19. assert.equal(timestep.step, 1, "should have right step size");
  20. });
  21. // TODO: check this - maybe should work for 1000?
  22. it('should work with specified scale (1 second)', function () {
  23. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5), 1001);
  24. assert.equal(timestep.scale, "second", "should have right scale");
  25. assert.equal(timestep.step, 5, "should have right step size");
  26. });
  27. it('should work with specified scale (2 seconds)', function () {
  28. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5), 2000);
  29. assert.equal(timestep.scale, "second", "should have right scale");
  30. assert.equal(timestep.step, 5, "should have right step size");
  31. });
  32. it('should work with specified scale (5 seconds)', function () {
  33. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5), 5001);
  34. assert.equal(timestep.scale, "second", "should have right scale");
  35. assert.equal(timestep.step, 10, "should have right step size");
  36. });
  37. it('should perform the step with a specified scale (1 year)', function () {
  38. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5));
  39. timestep.setScale({ scale: 'year', step: 1 });
  40. timestep.start();
  41. assert.equal(timestep.getCurrent().unix(), moment("2017-01-01T00:00:00.000").unix(), "should have the right initial value");
  42. timestep.next();
  43. assert.equal(timestep.getCurrent().unix(), moment("2018-01-01T00:00:00.000").unix(), "should have the right value after a step");
  44. });
  45. it('should perform the step with a specified scale (1 month)', function () {
  46. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5));
  47. timestep.setScale({ scale: 'month', step: 1 });
  48. timestep.start();
  49. assert.equal(timestep.getCurrent().unix(), moment("2017-04-01T00:00:00.000").unix(), "should have the right initial value");
  50. timestep.next();
  51. assert.equal(timestep.getCurrent().unix(), moment("2017-05-01T00:00:00.000").unix(), "should have the right value after a step");
  52. });
  53. it('should perform the step with a specified scale (1 week)', function () {
  54. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5));
  55. timestep.setScale({ scale: 'week', step: 1 });
  56. timestep.start();
  57. assert.equal(timestep.getCurrent().unix(), moment("2017-04-02T00:00:00.000").unix(), "should have the right initial value");
  58. timestep.next();
  59. assert.equal(timestep.getCurrent().unix(), moment("2017-04-09T00:00:00.000").unix(), "should have the right value after a step");
  60. });
  61. it('should perform the step with a specified scale (1 day)', function () {
  62. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5));
  63. timestep.setScale({ scale: 'day', step: 1 });
  64. timestep.start();
  65. assert.equal(timestep.getCurrent().unix(), moment("2017-04-03T00:00:00.000").unix(), "should have the right initial value");
  66. timestep.next();
  67. assert.equal(timestep.getCurrent().unix(), moment("2017-04-04T00:00:00.000").unix(), "should have the right value after a step");
  68. });
  69. it('should perform the step with a specified scale (1 hour)', function () {
  70. var timestep = new TimeStep(new Date(2017, 3, 3), new Date(2017, 3, 5));
  71. timestep.setScale({ scale: 'hour', step: 1 });
  72. timestep.start();
  73. assert.equal(timestep.getCurrent().unix(), moment("2017-04-03T00:00:00.000").unix(), "should have the right initial value");
  74. timestep.next();
  75. assert.equal(timestep.getCurrent().unix(), moment("2017-04-03T01:00:00.000").unix(), "should have the right value after a step");
  76. });
  77. });