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.

87 lines
4.4 KiB

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