8
0

composer.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import Document from '/ckeditor5/engine/treemodel/document.js';
  7. import Composer from '/ckeditor5/engine/treemodel/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( 'main', '$root' );
  14. composer = new Composer();
  15. } );
  16. describe( 'constructor', () => {
  17. it( 'attaches deleteContents default listener', () => {
  18. setData( document, 'main', '<p><selection>foo</selection>bar</p>' );
  19. const batch = document.batch();
  20. composer.fire( 'deleteContents', { batch, selection: document.selection } );
  21. expect( getData( document, 'main' ) ).to.equal( '<p>bar</p>' );
  22. expect( batch.deltas ).to.not.be.empty;
  23. } );
  24. it( 'attaches modifySelection default listener', () => {
  25. setData( document, 'main', '<p>foo<selection />bar</p>' );
  26. composer.fire( 'modifySelection', {
  27. selection: document.selection,
  28. options: {
  29. direction: 'BACKWARD'
  30. }
  31. } );
  32. expect( getData( document, 'main', { selection: true } ) )
  33. .to.equal( '<p>fo<selection backward>o</selection>bar</p>' );
  34. } );
  35. } );
  36. describe( 'deleteContents', () => {
  37. it( 'fires deleteContents event', () => {
  38. const spy = sinon.spy();
  39. const batch = document.batch();
  40. composer.on( 'deleteContents', spy );
  41. composer.deleteContents( batch, document.selection );
  42. const data = spy.args[ 0 ][ 1 ];
  43. expect( data.batch ).to.equal( batch );
  44. expect( data.selection ).to.equal( document.selection );
  45. } );
  46. } );
  47. describe( 'modifySelection', () => {
  48. it( 'fires deleteContents event', () => {
  49. const spy = sinon.spy();
  50. const opts = { direction: 'backward' };
  51. composer.on( 'modifySelection', spy );
  52. composer.modifySelection( document.selection, opts );
  53. const data = spy.args[ 0 ][ 1 ];
  54. expect( data.selection ).to.equal( document.selection );
  55. expect( data.options ).to.equal( opts );
  56. } );
  57. } );
  58. } );