e10888ff36d9d8a0445d2a33c4623a0362bccddc38edf9fb70f4002433b9f0c58d8f668acb2fe6a1dd48dc7cb1cba17a755e8d5ccb2f4d6d655878809c9305 5.2 KB

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