Performance.spec.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. describe('Performance', () => {
  2. var id = 'testContainer';
  3. // this is a test suite to test if there are no redundant operations
  4. beforeEach(function() {
  5. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  6. });
  7. afterEach(function() {
  8. if (this.$container) {
  9. destroy();
  10. this.$container.remove();
  11. }
  12. });
  13. it('should call renderer once for one cell (fixed column width)', () => {
  14. var count = 0;
  15. handsontable({
  16. data: Handsontable.helper.createSpreadsheetData(1, 1),
  17. colWidths: 100,
  18. rowHeights: 23,
  19. renderer() {
  20. Handsontable.renderers.TextRenderer.apply(this, arguments);
  21. count++;
  22. }
  23. });
  24. expect(count).toEqual(1); // only for master table
  25. });
  26. it('should call renderer twice for one cell (auto column width)', () => {
  27. var count = 0;
  28. var hot = handsontable({
  29. data: Handsontable.helper.createSpreadsheetData(1, 1),
  30. rowHeights: 23,
  31. renderer() {
  32. Handsontable.renderers.TextRenderer.apply(this, arguments);
  33. count++;
  34. }
  35. });
  36. expect(count).toEqual(2); // 1 for autoColumnSize, 1 for actual cell render
  37. });
  38. it('should call renderer twice for one cell (auto row height)', () => {
  39. var count = 0;
  40. var hot = handsontable({
  41. data: Handsontable.helper.createSpreadsheetData(1, 1),
  42. colWidths: 50,
  43. renderer() {
  44. Handsontable.renderers.TextRenderer.apply(this, arguments);
  45. count++;
  46. }
  47. });
  48. expect(count).toEqual(1); // 1 for actual cell render (colWidths prevent autoColumnSize to enable)
  49. });
  50. it('should call renderer triple times for one cell (auto row height, auto column width)', () => {
  51. var count = 0;
  52. var hot = handsontable({
  53. data: Handsontable.helper.createSpreadsheetData(1, 1),
  54. autoRowSize: true,
  55. autoColumnSize: true,
  56. renderer() {
  57. Handsontable.renderers.TextRenderer.apply(this, arguments);
  58. count++;
  59. }
  60. });
  61. expect(count).toEqual(3); // 1 for autoColumnSize, 1 for autoRowSize, 1 for actual cell render
  62. });
  63. it('should call getCellMeta minimum number of times for one cell (auto column width, without overlays)', () => {
  64. var count = 0;
  65. handsontable({
  66. data: Handsontable.helper.createSpreadsheetData(1, 1),
  67. rowHeights: 23,
  68. beforeGetCellMeta() {
  69. count++;
  70. }
  71. });
  72. expect(count).toEqual(7);
  73. });
  74. it('should call getCellMeta minimum number of times for one cell (auto row height, without overlays)', () => {
  75. var count = 0;
  76. handsontable({
  77. data: Handsontable.helper.createSpreadsheetData(1, 1),
  78. colWidths: 50,
  79. beforeGetCellMeta() {
  80. count++;
  81. }
  82. });
  83. expect(count).toEqual(5);
  84. });
  85. it('should call getCellMeta minimum number of times for one cell (auto column width, with left overlay)', () => {
  86. var count = 0;
  87. handsontable({
  88. data: Handsontable.helper.createSpreadsheetData(1, 1),
  89. colHeaders: true,
  90. rowHeights: 23,
  91. beforeGetCellMeta() {
  92. count++;
  93. }
  94. });
  95. expect(count).toEqual(8);
  96. });
  97. it('should call getCellMeta minimum number of times for one cell (auto row height, with left overlay)', () => {
  98. var count = 0;
  99. handsontable({
  100. data: Handsontable.helper.createSpreadsheetData(1, 1),
  101. colHeaders: true,
  102. colWidths: 50,
  103. beforeGetCellMeta() {
  104. count++;
  105. }
  106. });
  107. expect(count).toEqual(6);
  108. });
  109. it('should call getCellMeta minimum number of times for one cell (auto column width, with top overlay)', () => {
  110. var count = 0;
  111. handsontable({
  112. data: Handsontable.helper.createSpreadsheetData(1, 1),
  113. rowHeaders: true,
  114. rowHeights: 23,
  115. beforeGetCellMeta() {
  116. count++;
  117. }
  118. });
  119. expect(count).toEqual(7);
  120. });
  121. it('should call getCellMeta minimum number of times for one cell (auto row height, with top overlay)', () => {
  122. var count = 0;
  123. handsontable({
  124. data: Handsontable.helper.createSpreadsheetData(1, 1),
  125. rowHeaders: true,
  126. colWidths: 50,
  127. beforeGetCellMeta() {
  128. count++;
  129. }
  130. });
  131. expect(count).toEqual(5);
  132. });
  133. it('should call getCellMeta minimum number of times for one cell (auto column width, with all overlays)', () => {
  134. var count = 0;
  135. handsontable({
  136. data: Handsontable.helper.createSpreadsheetData(1, 1),
  137. colHeaders: true,
  138. rowHeaders: true,
  139. rowHeights: 23,
  140. beforeGetCellMeta() {
  141. count++;
  142. }
  143. });
  144. expect(count).toEqual(8);
  145. });
  146. it('should call getCellMeta minimum number of times for one cell (auto row height, with all overlays)', () => {
  147. var count = 0;
  148. handsontable({
  149. data: Handsontable.helper.createSpreadsheetData(1, 1),
  150. colHeaders: true,
  151. rowHeaders: true,
  152. colWidths: 50,
  153. beforeGetCellMeta() {
  154. count++;
  155. }
  156. });
  157. expect(count).toEqual(6);
  158. });
  159. it('should call renderer twice for each cell (auto column width)', () => {
  160. var count = 0;
  161. handsontable({
  162. data: Handsontable.helper.createSpreadsheetData(4, 4),
  163. rowHeights: 23,
  164. autoColumnSize: true,
  165. renderer() {
  166. Handsontable.renderers.TextRenderer.apply(this, arguments);
  167. count++;
  168. }
  169. });
  170. expect(count).toEqual(28);
  171. });
  172. it('should call renderer twice for each cell (auto row height)', () => {
  173. var count = 0;
  174. handsontable({
  175. data: Handsontable.helper.createSpreadsheetData(4, 4),
  176. colWidths: 50,
  177. autoRowSize: true,
  178. renderer() {
  179. Handsontable.renderers.TextRenderer.apply(this, arguments);
  180. count++;
  181. }
  182. });
  183. expect(count).toEqual(28); // 16 in main table and 4 rows for autoRowSize
  184. });
  185. it('should call renderer twice for each cell (auto row height, auto column width)', () => {
  186. var count = 0;
  187. handsontable({
  188. data: Handsontable.helper.createSpreadsheetData(4, 4),
  189. autoRowSize: true,
  190. autoColumnSize: true,
  191. renderer() {
  192. Handsontable.renderers.TextRenderer.apply(this, arguments);
  193. count++;
  194. }
  195. });
  196. expect(count).toEqual(40); // 16x2 in main table, 4 rows for autoRowSize and 4 cols for autoColumnSize
  197. });
  198. });