8
0

paragraph.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 Paragraph from '/ckeditor5/paragraph/paragraph.js';
  7. import VirtualTestEditor from '/tests/ckeditor5/_utils/virtualtesteditor.js';
  8. import { getData } from '/tests/engine/_utils/model.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. doc.createRoot();
  19. } );
  20. } );
  21. it( 'should be loaded', () => {
  22. expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
  23. } );
  24. it( 'should set proper schema rules', () => {
  25. expect( doc.schema.hasItem( 'paragraph' ) ).to.be.true;
  26. expect( doc.schema.check( { name: 'paragraph', inside: '$root' } ) ).to.be.true;
  27. expect( doc.schema.check( { name: '$inline', inside: 'paragraph' } ) ).to.be.true;
  28. } );
  29. it( 'should convert paragraph', () => {
  30. editor.setData( '<p>foobar</p>' );
  31. expect( getData( 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( getData( 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( getData( 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. } );