fixedRowsBottom.spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. describe('settings', () => {
  2. describe('fixedRowsBottom', () => {
  3. const id = 'testContainer';
  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. describe('defined in constructor', () => {
  14. it('should show rows headers', () => {
  15. handsontable({
  16. fixedRowsBottom: 3
  17. });
  18. expect(getBottomClone().find('tbody tr').length).toEqual(3);
  19. });
  20. it('should show rows headers when headers are enabled', () => {
  21. handsontable({
  22. rowHeaders: true,
  23. colHeaders: true,
  24. fixedRowsBottom: 2
  25. });
  26. expect(getBottomClone().find('thead tr').length).toEqual(1);
  27. expect(getBottomClone().find('thead tr').height()).toEqual(0); // header is always invisible
  28. expect(getBottomClone().find('tbody tr').length).toEqual(2);
  29. });
  30. });
  31. describe('defined in updateSettings', () => {
  32. it('should increase fixed rows', () => {
  33. handsontable({
  34. fixedRowsBottom: 2
  35. });
  36. updateSettings({
  37. fixedRowsBottom: 4
  38. });
  39. expect(getBottomClone().find('tbody tr').length).toEqual(4);
  40. });
  41. it('should decrease fixed rows', () => {
  42. handsontable({
  43. fixedRowsBottom: 4
  44. });
  45. updateSettings({
  46. fixedRowsBottom: 2
  47. });
  48. expect(getBottomClone().find('tbody tr').length).toEqual(2);
  49. });
  50. it('should create fixed rows when they are disabled eariler', () => {
  51. handsontable({
  52. fixedRowsBottom: 0
  53. });
  54. updateSettings({
  55. fixedRowsBottom: 2
  56. });
  57. expect(getBottomClone().find('tbody tr').length).toEqual(2);
  58. });
  59. it('should disable fixed rows', () => {
  60. handsontable({
  61. fixedRowsBottom: 2
  62. });
  63. updateSettings({
  64. fixedRowsBottom: 0
  65. });
  66. expect(getBottomClone().find('tbody tr').length).toEqual(2);
  67. expect(getLeftClone().height()).toBe(0);
  68. });
  69. it('should not throw errors while scrolling vertically when fixed rows was set', async() => {
  70. const spy = jasmine.createSpyObj('error', ['test']);
  71. const prevError = window.onerror;
  72. window.onerror = function() {
  73. spy.test();
  74. };
  75. const hot = handsontable({
  76. data: Handsontable.helper.createSpreadsheetData(50, 50),
  77. width: 200,
  78. height: 200,
  79. rowHeaders: true,
  80. });
  81. updateSettings({
  82. fixedRowsBottom: 2
  83. });
  84. await sleep(100);
  85. hot.scrollViewportTo(30, 30);
  86. await sleep(100);
  87. expect(spy.test.calls.count()).toBe(0);
  88. window.onerror = prevError;
  89. });
  90. });
  91. it('should synchronize scroll with master table', async() => {
  92. handsontable({
  93. data: Handsontable.helper.createSpreadsheetData(50, 50),
  94. width: 200,
  95. height: 200,
  96. rowHeaders: true,
  97. fixedRowsBottom: 2,
  98. });
  99. getMaster().find('.wtHolder').scrollLeft(100);
  100. await sleep(10);
  101. expect(getBottomClone().find('.wtHolder').scrollLeft()).toBe(getMaster().find('.wtHolder').scrollLeft());
  102. });
  103. });
  104. });