paragraph.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 as getModelData } from '/tests/engine/_utils/model.js';
  9. import { getData as getViewData } from '/tests/engine/_utils/view.js';
  10. describe( 'Paragraph feature', () => {
  11. let editor, doc;
  12. beforeEach( () => {
  13. return VirtualTestEditor.create( {
  14. features: [ Paragraph ]
  15. } )
  16. .then( newEditor => {
  17. editor = newEditor;
  18. doc = editor.document;
  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. describe( 'data pipeline conversions', () => {
  30. it( 'should convert paragraph', () => {
  31. editor.setData( '<p>foobar</p>' );
  32. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
  33. expect( editor.getData() ).to.equal( '<p>foobar</p>' );
  34. } );
  35. it( 'should convert paragraph only', () => {
  36. editor.setData( '<p>foo<b>baz</b>bar</p>' );
  37. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobazbar</paragraph>' );
  38. expect( editor.getData() ).to.equal( '<p>foobazbar</p>' );
  39. } );
  40. it( 'should convert multiple paragraphs', () => {
  41. editor.setData( '<p>foo</p><p>baz</p>' );
  42. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foo</paragraph><paragraph>baz</paragraph>' );
  43. expect( editor.getData() ).to.equal( '<p>foo</p><p>baz</p>' );
  44. } );
  45. } );
  46. describe( 'editing pipeline conversion', () => {
  47. it( 'should convert paragraph', () => {
  48. // Workaround for setting model data: https://github.com/ckeditor/ckeditor5-engine/issues/455
  49. editor.setData( '<p>foo</p><p>bar</p>' );
  50. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p>foo</p><p>bar</p>' );
  51. } );
  52. } );
  53. } );