8
0

table-integration.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Widget from '@ckeditor/ckeditor5-widget/src/widget';
  6. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  7. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  8. import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
  9. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  10. import {
  11. getData as getModelData,
  12. setData as setModelData
  13. } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  14. import { parse as parseView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  15. import TableEditing from '../src/tableediting';
  16. import { formatTable, formattedModelTable, modelTable } from './_utils/utils';
  17. describe( 'Table feature – integration', () => {
  18. describe( 'with clipboard', () => {
  19. it( 'pastes td as p when pasting into the table', () => {
  20. return VirtualTestEditor
  21. .create( { plugins: [ Paragraph, TableEditing, Widget, Clipboard ] } )
  22. .then( newEditor => {
  23. const editor = newEditor;
  24. const clipboard = editor.plugins.get( 'Clipboard' );
  25. setModelData( editor.model, modelTable( [ [ 'foo[]' ] ] ) );
  26. clipboard.fire( 'inputTransformation', {
  27. content: parseView( '<td>bar</td>' )
  28. } );
  29. expect( formatTable( getModelData( editor.model ) ) ).to.equal( formattedModelTable( [
  30. [ 'foobar[]' ]
  31. ] ) );
  32. } );
  33. } );
  34. it( 'pastes td as p when pasting into the p', () => {
  35. return VirtualTestEditor
  36. .create( { plugins: [ Paragraph, TableEditing, Widget, Clipboard ] } )
  37. .then( newEditor => {
  38. const editor = newEditor;
  39. const clipboard = editor.plugins.get( 'Clipboard' );
  40. setModelData( editor.model, '<paragraph>foo[]</paragraph>' );
  41. clipboard.fire( 'inputTransformation', {
  42. content: parseView( '<td>bar</td>' )
  43. } );
  44. expect( formatTable( getModelData( editor.model ) ) ).to.equal( '<paragraph>foobar[]</paragraph>' );
  45. } );
  46. } );
  47. } );
  48. describe( 'with undo', () => {
  49. it( 'fixing empty roots should be transparent to undo', () => {
  50. return VirtualTestEditor
  51. .create( { plugins: [ Paragraph, UndoEditing ] } )
  52. .then( newEditor => {
  53. const editor = newEditor;
  54. const doc = editor.model.document;
  55. const root = doc.getRoot();
  56. expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
  57. expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
  58. editor.setData( '<p>Foobar.</p>' );
  59. editor.model.change( writer => {
  60. writer.remove( root.getChild( 0 ) );
  61. } );
  62. expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
  63. editor.execute( 'undo' );
  64. expect( editor.getData() ).to.equal( '<p>Foobar.</p>' );
  65. editor.execute( 'redo' );
  66. expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
  67. editor.execute( 'undo' );
  68. expect( editor.getData() ).to.equal( '<p>Foobar.</p>' );
  69. } );
  70. } );
  71. it( 'fixing empty roots should be transparent to undo - multiple roots', () => {
  72. return VirtualTestEditor
  73. .create( { plugins: [ Paragraph, UndoEditing ] } )
  74. .then( newEditor => {
  75. const editor = newEditor;
  76. const doc = editor.model.document;
  77. const root = doc.getRoot();
  78. const otherRoot = doc.createRoot( '$root', 'otherRoot' );
  79. editor.data.set( '<p>Foobar.</p>', 'main' );
  80. editor.data.set( '<p>Foobar.</p>', 'otherRoot' );
  81. editor.model.change( writer => {
  82. writer.remove( root.getChild( 0 ) );
  83. } );
  84. editor.model.change( writer => {
  85. writer.remove( otherRoot.getChild( 0 ) );
  86. } );
  87. expect( editor.data.get( 'main' ) ).to.equal( '<p>&nbsp;</p>' );
  88. expect( editor.data.get( 'otherRoot' ) ).to.equal( '<p>&nbsp;</p>' );
  89. editor.execute( 'undo' );
  90. expect( editor.data.get( 'main' ) ).to.equal( '<p>&nbsp;</p>' );
  91. expect( editor.data.get( 'otherRoot' ) ).to.equal( '<p>Foobar.</p>' );
  92. editor.execute( 'undo' );
  93. expect( editor.data.get( 'main' ) ).to.equal( '<p>Foobar.</p>' );
  94. expect( editor.data.get( 'otherRoot' ) ).to.equal( '<p>Foobar.</p>' );
  95. } );
  96. } );
  97. } );
  98. } );