de1b523808d8284d9d8e6ed89d15a0ef68a4cb8467d1208f116bcebb95ef2bab818c007bb581fa5040fef38f75130662c6ec00faa401333c0f552847f9a4f1 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. describe('Core.spliceRow', () => {
  2. var 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 remove from the second row three columns starting from the beginning', () => {
  13. var hot = handsontable({
  14. data: Handsontable.helper.createSpreadsheetData(5, 5),
  15. });
  16. var removedData = hot.spliceRow(1, 0, 3);
  17. expect(removedData).toEqual(['A2', 'B2', 'C2']);
  18. expect(hot.getDataAtRow(0)).toEqual(['A1', 'B1', 'C1', 'D1', 'E1']);
  19. expect(hot.getDataAtRow(1)).toEqual(['D2', 'E2', null, null, null]);
  20. expect(hot.getDataAtRow(2)).toEqual(['A3', 'B3', 'C3', 'D3', 'E3']);
  21. expect(hot.getDataAtRow(3)).toEqual(['A4', 'B4', 'C4', 'D4', 'E4']);
  22. expect(hot.getDataAtRow(4)).toEqual(['A5', 'B5', 'C5', 'D5', 'E5']);
  23. });
  24. it('should remove from the third row three columns starting from the second column', () => {
  25. var hot = handsontable({
  26. data: Handsontable.helper.createSpreadsheetData(5, 5),
  27. });
  28. var removedData = hot.spliceRow(2, 1, 3);
  29. expect(removedData).toEqual(['B3', 'C3', 'D3']);
  30. expect(hot.getDataAtRow(0)).toEqual(['A1', 'B1', 'C1', 'D1', 'E1']);
  31. expect(hot.getDataAtRow(1)).toEqual(['A2', 'B2', 'C2', 'D2', 'E2']);
  32. expect(hot.getDataAtRow(2)).toEqual(['A3', 'E3', null, null, null]);
  33. expect(hot.getDataAtRow(3)).toEqual(['A4', 'B4', 'C4', 'D4', 'E4']);
  34. expect(hot.getDataAtRow(4)).toEqual(['A5', 'B5', 'C5', 'D5', 'E5']);
  35. });
  36. it('should replace and append new columns in the second row starting from the second column', () => {
  37. var hot = handsontable({
  38. data: Handsontable.helper.createSpreadsheetData(5, 5),
  39. });
  40. var removedData = hot.spliceRow(1, 1, 3, 'X1', 'X2', 'X3', 'X4', 'X5');
  41. expect(removedData).toEqual(['B2', 'C2', 'D2']);
  42. expect(hot.getDataAtRow(0)).toEqual(['A1', 'B1', 'C1', 'D1', 'E1', null, null]);
  43. expect(hot.getDataAtRow(1)).toEqual(['A2', 'X1', 'X2', 'X3', 'X4', 'X5', 'E2']);
  44. expect(hot.getDataAtRow(2)).toEqual(['A3', 'B3', 'C3', 'D3', 'E3', null, null]);
  45. expect(hot.getDataAtRow(3)).toEqual(['A4', 'B4', 'C4', 'D4', 'E4', null, null]);
  46. expect(hot.getDataAtRow(4)).toEqual(['A5', 'B5', 'C5', 'D5', 'E5', null, null]);
  47. });
  48. it('should trigger beforeChange and afterChange hook with proper arguments', () => {
  49. var spyAfter = jasmine.createSpy('after');
  50. var spyBefore = jasmine.createSpy('before');
  51. var hot = handsontable({
  52. data: Handsontable.helper.createSpreadsheetData(5, 5),
  53. beforeChange: spyBefore,
  54. afterChange: spyAfter,
  55. });
  56. hot.spliceRow(2, 1, 3, 'X1');
  57. expect(spyBefore.calls.argsFor(0)[0]).toEqual([[2, 1, 'B3', 'X1'], [2, 2, 'C3', 'E3'], [2, 3, 'D3', null], [2, 4, 'E3', null], [2, 5, undefined, null]]);
  58. expect(spyBefore.calls.argsFor(0)[1]).toBe('spliceRow');
  59. expect(spyAfter.calls.argsFor(1)[0]).toEqual([[2, 1, 'B3', 'X1'], [2, 2, 'C3', 'E3'], [2, 3, 'D3', null], [2, 4, 'E3', null], [2, 5, undefined, null]]);
  60. expect(spyAfter.calls.argsFor(1)[1]).toBe('spliceRow');
  61. });
  62. it('should trigger beforeCreateCol and afterCreateCol hook with proper arguments', () => {
  63. var spyAfter = jasmine.createSpy('after');
  64. var spyBefore = jasmine.createSpy('before');
  65. var hot = handsontable({
  66. data: Handsontable.helper.createSpreadsheetData(5, 5),
  67. beforeCreateCol: spyBefore,
  68. afterCreateCol: spyAfter,
  69. });
  70. hot.spliceRow(2, 1, 3, 'X1', 'X2', 'X3', 'X4');
  71. expect(spyBefore).toHaveBeenCalledWith(5, 1, 'spliceRow', undefined, undefined, undefined);
  72. expect(spyAfter).toHaveBeenCalledWith(5, 1, 'spliceRow', undefined, undefined, undefined);
  73. });
  74. });