contextMenuCopyPaste.e2e.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. describe('ContextMenuCopyPaste', function () {
  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', function () {
  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. );
  41. }).parents('td');
  42. var $pasteButton = $contextMenuEntries.find('div').filter(function () {
  43. return (/Paste/i.test($(this).text())
  44. );
  45. }).parents('td');
  46. expect($contextMenuEntries.index($copyButton)).toEqual(0);
  47. expect($contextMenuEntries.index($pasteButton)).toEqual(1);
  48. });
  49. it('should add Copy and Paste context menu options at the provided index', function () {
  50. var hot = handsontable({
  51. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  52. rowHeaders: true,
  53. colHeaders: true,
  54. minSpareRows: 1,
  55. contextMenu: ['row_above', 'copy', 'paste', 'row_below'],
  56. contextMenuCopyPaste: {
  57. swfPath: '../../demo/swf/ZeroClipboard.swf'
  58. }
  59. });
  60. selectCell(1, 1);
  61. contextMenu();
  62. var $contextMenuEntries = $('.htContextMenu .ht_master .htCore tbody').find('td');
  63. var $copyButton = $contextMenuEntries.find('div').filter(function () {
  64. return (/Copy/i.test($(this).text())
  65. );
  66. }).parents('td');
  67. var $pasteButton = $contextMenuEntries.find('div').filter(function () {
  68. return (/Paste/i.test($(this).text())
  69. );
  70. }).parents('td');
  71. expect($contextMenuEntries.not('[class*=htSeparator]').index($copyButton)).toEqual(1);
  72. expect($contextMenuEntries.not('[class*=htSeparator]').index($pasteButton)).toEqual(2);
  73. });
  74. it('should disable `Copy` and `Paste` items when context menu was triggered from corner header', function () {
  75. var hot = handsontable({
  76. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  77. rowHeaders: true,
  78. colHeaders: true,
  79. minSpareRows: 1,
  80. contextMenu: true,
  81. contextMenuCopyPaste: {
  82. swfPath: '../../demo/swf/ZeroClipboard.swf'
  83. }
  84. });
  85. $('.ht_clone_top_left_corner .htCore').find('thead').find('th').eq(0).simulate('mousedown', { which: 3 });
  86. contextMenu();
  87. expect($('.htContextMenu tbody td.htDisabled').text()).toBe(['Copy', 'Paste', 'Insert column on the left', 'Insert column on the right', 'Remove row', 'Remove column', 'Undo', 'Redo', 'Read only', 'Alignment'].join(''));
  88. });
  89. // see https://github.com/handsontable/handsontable/issues/3140
  90. it('should not throwing error when ContextMenu plugin is disabled', function () {
  91. var spy = jasmine.createSpy();
  92. var prevError = window.onerror;
  93. window.onerror = function () {
  94. spy();
  95. };
  96. var hot = handsontable({
  97. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  98. rowHeaders: true,
  99. colHeaders: true,
  100. minSpareRows: 1,
  101. contextMenu: true,
  102. contextMenuCopyPaste: {
  103. swfPath: '../../demo/swf/ZeroClipboard.swf'
  104. }
  105. });
  106. hot.getPlugin('contextMenu').disablePlugin();
  107. $(getCell(0, 0)).simulate('mouseenter');
  108. expect(spy).not.toHaveBeenCalled();
  109. window.onerror = prevError;
  110. });
  111. });