Core_countEmptyCols.spec.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* eslint-disable no-multi-spaces, array-bracket-spacing */
  2. describe('Core_countEmptyCols', () => {
  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. it('should count empty columns properly for empty data set', () => {
  14. handsontable({
  15. data: []
  16. });
  17. expect(countEmptyCols()).toBe(0);
  18. });
  19. it('should count empty columns properly when using a simple data set', () => {
  20. handsontable({
  21. data: [
  22. [null, null, 1, null, null, null],
  23. [4, null, null, null, null, null],
  24. [null, null, null, null, null, null],
  25. [3, null, null, null, null, null],
  26. [1, null, null, null, null, null],
  27. [null, null, null, null, 1, null],
  28. ]
  29. });
  30. expect(countEmptyCols()).toBe(3);
  31. });
  32. it('should count empty columns at the end of the data source properly (optional `ending` parameter)', () => {
  33. handsontable({
  34. data: [
  35. [null, null, 1, null, null, null],
  36. [4, null, null, null, null, null],
  37. [null, null, null, null, null, null],
  38. [3, null, null, null, null, null],
  39. [1, null, null, null, null, null],
  40. [null, null, null, null, 1, null],
  41. ]
  42. });
  43. expect(countEmptyCols(true)).toBe(1);
  44. });
  45. it('should count empty columns properly when using `minSpareCols` option', () => {
  46. handsontable({
  47. data: [
  48. [null, null, 1, null, null],
  49. [4, null, null, null, null],
  50. [null, null, null, null, null],
  51. [3, null, null, null, null],
  52. [1, null, null, null, null],
  53. [null, null, null, null, 1 ],
  54. ],
  55. minSpareCols: 2
  56. });
  57. expect(countEmptyCols()).toBe(4);
  58. });
  59. it('should count empty columns properly when translating columns in the viewport', () => {
  60. handsontable({
  61. data: Handsontable.helper.createSpreadsheetData(5, 5),
  62. modifyCol(row) {
  63. return row + 2;
  64. }
  65. });
  66. expect(countEmptyCols()).toBe(2);
  67. });
  68. it('should count empty columns properly when translating columns outside the viewport', () => {
  69. handsontable({
  70. data: Handsontable.helper.createSpreadsheetData(100, 100),
  71. modifyCol(column) {
  72. return column + 5;
  73. }
  74. });
  75. expect(countEmptyCols()).toBe(5);
  76. });
  77. });