09dc9a03f7de6f5944ab2b49368cca968ad399038fa73aa8931c0b25b3f6e3dcb7e079d235c9af4e7a6c3245dcef0201ca23c6ce15d968ae33d4fd51b631bf 3.8 KB

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