ff5bb779a643557dc1841b037c3b0bb1f53799d8e35c5c31e946356bfe63e69d2588a9fbed8953779a8c7530ba3cbb641e621156b3c3e75af0529f896bed44 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use strict';
  2. describe('rowHeaders option', function () {
  3. var $table,
  4. $container,
  5. $wrapper,
  6. debug = false;
  7. beforeEach(function () {
  8. $wrapper = $('<div></div>').css({ overflow: 'hidden', position: 'relative' });
  9. $wrapper.width(500).height(201);
  10. $container = $('<div></div>');
  11. $table = $('<table></table>'); // create a table that is not attached to document
  12. $wrapper.append($container);
  13. $container.append($table);
  14. $wrapper.appendTo('body');
  15. createDataArray();
  16. });
  17. afterEach(function () {
  18. if (!debug) {
  19. $('.wtHolder').remove();
  20. }
  21. $wrapper.remove();
  22. });
  23. it('should not add class `htRowHeader` when row headers are disabled', function () {
  24. var wt = new Walkontable.Core({
  25. table: $table[0],
  26. data: getData,
  27. totalRows: getTotalRows,
  28. totalColumns: getTotalColumns
  29. });
  30. wt.draw();
  31. expect($wrapper.hasClass('htRowHeaders')).toBe(false);
  32. });
  33. it('should add class `htRowHeader` when row headers are enabled', function () {
  34. var wt = new Walkontable.Core({
  35. table: $table[0],
  36. data: getData,
  37. totalRows: getTotalRows,
  38. totalColumns: getTotalColumns,
  39. rowHeaders: [function (row, TH) {
  40. TH.innerHTML = row + 1;
  41. }]
  42. });
  43. wt.draw();
  44. expect($wrapper.hasClass('htRowHeaders')).toBe(true);
  45. });
  46. it('should create table row headers', function () {
  47. var wt = new Walkontable.Core({
  48. table: $table[0],
  49. data: getData,
  50. totalRows: getTotalRows,
  51. totalColumns: getTotalColumns,
  52. rowHeaders: [function (row, TH) {
  53. TH.innerHTML = row + 1;
  54. }]
  55. });
  56. wt.draw();
  57. expect($wrapper.find('.ht_clone_left colgroup col').length).toBe(1);
  58. expect($wrapper.find('.ht_clone_left thead tr').length).toBe(0);
  59. expect($wrapper.find('.ht_clone_left tbody tr').length).toBe(9);
  60. expect($wrapper.find('.ht_clone_top colgroup col').length).toBe(0);
  61. expect($wrapper.find('.ht_clone_top thead tr').length).toBe(0);
  62. expect($wrapper.find('.ht_clone_top tbody tr').length).toBe(0);
  63. expect($wrapper.find('.ht_master colgroup col').length).toBe(5);
  64. expect($wrapper.find('.ht_master thead tr').length).toBe(0);
  65. expect($wrapper.find('.ht_master tbody tr').length).toBe(9);
  66. });
  67. it('should generate headers from function', function () {
  68. var wt = new Walkontable.Core({
  69. table: $table[0],
  70. data: getData,
  71. totalRows: getTotalRows,
  72. totalColumns: getTotalColumns,
  73. rowHeaders: [function (row, TH) {
  74. TH.innerHTML = row + 1;
  75. }]
  76. });
  77. wt.draw();
  78. var potentialRowCount = 9;
  79. expect($table.find('tbody td').length).toBe(potentialRowCount * wt.wtTable.getRenderedColumnsCount()); // displayed cells
  80. expect($table.find('tbody th').length).toBe(potentialRowCount); // 9*1=9 displayed row headers
  81. expect($table.find('tbody tr:first th').length).toBe(1); // only one th per row
  82. expect($table.find('tbody tr:first th')[0].innerHTML).toBe('1'); // this should be the first row header
  83. });
  84. it('should add \'rowHeader\' class to row header column', function () {
  85. var wt = new Walkontable.Core({
  86. table: $table[0],
  87. data: getData,
  88. totalRows: getTotalRows,
  89. totalColumns: getTotalColumns,
  90. rowHeaders: [function (row, TH) {
  91. TH.innerHTML = row + 1;
  92. }],
  93. columnHeaders: [function (col, TH) {
  94. TH.innerHTML = col + 1;
  95. }]
  96. });
  97. wt.draw();
  98. expect($table.find('col:first').hasClass('rowHeader')).toBe(true);
  99. });
  100. });