955dccd58096e0bf84c8136e2aac9c6ff5f680a81c069112e4d25065718d9b9d126b204d77942bd2997c97716f1b56d1b077c32968a6a2939511d63c69e845 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. 'use strict';
  2. describe('columnHeaders 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 `htColumnHeaders` when column 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('htColumnHeaders')).toBe(false);
  32. });
  33. it('should add class `htColumnHeaders` when column headers are enabled', function () {
  34. var wt = new Walkontable.Core({
  35. table: $table[0],
  36. data: getData,
  37. totalRows: getTotalRows,
  38. totalColumns: getTotalColumns,
  39. columnHeaders: [function (col, TH) {
  40. TH.innerHTML = col + 1;
  41. }]
  42. });
  43. wt.draw();
  44. expect($wrapper.hasClass('htColumnHeaders')).toBe(true);
  45. });
  46. it('should create table with column headers', function () {
  47. var wt = new Walkontable.Core({
  48. table: $table[0],
  49. data: getData,
  50. totalRows: getTotalRows,
  51. totalColumns: getTotalColumns,
  52. columnHeaders: [function (col, TH) {
  53. TH.innerHTML = col + 1;
  54. }]
  55. });
  56. wt.draw();
  57. expect($wrapper.find('.ht_clone_left colgroup col').length).toBe(0);
  58. expect($wrapper.find('.ht_clone_left thead tr').length).toBe(1);
  59. expect($wrapper.find('.ht_clone_left tbody tr').length).toBe(0);
  60. expect($wrapper.find('.ht_clone_top colgroup col').length).toBe(4);
  61. expect($wrapper.find('.ht_clone_top thead tr').length).toBe(1);
  62. expect($wrapper.find('.ht_clone_top tbody tr').length).toBe(0);
  63. expect($wrapper.find('.ht_master colgroup col').length).toBe(4);
  64. expect($wrapper.find('.ht_master thead tr').length).toBe(1);
  65. expect($wrapper.find('.ht_master tbody tr').length).toBe(9);
  66. });
  67. it('should create column headers with correct height when th has css `white-space: normal`', function () {
  68. var style = $('<style>.handsontable thead th {white-space: normal;}</style>').appendTo('head');
  69. var wt = new Walkontable.Core({
  70. table: $table[0],
  71. data: getData,
  72. totalRows: getTotalRows,
  73. totalColumns: getTotalColumns,
  74. columnHeaders: [function (col, TH) {
  75. TH.innerHTML = 'Client State State';
  76. }],
  77. columnWidth: 80
  78. });
  79. wt.draw();
  80. expect($wrapper.find('.ht_clone_top thead tr').height()).toBe(43);
  81. style.remove();
  82. });
  83. it('should create column headers with correct height when th has css `white-space: pre-line` (default)', function () {
  84. var wt = new Walkontable.Core({
  85. table: $table[0],
  86. data: getData,
  87. totalRows: getTotalRows,
  88. totalColumns: getTotalColumns,
  89. columnHeaders: [function (col, TH) {
  90. TH.innerHTML = 'Client State State';
  91. }],
  92. columnWidth: 80
  93. });
  94. wt.draw();
  95. expect($wrapper.find('.ht_clone_top thead tr').height()).toBe(23);
  96. });
  97. it('should generate column headers from function', function () {
  98. var headers = ['Description', 2012, 2013, 2014];
  99. var wt = new Walkontable.Core({
  100. table: $table[0],
  101. data: getData,
  102. totalRows: getTotalRows,
  103. totalColumns: getTotalColumns,
  104. columnHeaders: [function (column, TH) {
  105. TH.innerHTML = headers[column];
  106. }]
  107. });
  108. wt.draw();
  109. var visibleHeaders = headers.slice(0, wt.wtTable.getLastRenderedColumn() + 1); // headers for rendered columns only
  110. expect($table.find('thead tr:first th').length).toBe(visibleHeaders.length);
  111. expect($table.find('thead tr:first th').text()).toEqual(visibleHeaders.join(''));
  112. });
  113. });