832afe4f38274666d469028cfbd299dcc8025a6f9d8e3e791b84ae4e3922c4024c39ec35d82097276baa3c2f4bca307fbba1bc834647262ea03fefb8905ee1 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. describe('WalkontableCore', () => {
  2. var $table,
  3. $container,
  4. $wrapper,
  5. debug = false;
  6. beforeEach(() => {
  7. $wrapper = $('<div></div>').css({overflow: 'hidden'});
  8. $container = $('<div></div>');
  9. $table = $('<table></table>'); // create a table that is not attached to document
  10. $wrapper.append($container);
  11. $container.append($table);
  12. $wrapper.appendTo('body');
  13. createDataArray(100, 4);
  14. });
  15. afterEach(() => {
  16. if (!debug) {
  17. $('.wtHolder').remove();
  18. }
  19. $wrapper.remove();
  20. });
  21. it('first row should have the same text as in data source', () => {
  22. var wt = new Walkontable.Core({
  23. table: $table[0],
  24. data: getData,
  25. totalRows: getTotalRows,
  26. totalColumns: getTotalColumns
  27. });
  28. wt.draw();
  29. var TDs = $table.find('tbody tr:first td');
  30. expect(TDs[0].innerHTML).toBe('0');
  31. expect(TDs[1].innerHTML).toBe('a');
  32. });
  33. it('should bootstrap table if empty TABLE is given', () => {
  34. $wrapper.width(200).height(200);
  35. var wt = new Walkontable.Core({
  36. table: $table[0],
  37. data: getData,
  38. totalRows: getTotalRows,
  39. totalColumns: getTotalColumns,
  40. renderAllRows: true
  41. });
  42. wt.draw();
  43. expect($table.find('td').length).toBe(400);
  44. });
  45. it('should bootstrap column headers if THEAD is given', () => {
  46. $table.remove();
  47. $table = $('<table><thead><tr><th>A</th><th>B</th><th>C</th><th>D</th></tr></thead></table>');
  48. $table.appendTo('body');
  49. var wt = new Walkontable.Core({
  50. table: $table[0],
  51. data: getData,
  52. totalRows: getTotalRows,
  53. totalColumns: getTotalColumns,
  54. rowHeaders: [function(row, TH) {
  55. TH.innerHTML = row + 1;
  56. }]
  57. });
  58. wt.draw();
  59. expect($table.find('thead th').length).toBe(5); // include corner TH
  60. expect($table.find('tbody tr:first th').length).toBe(1);
  61. expect($table.find('tbody tr:first td').length).toBe(4);
  62. });
  63. it('should figure out how many columns to display if width param given', () => {
  64. $wrapper.width(100);
  65. var wt = new Walkontable.Core({
  66. table: $table[0],
  67. data: getData,
  68. totalRows: getTotalRows,
  69. totalColumns: getTotalColumns
  70. });
  71. wt.draw();
  72. expect($table.find('tbody tr:first td').length).toBe(2);
  73. });
  74. it('should not render table that is removed from DOM', () => {
  75. $wrapper.remove();
  76. var wt = new Walkontable.Core({
  77. table: $table[0],
  78. data: getData,
  79. totalRows: getTotalRows,
  80. totalColumns: getTotalColumns
  81. });
  82. wt.draw();
  83. expect(wt.drawn).toBe(false);
  84. expect(wt.drawInterrupted).toBe(true);
  85. });
  86. it('should not render table that is `display: none`', () => {
  87. var $div = $('<div style="display: none"></div>').appendTo('body');
  88. $div.append($table);
  89. var wt = new Walkontable.Core({
  90. table: $table[0],
  91. data: getData,
  92. totalRows: getTotalRows,
  93. totalColumns: getTotalColumns
  94. });
  95. wt.draw();
  96. expect(wt.drawn).toBe(false);
  97. expect(wt.drawInterrupted).toBe(true);
  98. $div.remove();
  99. });
  100. it('should render empty table (limited height)', () => {
  101. createDataArray(0, 5);
  102. var wt = new Walkontable.Core({
  103. table: $table[0],
  104. data: getData,
  105. totalRows: getTotalRows,
  106. totalColumns: getTotalColumns
  107. });
  108. wt.draw();
  109. expect(() => {
  110. wt.draw(); // second render was giving "Cannot read property 'firstChild' of null" sometimes
  111. }).not.toThrow();
  112. });
  113. it('should render empty table (unlimited height)', () => {
  114. createDataArray(0, 5);
  115. var wt = new Walkontable.Core({
  116. table: $table[0],
  117. data: getData,
  118. totalRows: getTotalRows,
  119. totalColumns: getTotalColumns
  120. });
  121. wt.draw();
  122. expect(() => {
  123. wt.draw(); // second render was giving "Cannot read property 'firstChild' of null" sometimes
  124. }).not.toThrow();
  125. });
  126. it('should render empty then filled table (limited height)', () => {
  127. createDataArray(0, 5);
  128. var wt = new Walkontable.Core({
  129. table: $table[0],
  130. data: getData,
  131. totalRows: getTotalRows,
  132. totalColumns: getTotalColumns
  133. });
  134. wt.draw();
  135. createDataArray(1, 5);
  136. expect(() => {
  137. wt.draw(); // second render was giving "Cannot read property 'firstChild' of null" sometimes
  138. }).not.toThrow();
  139. });
  140. it('should render empty then filled table (unlimited height)', () => {
  141. createDataArray(0, 5);
  142. var wt = new Walkontable.Core({
  143. table: $table[0],
  144. data: getData,
  145. totalRows: getTotalRows,
  146. totalColumns: getTotalColumns
  147. });
  148. wt.draw();
  149. createDataArray(1, 5);
  150. expect(() => {
  151. wt.draw(); // second render was giving "Cannot read property 'firstChild' of null" sometimes
  152. }).not.toThrow();
  153. });
  154. it('should render table with rows but no columns', () => {
  155. createDataArray(5, 0);
  156. var wt = new Walkontable.Core({
  157. table: $table[0],
  158. data: getData,
  159. totalRows: getTotalRows,
  160. totalColumns: getTotalColumns
  161. });
  162. wt.draw();
  163. expect($table.find('tbody tr').length).toBe(5);
  164. expect($table.find('tbody td').length).toBe(0);
  165. expect($table.find('tbody col').length).toBe(0);
  166. });
  167. });