Browse Source

Tests: Added tests for the editing pipeline.

Piotrek Koszuliński 9 years ago
parent
commit
1b08d5bea2

+ 12 - 4
packages/ckeditor5-paragraph/src/paragraph.js

@@ -9,23 +9,31 @@ import Feature from '../feature.js';
 import BuildModelConverterFor from '../engine/conversion/model-converter-builder.js';
 import BuildViewConverterFor from '../engine/conversion/view-converter-builder.js';
 
+/**
+ * A paragraph feature for editor.
+ * Introduces `<paragraph>` element in the model which renders as `<p>` in the DOM and data.
+ *
+ * @memberOf paragraph
+ * @extends ckeditor5.Feature
+ */
 export default class Paragraph extends Feature {
+	/**
+	 * @inheritDoc
+	 */
 	init() {
 		const editor = this.editor;
-		const document = editor.document;
-		const schema = document.schema;
 		const data = editor.data;
 		const editing = editor.editing;
 
 		// Schema.
-		schema.registerItem( 'paragraph', '$block' );
+		editor.document.schema.registerItem( 'paragraph', '$block' );
 
 		// Build converter from model to view for data and editing pipelines.
 		BuildModelConverterFor( data.modelToView, editing.modelToView )
 			.fromElement( 'paragraph' )
 			.toElement( 'p' );
 
-		// Build converter from view to model for data and editing pipelines.
+		// Build converter from view to model for data pipeline.
 		BuildViewConverterFor( data.viewToModel )
 			.fromElement( 'p' )
 			.toElement( 'paragraph' );

+ 26 - 14
packages/ckeditor5-paragraph/tests/paragraph.js

@@ -7,7 +7,8 @@
 
 import Paragraph from '/ckeditor5/paragraph/paragraph.js';
 import VirtualTestEditor from '/tests/ckeditor5/_utils/virtualtesteditor.js';
-import { getData } from '/tests/engine/_utils/model.js';
+import { getData as getModelData } from '/tests/engine/_utils/model.js';
+import { getData as getViewData } from '/tests/engine/_utils/view.js';
 
 describe( 'Paragraph feature', () => {
 	let editor, doc;
@@ -32,24 +33,35 @@ describe( 'Paragraph feature', () => {
 		expect( doc.schema.check( { name: '$inline', inside: 'paragraph' } ) ).to.be.true;
 	} );
 
-	it( 'should convert paragraph', () => {
-		editor.setData( '<p>foobar</p>' );
+	describe( 'data pipeline conversions', () => {
+		it( 'should convert paragraph', () => {
+			editor.setData( '<p>foobar</p>' );
 
-		expect( getData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
-		expect( editor.getData() ).to.equal( '<p>foobar</p>' );
-	} );
+			expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+		} );
+
+		it( 'should convert paragraph only', () => {
+			editor.setData( '<p>foo<b>baz</b>bar</p>' );
+
+			expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobazbar</paragraph>' );
+			expect( editor.getData() ).to.equal( '<p>foobazbar</p>' );
+		} );
 
-	it( 'should convert paragraph only', () => {
-		editor.setData( '<p>foo<b>baz</b>bar</p>' );
+		it( 'should convert multiple paragraphs', () => {
+			editor.setData( '<p>foo</p><p>baz</p>' );
 
-		expect( getData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foobazbar</paragraph>' );
-		expect( editor.getData() ).to.equal( '<p>foobazbar</p>' );
+			expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foo</paragraph><paragraph>baz</paragraph>' );
+			expect( editor.getData() ).to.equal( '<p>foo</p><p>baz</p>' );
+		} );
 	} );
 
-	it( 'should convert multiple paragraphs', () => {
-		editor.setData( '<p>foo</p><p>baz</p>' );
+	describe( 'editing pipeline conversion', () => {
+		it( 'should convert paragraph', () => {
+			// Workaround for setting model data: https://github.com/ckeditor/ckeditor5-engine/issues/455
+			editor.setData( '<p>foo</p><p>bar</p>' );
 
-		expect( getData( doc, { withoutSelection: true } ) ).to.equal( '<paragraph>foo</paragraph><paragraph>baz</paragraph>' );
-		expect( editor.getData() ).to.equal( '<p>foo</p><p>baz</p>' );
+			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p>foo</p><p>bar</p>' );
+		} );
 	} );
 } );