blockquoteengine.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import BlockQuoteEngine from '../src/blockquoteengine';
  6. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  7. import ListEngine from '@ckeditor/ckeditor5-list/src/listengine';
  8. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  9. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import BlockQuoteCommand from '../src/blockquotecommand';
  11. describe( 'BlockQuoteEngine', () => {
  12. let editor, model;
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ BlockQuoteEngine, Paragraph ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. model = editor.model;
  21. } );
  22. } );
  23. afterEach( () => {
  24. return editor.destroy();
  25. } );
  26. it( 'adds a blockQuote command', () => {
  27. expect( editor.commands.get( 'blockQuote' ) ).to.be.instanceOf( BlockQuoteCommand );
  28. } );
  29. it( 'allows for blockQuote in the $root', () => {
  30. expect( model.schema.checkChild( [ '$root' ], 'blockQuote' ) ).to.be.true;
  31. } );
  32. it( 'allows for $block in blockQuote', () => {
  33. expect( model.schema.checkChild( [ '$root', 'blockQuote' ], '$block' ) ).to.be.true;
  34. expect( model.schema.checkChild( [ '$root', 'blockQuote' ], 'paragraph' ) ).to.be.true;
  35. } );
  36. it( 'does not allow for blockQuote in blockQuote', () => {
  37. expect( model.schema.checkChild( [ '$root', 'blockQuote' ], 'blockQuote' ) ).to.be.false;
  38. } );
  39. it( 'does not break when checking an unregisterd item', () => {
  40. expect( model.schema.checkChild( [ '$root', 'blockQuote' ], 'foo' ) ).to.be.false;
  41. } );
  42. it( 'adds converters to the data pipeline', () => {
  43. const data = '<blockquote><p>x</p></blockquote>';
  44. editor.setData( data );
  45. expect( getModelData( model ) ).to.equal( '<blockQuote><paragraph>[]x</paragraph></blockQuote>' );
  46. expect( editor.getData() ).to.equal( data );
  47. } );
  48. it( 'adds a converter to the view pipeline', () => {
  49. setModelData( model, '<blockQuote><paragraph>x</paragraph></blockQuote>' );
  50. expect( editor.getData() ).to.equal( '<blockquote><p>x</p></blockquote>' );
  51. } );
  52. it( 'allows list items inside blockQuote', () => {
  53. return VirtualTestEditor
  54. .create( {
  55. plugins: [ BlockQuoteEngine, Paragraph, ListEngine ]
  56. } )
  57. .then( editor => {
  58. editor.setData( '<blockquote><ul><li>xx</li></ul></blockquote>' );
  59. expect( editor.getData() ).to.equal( '<blockquote><ul><li>xx</li></ul></blockquote>' );
  60. } );
  61. } );
  62. } );