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.

94 lines
4.5 KiB

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