8
0
Просмотр исходного кода

Added tests checking paragraph feature converters.

Szymon Kupś 9 лет назад
Родитель
Сommit
28219b4aea

+ 3 - 3
packages/ckeditor5-paragraph/src/paragraph.js

@@ -15,18 +15,18 @@ export default class Paragraph extends Feature {
 		const document = editor.document;
 		const schema = document.schema;
 		const data = editor.data;
-		const editing = editor.editing;
+		// const editing = editor.editing;
 
 		// Schema.
 		schema.registerItem( 'paragraph', '$block' );
 
 		// Build converter from model to view for data and editing pipelines.
-		BuildModelConverterFor( data.toView, editing.toView )
+		BuildModelConverterFor( data.modelToView )
 			.fromElement( 'paragraph' )
 			.toElement( 'p' );
 
 		// Build converter from view to model for data and editing pipelines.
-		BuildViewConverterFor( data.toModel, editing.toModel )
+		BuildViewConverterFor( data.viewToModel )
 			.fromElement( 'p' )
 			.toElement( 'paragraph' );
 	}

+ 29 - 2
packages/ckeditor5-paragraph/tests/paragraph.js

@@ -8,9 +8,10 @@
 import Paragraph from '/ckeditor5/paragraph/paragraph.js';
 import Editor from '/ckeditor5/editor.js';
 import StandardCreator from '/ckeditor5/creator/standardcreator.js';
+import { getData } from '/tests/engine/_utils/model.js';
 
 describe( 'Paragraph feature', () => {
-	let editor;
+	let editor, document;
 
 	beforeEach( () => {
 		editor = new Editor( null, {
@@ -18,10 +19,36 @@ describe( 'Paragraph feature', () => {
 			features: [ Paragraph ]
 		} );
 
-		return editor.init();
+		return editor.init().then( () => {
+			document = editor.document;
+		} );
 	} );
 
 	it( 'should be loaded', () => {
 		expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
 	} );
+
+	it( 'should convert paragraph', () => {
+		document.createRoot( 'main' );
+		editor.setData( '<p>foobar</p>' );
+
+		expect( getData( document, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+		expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+	} );
+
+	it( 'should convert paragraph only', () => {
+		document.createRoot( 'main' );
+		editor.setData( '<p>foo<b>baz</b>bar</p>' );
+
+		expect( getData( document, { withoutSelection: true } ) ).to.equal( '<paragraph>foobazbar</paragraph>' );
+		expect( editor.getData() ).to.equal( '<p>foobazbar</p>' );
+	} );
+
+	it( 'should convert multiple paragraphs', () => {
+		document.createRoot( 'main' );
+		editor.setData( '<p>foo</p><p>baz</p>' );
+
+		expect( getData( document, { withoutSelection: true } ) ).to.equal( '<paragraph>foo</paragraph><paragraph>baz</paragraph>' );
+		expect( editor.getData() ).to.equal( '<p>foo</p><p>baz</p>' );
+	} );
 } );