8
0

composer.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: model, composer */
  6. import Document from '/ckeditor5/engine/model/document.js';
  7. import Composer from '/ckeditor5/engine/model/composer/composer.js';
  8. import { setData, getData } from '/tests/engine/_utils/model.js';
  9. describe( 'Composer', () => {
  10. let document, composer;
  11. beforeEach( () => {
  12. document = new Document();
  13. document.createRoot();
  14. composer = new Composer();
  15. } );
  16. describe( 'constructor', () => {
  17. it( 'attaches deleteContents default listener', () => {
  18. setData( document, '<p>f<selection>oo</p><p>ba</selection>r</p>' );
  19. const batch = document.batch();
  20. composer.fire( 'deleteContents', { batch, selection: document.selection } );
  21. expect( getData( document ) ).to.equal( '<p>f<selection /></p><p>r</p>' );
  22. expect( batch.deltas ).to.not.be.empty;
  23. } );
  24. it( 'attaches deleteContents default listener which passes options', () => {
  25. setData( document, '<p>f<selection>oo</p><p>ba</selection>r</p>' );
  26. const batch = document.batch();
  27. composer.fire( 'deleteContents', {
  28. batch,
  29. selection: document.selection,
  30. options: { merge: true }
  31. } );
  32. expect( getData( document ) ).to.equal( '<p>f<selection />r</p>' );
  33. } );
  34. it( 'attaches modifySelection default listener', () => {
  35. setData( document, '<p>foo<selection />bar</p>' );
  36. composer.fire( 'modifySelection', {
  37. selection: document.selection,
  38. options: {
  39. direction: 'backward'
  40. }
  41. } );
  42. expect( getData( document ) )
  43. .to.equal( '<p>fo<selection backward>o</selection>bar</p>' );
  44. } );
  45. } );
  46. describe( 'deleteContents', () => {
  47. it( 'fires deleteContents event', () => {
  48. const spy = sinon.spy();
  49. const batch = document.batch();
  50. composer.on( 'deleteContents', spy );
  51. composer.deleteContents( batch, document.selection );
  52. const data = spy.args[ 0 ][ 1 ];
  53. expect( data.batch ).to.equal( batch );
  54. expect( data.selection ).to.equal( document.selection );
  55. } );
  56. } );
  57. describe( 'modifySelection', () => {
  58. it( 'fires deleteContents event', () => {
  59. const spy = sinon.spy();
  60. const opts = { direction: 'backward' };
  61. composer.on( 'modifySelection', spy );
  62. composer.modifySelection( document.selection, opts );
  63. const data = spy.args[ 0 ][ 1 ];
  64. expect( data.selection ).to.equal( document.selection );
  65. expect( data.options ).to.equal( opts );
  66. } );
  67. } );
  68. } );