Number.spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {
  2. rangeEach,
  3. rangeEachReverse,
  4. } from 'handsontable/helpers/number';
  5. describe('Number helper', () => {
  6. //
  7. // Handsontable.helper.rangeEach
  8. //
  9. describe('rangeEach', () => {
  10. it('should iterate increasingly, when `from` and `to` arguments are passed and `from` number is lower then `to`', () => {
  11. var spy = jasmine.createSpy();
  12. rangeEach(-1, 2, spy);
  13. expect(spy.calls.count()).toBe(4);
  14. expect(spy.calls.argsFor(0)).toEqual([-1]);
  15. expect(spy.calls.argsFor(1)).toEqual([0]);
  16. expect(spy.calls.argsFor(2)).toEqual([1]);
  17. expect(spy.calls.argsFor(3)).toEqual([2]);
  18. });
  19. it('should iterate only once, when `from` and `to` arguments are equal', () => {
  20. var spy = jasmine.createSpy();
  21. rangeEach(10, 10, spy);
  22. expect(spy.calls.count()).toBe(1);
  23. expect(spy.calls.argsFor(0)).toEqual([10]);
  24. });
  25. it('should iterate only once, when `from` and `to` arguments are equal and from value is zero', () => {
  26. var spy = jasmine.createSpy();
  27. rangeEach(0, spy);
  28. expect(spy.calls.count()).toBe(1);
  29. expect(spy.calls.argsFor(0)).toEqual([0]);
  30. });
  31. it('should iterate increasingly from 0, when only `from` argument is passed', () => {
  32. var spy = jasmine.createSpy();
  33. rangeEach(4, spy);
  34. expect(spy.calls.count()).toBe(5);
  35. expect(spy.calls.argsFor(0)).toEqual([0]);
  36. expect(spy.calls.argsFor(4)).toEqual([4]);
  37. });
  38. it('should not iterate decreasingly, when `from` and `to` arguments are passed and `from` number is higher then `to`', () => {
  39. var spy = jasmine.createSpy();
  40. rangeEach(1, -3, spy);
  41. expect(spy.calls.count()).toBe(0);
  42. });
  43. });
  44. //
  45. // Handsontable.helper.rangeEachReverse
  46. //
  47. describe('rangeEachReverse', () => {
  48. it('should iterate decreasingly, when `from` and `to` arguments are passed and `from` number is higher then `to`', () => {
  49. var spy = jasmine.createSpy();
  50. rangeEachReverse(2, -1, spy);
  51. expect(spy.calls.count()).toBe(4);
  52. expect(spy.calls.argsFor(0)).toEqual([2]);
  53. expect(spy.calls.argsFor(1)).toEqual([1]);
  54. expect(spy.calls.argsFor(2)).toEqual([0]);
  55. expect(spy.calls.argsFor(3)).toEqual([-1]);
  56. });
  57. it('should iterate only once, when `from` and `to` arguments are equal', () => {
  58. var spy = jasmine.createSpy();
  59. rangeEachReverse(10, 10, spy);
  60. expect(spy.calls.count()).toBe(1);
  61. expect(spy.calls.argsFor(0)).toEqual([10]);
  62. });
  63. it('should iterate only once, when `from` and `to` arguments are equal and from value is zero', () => {
  64. var spy = jasmine.createSpy();
  65. rangeEachReverse(0, spy);
  66. expect(spy.calls.count()).toBe(1);
  67. expect(spy.calls.argsFor(0)).toEqual([0]);
  68. });
  69. it('should iterate decreasingly to 0, when only `from` argument is passed', () => {
  70. var spy = jasmine.createSpy();
  71. rangeEachReverse(4, spy);
  72. expect(spy.calls.count()).toBe(5);
  73. expect(spy.calls.argsFor(0)).toEqual([4]);
  74. expect(spy.calls.argsFor(4)).toEqual([0]);
  75. });
  76. it('should not iterate increasingly, when `from` and `to` arguments are passed and `from` number is higher then `to`', () => {
  77. var spy = jasmine.createSpy();
  78. rangeEachReverse(1, 5, spy);
  79. expect(spy.calls.count()).toBe(0);
  80. });
  81. });
  82. });