Core_countEmptyRows.spec.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. describe('Core_countEmptyRows', () => {
  2. const id = 'testContainer';
  3. beforeEach(function() {
  4. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  5. });
  6. afterEach(function() {
  7. if (this.$container) {
  8. destroy();
  9. this.$container.remove();
  10. }
  11. });
  12. it('should count empty rows properly when using a simple data set', () => {
  13. handsontable({
  14. data: [
  15. [null],
  16. [4],
  17. [null],
  18. [3],
  19. [1],
  20. [null],
  21. ]
  22. });
  23. expect(countEmptyRows()).toBe(3);
  24. });
  25. it('should count empty rows at the end of the data source properly (optional `ending` parameter)', () => {
  26. handsontable({
  27. data: [
  28. [null],
  29. [4],
  30. [null],
  31. [3],
  32. [1],
  33. [null],
  34. [null],
  35. [null],
  36. [null],
  37. [null],
  38. ]
  39. });
  40. expect(countEmptyRows(true)).toBe(5);
  41. });
  42. it('should count empty rows properly when using `minSpareRows` option', () => {
  43. handsontable({
  44. data: [
  45. [null],
  46. [4],
  47. [null],
  48. [3],
  49. [1],
  50. ],
  51. minSpareRows: 2
  52. });
  53. expect(countEmptyRows()).toBe(4);
  54. });
  55. it('should count empty rows properly when translating rows in the viewport', () => {
  56. handsontable({
  57. data: Handsontable.helper.createSpreadsheetData(5, 5),
  58. modifyRow(row) {
  59. return row + 2;
  60. }
  61. });
  62. expect(countEmptyRows()).toBe(2);
  63. });
  64. it('should count empty rows properly when translating rows below the viewport', () => {
  65. handsontable({
  66. data: Handsontable.helper.createSpreadsheetData(100, 100),
  67. modifyRow(row) {
  68. return row + 5;
  69. }
  70. });
  71. expect(countEmptyRows()).toBe(5);
  72. });
  73. it('should count empty rows properly when rows was trimmed', () => {
  74. handsontable({
  75. data: Handsontable.helper.createSpreadsheetData(10, 10),
  76. modifyRow(row) {
  77. if (row === 9 || row === 8) {
  78. return null;
  79. }
  80. if (row >= 2) {
  81. return row + 2;
  82. }
  83. return row;
  84. }
  85. });
  86. expect(countEmptyRows()).toBe(0);
  87. });
  88. });