46007d249372d8c36ca5df2658aea3ca95becc18bf0923667020e04e3d2dfaa028fe1ed0e9528d63eb6187a9d41edf53fa23dbe6b82bad0394a82ad1d01ce0 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. describe('Core_copy', () => {
  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. var arrayOfArrays = function() {
  13. return [
  14. ['', 'Kia', 'Nissan', 'Toyota', 'Honda'],
  15. ['2008', 10, 11, 12, 13],
  16. ['2009', 20, 11, 14, 13],
  17. ['2010', 30, 15, 12, 13]
  18. ];
  19. };
  20. it('should set copyable text until copyRowsLimit is reached', () => {
  21. handsontable({
  22. data: arrayOfArrays(),
  23. copyRowsLimit: 2
  24. });
  25. selectCell(0, 0, countRows() - 1, countCols() - 1); // selectAll
  26. keyDownUp('ctrl');
  27. // should prepare 2 rows for copying
  28. expect($('textarea.copyPaste').val()).toEqual('\tKia\tNissan\tToyota\tHonda\n2008\t10\t11\t12\t13');
  29. });
  30. it('should set copyable text until copyColsLimit is reached', () => {
  31. handsontable({
  32. data: arrayOfArrays(),
  33. copyColsLimit: 2
  34. });
  35. selectCell(0, 0, countRows() - 1, countCols() - 1); // selectAll
  36. keyDownUp('ctrl');
  37. // should prepare 2 columns for copying
  38. expect($('textarea.copyPaste').val()).toEqual('\tKia\n2008\t10\n2009\t20\n2010\t30');
  39. });
  40. it('should call onCopyLimit callback when copy limit was reached', () => {
  41. var result;
  42. handsontable({
  43. data: arrayOfArrays(),
  44. copyRowsLimit: 2,
  45. copyColsLimit: 2,
  46. afterCopyLimit(selectedRowsCount, selectedColsCount, copyRowsLimit, copyColsLimit) {
  47. result = [selectedRowsCount, selectedColsCount, copyRowsLimit, copyColsLimit];
  48. }
  49. });
  50. selectCell(0, 0, countRows() - 1, countCols() - 1); // selectAll
  51. keyDownUp('ctrl');
  52. expect(result).toEqual([4, 5, 2, 2]);
  53. });
  54. it('ctrl+x should cut selected data', async () => {
  55. var hot = handsontable({
  56. data: arrayOfArrays()
  57. });
  58. selectCell(0, 0, countRows() - 1, countCols() - 1); // selectAll
  59. keyDownUp('ctrl+x');
  60. await sleep(300);
  61. expect(hot.getDataAtCell(0, 0)).toEqual('');
  62. expect(hot.getDataAtCell(1, 1)).toEqual('');
  63. expect(hot.getDataAtCell(2, 2)).toEqual('');
  64. });
  65. it('ctrl+v should paste copied data to selected range', async () => {
  66. const hot = handsontable({
  67. data: arrayOfArrays()
  68. });
  69. $('textarea.copyPaste').val('\tKia\tNissan\tToyota\tHonda\n2008\t10\t11\t12\t13');
  70. selectCell(0, 0, countRows() - 1, countCols() - 1); // selectAll
  71. keyDownUp('ctrl+v');
  72. await sleep(200);
  73. expect(hot.getDataAtCell(0, 0)).toEqual('');
  74. expect(hot.getDataAtCell(0, 1)).toEqual('Kia');
  75. expect(hot.getDataAtCell(0, 2)).toEqual('Nissan');
  76. expect(hot.getDataAtCell(0, 3)).toEqual('Toyota');
  77. expect(hot.getDataAtCell(1, 0)).toEqual('2008');
  78. expect(hot.getDataAtCell(1, 1)).toEqual('10');
  79. expect(hot.getDataAtCell(1, 2)).toEqual('11');
  80. expect(hot.getDataAtCell(1, 3)).toEqual('12');
  81. });
  82. });