e15666b55a2edb1fc1fc08a490be3ad1ae3b69c7c6b6fe46daad5a1da1cab8f411947203fdb512f574b274994c1dac45bfd6df49c5dadee83ae34853a521fd 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. describe('Walkontable.ViewportColumnsCalculator', function () {
  2. function allColumns20() {
  3. return 20;
  4. }
  5. it('should render first 5 columns in unscrolled container', function () {
  6. var calc = new Walkontable.ViewportColumnsCalculator(100, 0, 1000, allColumns20);
  7. expect(calc.startColumn).toBe(0);
  8. expect(calc.startPosition).toBe(0);
  9. expect(calc.endColumn).toBe(4);
  10. var visibleCalc = new Walkontable.ViewportColumnsCalculator(100, 0, 1000, allColumns20, null, true);
  11. expect(visibleCalc.startColumn).toBe(0);
  12. expect(visibleCalc.endColumn).toBe(4);
  13. });
  14. it('should render 6 columns, starting from 3 in container scrolled to half of fourth column', function () {
  15. var calc = new Walkontable.ViewportColumnsCalculator(100, 70, 1000, allColumns20);
  16. expect(calc.startColumn).toBe(3);
  17. expect(calc.startPosition).toBe(60);
  18. expect(calc.endColumn).toBe(8);
  19. var visibleCalc = new Walkontable.ViewportColumnsCalculator(100, 70, 1000, allColumns20, null, true);
  20. expect(visibleCalc.startColumn).toBe(4);
  21. expect(visibleCalc.endColumn).toBe(7);
  22. });
  23. it('should render 10 columns, starting from 1 in container scrolled to half of fourth column (with render overrides)', function () {
  24. var overrideFn = function overrideFn(calc) {
  25. calc.startColumn -= 2;
  26. calc.endColumn += 2;
  27. };
  28. var calc = new Walkontable.ViewportColumnsCalculator(100, 70, 1000, allColumns20, overrideFn);
  29. expect(calc.startColumn).toBe(1);
  30. expect(calc.startPosition).toBe(20);
  31. expect(calc.endColumn).toBe(10);
  32. var visibleCalc = new Walkontable.ViewportColumnsCalculator(100, 70, 1000, allColumns20, null, true);
  33. expect(visibleCalc.startColumn).toBe(4);
  34. expect(visibleCalc.endColumn).toBe(7);
  35. });
  36. it('should return number of rendered columns', function () {
  37. var calc = new Walkontable.ViewportColumnsCalculator(100, 50, 1000, allColumns20);
  38. expect(calc.count).toBe(6);
  39. var visibleCalc = new Walkontable.ViewportColumnsCalculator(100, 50, 1000, allColumns20, null, true);
  40. expect(visibleCalc.count).toBe(4);
  41. });
  42. it('should render all columns if their size is smaller than viewport', function () {
  43. var calc = new Walkontable.ViewportColumnsCalculator(200, 0, 8, allColumns20);
  44. expect(calc.startColumn).toBe(0);
  45. expect(calc.endColumn).toBe(7);
  46. expect(calc.count).toBe(8);
  47. var visibleCalc = new Walkontable.ViewportColumnsCalculator(200, 0, 8, allColumns20, null, true);
  48. expect(visibleCalc.startColumn).toBe(0);
  49. expect(visibleCalc.endColumn).toBe(7);
  50. expect(visibleCalc.count).toBe(8);
  51. });
  52. it('should render all columns if their size is exactly the viewport', function () {
  53. var calc = new Walkontable.ViewportColumnsCalculator(200, 0, 10, allColumns20);
  54. expect(calc.startColumn).toBe(0);
  55. expect(calc.endColumn).toBe(9);
  56. expect(calc.count).toBe(10);
  57. var visibleCalc = new Walkontable.ViewportColumnsCalculator(200, 0, 10, allColumns20, null, true);
  58. expect(visibleCalc.startColumn).toBe(0);
  59. expect(visibleCalc.endColumn).toBe(9);
  60. expect(visibleCalc.count).toBe(10);
  61. });
  62. it('should render all columns if their size is slightly larger than viewport', function () {
  63. var calc = new Walkontable.ViewportColumnsCalculator(199, 0, 10, allColumns20);
  64. expect(calc.startColumn).toBe(0);
  65. expect(calc.endColumn).toBe(9);
  66. expect(calc.count).toBe(10);
  67. var visibleCalc = new Walkontable.ViewportColumnsCalculator(199, 0, 10, allColumns20, null, true);
  68. expect(visibleCalc.startColumn).toBe(0);
  69. expect(visibleCalc.endColumn).toBe(8);
  70. expect(visibleCalc.count).toBe(9);
  71. });
  72. it('should set null values if total columns is 0', function () {
  73. var calc = new Walkontable.ViewportColumnsCalculator(200, 0, 0, allColumns20);
  74. expect(calc.startColumn).toBe(null);
  75. expect(calc.startPosition).toBe(null);
  76. expect(calc.endColumn).toBe(null);
  77. expect(calc.count).toBe(0);
  78. var visibleCalc = new Walkontable.ViewportColumnsCalculator(200, 0, 0, allColumns20, null, true);
  79. expect(visibleCalc.startColumn).toBe(null);
  80. expect(visibleCalc.endColumn).toBe(null);
  81. });
  82. it('should set null values if total columns is 0 (with overrideFn provided)', function () {
  83. var overrideFn = function overrideFn(myCalc) {
  84. myCalc.startColumn = 0;
  85. myCalc.endColumn = 0;
  86. };
  87. var calc = new Walkontable.ViewportColumnsCalculator(200, 0, 0, allColumns20, overrideFn);
  88. expect(calc.startColumn).toBe(null);
  89. expect(calc.startPosition).toBe(null);
  90. expect(calc.endColumn).toBe(null);
  91. expect(calc.count).toBe(0);
  92. var visibleCalc = new Walkontable.ViewportColumnsCalculator(200, 0, 0, allColumns20, null, true);
  93. expect(visibleCalc.startColumn).toBe(null);
  94. expect(visibleCalc.endColumn).toBe(null);
  95. });
  96. it('should scroll backwards if total columns is reached', function () {
  97. var calc = new Walkontable.ViewportColumnsCalculator(190, 350, 20, allColumns20);
  98. expect(calc.startColumn).toBe(10);
  99. expect(calc.startPosition).toBe(200);
  100. expect(calc.endColumn).toBe(19);
  101. expect(calc.count).toBe(10);
  102. var visibleCalc = new Walkontable.ViewportColumnsCalculator(190, 350, 20, allColumns20, null, true);
  103. expect(visibleCalc.startColumn).toBe(11);
  104. expect(visibleCalc.endColumn).toBe(19);
  105. });
  106. it('should update stretchAllRatio after refreshStretching call (stretch: all)', function () {
  107. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 20, allColumns20, null, true, 'all');
  108. expect(calc.stretchAllRatio).toBe(0);
  109. expect(calc.stretchLastWidth).toBe(0);
  110. calc.refreshStretching(414);
  111. expect(calc.stretchAllRatio).toBe(1.035);
  112. expect(calc.stretchLastWidth).toBe(0);
  113. });
  114. it('should update stretchAllRatio after refreshStretching call (stretch: last)', function () {
  115. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 5, allColumns20, null, true, 'last');
  116. expect(calc.stretchAllRatio).toBe(0);
  117. expect(calc.stretchLastWidth).toBe(0);
  118. calc.refreshStretching(414);
  119. expect(calc.stretchAllRatio).toBe(0);
  120. expect(calc.stretchLastWidth).toBe(334);
  121. });
  122. it('should return valid stretched column width (stretch: all)', function () {
  123. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 5, allColumns20, null, true, 'all');
  124. expect(calc.getStretchedColumnWidth(0, 50)).toBe(null);
  125. expect(calc.needVerifyLastColumnWidth).toBe(true);
  126. calc.refreshStretching(417);
  127. expect(calc.getStretchedColumnWidth(0, allColumns20())).toBe(83);
  128. expect(calc.getStretchedColumnWidth(1, allColumns20())).toBe(83);
  129. expect(calc.getStretchedColumnWidth(2, allColumns20())).toBe(83);
  130. expect(calc.getStretchedColumnWidth(3, allColumns20())).toBe(83);
  131. expect(calc.needVerifyLastColumnWidth).toBe(true);
  132. expect(calc.getStretchedColumnWidth(4, allColumns20())).toBe(85);
  133. expect(calc.needVerifyLastColumnWidth).toBe(false);
  134. });
  135. it('should return valid stretched column width (stretch: last)', function () {
  136. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 5, allColumns20, null, true, 'last');
  137. expect(calc.getStretchedColumnWidth(0, 50)).toBe(null);
  138. calc.refreshStretching(417);
  139. expect(calc.getStretchedColumnWidth(0, allColumns20())).toBe(null);
  140. expect(calc.getStretchedColumnWidth(1, allColumns20())).toBe(null);
  141. expect(calc.getStretchedColumnWidth(2, allColumns20())).toBe(null);
  142. expect(calc.getStretchedColumnWidth(3, allColumns20())).toBe(null);
  143. expect(calc.getStretchedColumnWidth(4, allColumns20())).toBe(337);
  144. });
  145. it('call refreshStretching should clear stretchAllColumnsWidth and needVerifyLastColumnWidth property', function () {
  146. var calc = new Walkontable.ViewportColumnsCalculator(250, 0, 5, allColumns20, null, true, 'all');
  147. expect(calc.stretchAllColumnsWidth.length).toBe(0);
  148. expect(calc.needVerifyLastColumnWidth).toBe(true);
  149. calc.refreshStretching(417);
  150. calc.getStretchedColumnWidth(0, allColumns20());
  151. calc.getStretchedColumnWidth(1, allColumns20());
  152. calc.getStretchedColumnWidth(2, allColumns20());
  153. calc.getStretchedColumnWidth(3, allColumns20());
  154. calc.getStretchedColumnWidth(4, allColumns20());
  155. expect(calc.stretchAllColumnsWidth.length).toBe(5);
  156. expect(calc.needVerifyLastColumnWidth).toBe(false);
  157. calc.refreshStretching(201);
  158. expect(calc.stretchAllColumnsWidth.length).toBe(0);
  159. expect(calc.needVerifyLastColumnWidth).toBe(true);
  160. });
  161. });