8
0

composer.js 2.1 KB

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