fixedRowsTop.spec.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. describe('settings', () => {
  2. describe('fixedRowsTop', () => {
  3. var 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. fixedRowsTop: 3
  17. });
  18. expect(getTopClone().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. fixedRowsTop: 2
  25. });
  26. expect(getTopClone().find('thead tr').length).toEqual(1);
  27. expect(getTopClone().find('tbody tr').length).toEqual(2);
  28. });
  29. });
  30. describe('defined in updateSettings', () => {
  31. it('should increase fixed rows', () => {
  32. handsontable({
  33. fixedRowsTop: 2
  34. });
  35. updateSettings({
  36. fixedRowsTop: 4
  37. });
  38. expect(getTopClone().find('tbody tr').length).toEqual(4);
  39. });
  40. it('should decrease fixed rows', () => {
  41. handsontable({
  42. fixedRowsTop: 4
  43. });
  44. updateSettings({
  45. fixedRowsTop: 2
  46. });
  47. expect(getTopClone().find('tbody tr').length).toEqual(2);
  48. });
  49. it('should create fixed rows when they are disabled eariler', () => {
  50. handsontable({
  51. fixedRowsTop: 0
  52. });
  53. updateSettings({
  54. fixedRowsTop: 2
  55. });
  56. expect(getTopClone().find('tbody tr').length).toEqual(2);
  57. });
  58. it('should disable fixed rows', () => {
  59. handsontable({
  60. fixedRowsTop: 2
  61. });
  62. updateSettings({
  63. fixedRowsTop: 0
  64. });
  65. expect(getTopClone().find('tbody tr').length).toEqual(2);
  66. expect(getLeftClone().height()).toBe(0);
  67. });
  68. it('should not throw errors while scrolling vertically when fixed rows was set', (done) => {
  69. var spy = jasmine.createSpyObj('error', ['test']);
  70. var prevError = window.onerror;
  71. window.onerror = function(messageOrEvent, source, lineno, colno, error) {
  72. spy.test();
  73. };
  74. var hot = handsontable({
  75. data: Handsontable.helper.createSpreadsheetData(50, 50),
  76. width: 200,
  77. height: 200,
  78. rowHeaders: true,
  79. });
  80. updateSettings({
  81. fixedRowsTop: 2
  82. });
  83. setTimeout(() => {
  84. hot.scrollViewportTo(30, 30);
  85. }, 100);
  86. setTimeout(() => {
  87. expect(spy.test.calls.count()).toBe(0);
  88. done();
  89. window.onerror = prevError;
  90. }, 200);
  91. });
  92. });
  93. });
  94. });