tableselection-clipboard.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  6. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  7. import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  8. import TableEditing from '../src/tableediting';
  9. import TableSelection from '../src/tableselection';
  10. import { modelTable } from './_utils/utils';
  11. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  12. describe( 'table selection', () => {
  13. let editor, model, modelRoot, tableSelection, viewDocument;
  14. beforeEach( async () => {
  15. editor = await VirtualTestEditor.create( {
  16. plugins: [ TableEditing, TableSelection, Paragraph, Clipboard ]
  17. } );
  18. model = editor.model;
  19. modelRoot = model.document.getRoot();
  20. viewDocument = editor.editing.view.document;
  21. tableSelection = editor.plugins.get( TableSelection );
  22. setModelData( model, modelTable( [
  23. [ '11[]', '12', '13' ],
  24. [ '21', '22', '23' ],
  25. [ '31', '32', '33' ]
  26. ] ) );
  27. } );
  28. afterEach( async () => {
  29. await editor.destroy();
  30. } );
  31. describe( 'Clipboard integration', () => {
  32. describe( 'cut', () => {
  33. it( 'is disabled for multi-range selection over a table', () => {
  34. const dataTransferMock = createDataTransfer();
  35. const preventDefaultSpy = sinon.spy();
  36. const spy = sinon.spy();
  37. viewDocument.on( 'clipboardOutput', spy );
  38. tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
  39. tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 1, 2 ] ) );
  40. viewDocument.fire( 'cut', {
  41. dataTransfer: dataTransferMock,
  42. preventDefault: preventDefaultSpy
  43. } );
  44. sinon.assert.notCalled( spy );
  45. sinon.assert.calledOnce( preventDefaultSpy );
  46. } );
  47. it( 'is not disabled normal selection over a table', () => {
  48. const dataTransferMock = createDataTransfer();
  49. const spy = sinon.spy();
  50. viewDocument.on( 'clipboardOutput', spy );
  51. viewDocument.fire( 'cut', {
  52. dataTransfer: dataTransferMock,
  53. preventDefault: sinon.spy()
  54. } );
  55. sinon.assert.calledOnce( spy );
  56. } );
  57. } );
  58. } );
  59. function createDataTransfer() {
  60. const store = new Map();
  61. return {
  62. setData( type, data ) {
  63. store.set( type, data );
  64. },
  65. getData( type ) {
  66. return store.get( type );
  67. }
  68. };
  69. }
  70. } );