paragraph.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Paragraph from '/ckeditor5/paragraph/paragraph.js';
  6. import VirtualTestEditor from '/tests/core/_utils/virtualtesteditor.js';
  7. import { getData as getModelData } from '/ckeditor5/engine/dev-utils/model.js';
  8. import { getData as getViewData } from '/ckeditor5/engine/dev-utils/view.js';
  9. describe( 'Paragraph feature', () => {
  10. let editor, doc;
  11. beforeEach( () => {
  12. return VirtualTestEditor.create( {
  13. features: [ Paragraph ]
  14. } )
  15. .then( newEditor => {
  16. editor = newEditor;
  17. doc = editor.document;
  18. } );
  19. } );
  20. it( 'should be loaded', () => {
  21. expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
  22. } );
  23. it( 'should set proper schema rules', () => {
  24. expect( doc.schema.hasItem( 'paragraph' ) ).to.be.true;
  25. expect( doc.schema.check( { name: 'paragraph', inside: '$root' } ) ).to.be.true;
  26. expect( doc.schema.check( { name: '$inline', inside: 'paragraph' } ) ).to.be.true;
  27. } );
  28. describe( 'data pipeline conversions', () => {
  29. it( 'should convert paragraph', () => {
  30. editor.setData( '<p>foobar</p>' );
  31. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
  32. expect( editor.getData() ).to.equal( '<p>foobar</p>' );
  33. } );
  34. it( 'should convert paragraph only', () => {
  35. editor.setData( '<p>foo<b>baz</b>bar</p>' );
  36. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobazbar</paragraph>' );
  37. expect( editor.getData() ).to.equal( '<p>foobazbar</p>' );
  38. } );
  39. it( 'should convert multiple paragraphs', () => {
  40. editor.setData( '<p>foo</p><p>baz</p>' );
  41. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foo</paragraph><paragraph>baz</paragraph>' );
  42. expect( editor.getData() ).to.equal( '<p>foo</p><p>baz</p>' );
  43. } );
  44. } );
  45. describe( 'editing pipeline conversion', () => {
  46. it( 'should convert paragraph', () => {
  47. // Workaround for setting model data: https://github.com/ckeditor/ckeditor5-engine/issues/455
  48. editor.setData( '<p>foo</p><p>bar</p>' );
  49. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p>foo</p><p>bar</p>' );
  50. } );
  51. } );
  52. } );