3e1dd7e18b83e23958f7d44b7988ce3751c4c9e5bc3bdbd1bc480bd91f9d49f96c62493c99182a0118e05f093f7bbc6326317e0470fb49cdbaa2f7fea76a98 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. describe('ContextMenuCopyPaste', () => {
  2. var id = 'testContainer';
  3. if (typeof navigator.mimeTypes['application/x-shockwave-flash'] === 'undefined') {
  4. navigator.mimeTypes['application/x-shockwave-flash'] = {}; // mock Adobe Flash plugin so that contextMenuCopyPaste.js does not throw an error in PhantomJS
  5. }
  6. beforeEach(function() {
  7. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  8. var wrapper = $('<div></div>').css({
  9. width: 400,
  10. height: 200,
  11. overflow: 'scroll'
  12. });
  13. this.$wrapper = this.$container.wrap(wrapper).parent();
  14. });
  15. afterEach(function() {
  16. if (this.$container) {
  17. destroy();
  18. this.$container.remove();
  19. }
  20. this.$wrapper.remove();
  21. $('head').find('script[src*=ZeroClipboard]').remove();
  22. delete window.ZeroClipboard;
  23. });
  24. it('should add Copy and Paste context menu options at the beginning by default', () => {
  25. var hot = handsontable({
  26. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  27. rowHeaders: true,
  28. colHeaders: true,
  29. minSpareRows: 1,
  30. contextMenu: true,
  31. contextMenuCopyPaste: {
  32. swfPath: '../../demo/swf/ZeroClipboard.swf'
  33. }
  34. });
  35. selectCell(1, 1);
  36. contextMenu();
  37. var $contextMenuEntries = $('.htContextMenu .ht_master .htCore tbody').find('td');
  38. var $copyButton = $contextMenuEntries.find('div').filter(function() {
  39. return (/Copy/i).test($(this).text());
  40. }).parents('td');
  41. var $pasteButton = $contextMenuEntries.find('div').filter(function() {
  42. return (/Paste/i).test($(this).text());
  43. }).parents('td');
  44. expect($contextMenuEntries.index($copyButton)).toEqual(0);
  45. expect($contextMenuEntries.index($pasteButton)).toEqual(1);
  46. });
  47. it('should add Copy and Paste context menu options at the provided index', () => {
  48. var hot = handsontable({
  49. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  50. rowHeaders: true,
  51. colHeaders: true,
  52. minSpareRows: 1,
  53. contextMenu: ['row_above', 'copy', 'paste', 'row_below'],
  54. contextMenuCopyPaste: {
  55. swfPath: '../../demo/swf/ZeroClipboard.swf'
  56. }
  57. });
  58. selectCell(1, 1);
  59. contextMenu();
  60. var $contextMenuEntries = $('.htContextMenu .ht_master .htCore tbody').find('td');
  61. var $copyButton = $contextMenuEntries.find('div').filter(function() {
  62. return (/Copy/i).test($(this).text());
  63. }).parents('td');
  64. var $pasteButton = $contextMenuEntries.find('div').filter(function() {
  65. return (/Paste/i).test($(this).text());
  66. }).parents('td');
  67. expect($contextMenuEntries.not('[class*=htSeparator]').index($copyButton)).toEqual(1);
  68. expect($contextMenuEntries.not('[class*=htSeparator]').index($pasteButton)).toEqual(2);
  69. });
  70. it('should disable `Copy` and `Paste` items when context menu was triggered from corner header', () => {
  71. var hot = handsontable({
  72. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  73. rowHeaders: true,
  74. colHeaders: true,
  75. minSpareRows: 1,
  76. contextMenu: true,
  77. contextMenuCopyPaste: {
  78. swfPath: '../../demo/swf/ZeroClipboard.swf'
  79. }
  80. });
  81. $('.ht_clone_top_left_corner .htCore').find('thead').find('th').eq(0).simulate('mousedown', {which: 3});
  82. contextMenu();
  83. expect($('.htContextMenu tbody td.htDisabled').text()).toBe([
  84. 'Copy',
  85. 'Paste',
  86. 'Insert column on the left',
  87. 'Insert column on the right',
  88. 'Remove row',
  89. 'Remove column',
  90. 'Undo',
  91. 'Redo',
  92. 'Read only',
  93. 'Alignment',
  94. ].join(''));
  95. });
  96. // see https://github.com/handsontable/handsontable/issues/3140
  97. it('should not throwing error when ContextMenu plugin is disabled', () => {
  98. var spy = jasmine.createSpy();
  99. var prevError = window.onerror;
  100. window.onerror = function() {
  101. spy();
  102. };
  103. var hot = handsontable({
  104. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  105. rowHeaders: true,
  106. colHeaders: true,
  107. minSpareRows: 1,
  108. contextMenu: true,
  109. contextMenuCopyPaste: {
  110. swfPath: '../../demo/swf/ZeroClipboard.swf'
  111. }
  112. });
  113. hot.getPlugin('contextMenu').disablePlugin();
  114. $(getCell(0, 0)).simulate('mouseenter');
  115. expect(spy).not.toHaveBeenCalled();
  116. window.onerror = prevError;
  117. });
  118. });