浏览代码

Third batch of changes aligning schema use to the new API.

Piotrek Koszuliński 8 年之前
父节点
当前提交
b18f3d1786

+ 15 - 11
packages/ckeditor5-basic-styles/tests/attributecommand.js

@@ -29,18 +29,20 @@ describe( 'AttributeCommand', () => {
 				model.schema.register( 'p', { inheritAllFrom: '$block' } );
 				model.schema.register( 'h1', { inheritAllFrom: '$block' } );
 				model.schema.register( 'img', {
-					allowWhere: '$block',
+					allowWhere: [ '$block', '$text' ],
 					isObject: true
 				} );
 
-				// TODO the following rules are odd
+				model.schema.on( 'checkAttribute', ( evt, args ) => {
+					const ctx = args[ 0 ];
+					const attributeName = args[ 1 ];
 
-				// Bold text is allowed only in P.
-				// model.schema.xallow( { name: '$text', attributes: 'bold', inside: 'p' } );
-				// model.schema.xallow( { name: 'p', attributes: 'bold', inside: '$root' } );
-
-				// Disallow bold on image.
-				// model.schema.xdisallow( { name: 'img', attributes: 'bold', inside: '$root' } );
+					// Allow 'bold' on p>$text.
+					if ( ctx.matchEnd( 'p $text' ) && attributeName == 'bold' ) {
+						evt.stop();
+						evt.return = true;
+					}
+				}, { priority: 'high' } );
 			} );
 	} );
 
@@ -69,12 +71,15 @@ describe( 'AttributeCommand', () => {
 
 		// See https://github.com/ckeditor/ckeditor5-core/issues/73#issuecomment-311572827.
 		it( 'is false when selection contains object with nested editable', () => {
-			model.schema.register( 'caption', { inheritAllFrom: '$block' } );
+			model.schema.register( 'caption', {
+				allowContentOf: '$block',
+				allowIn: 'img',
+				isLimit: true
+			} );
 			model.schema.extend( '$text', {
 				allowIn: 'caption',
 				allowAttributes: 'bold'
 			} );
-			model.schema.extend( 'caption', { allowIn: 'img' } );
 
 			setData( model, '<p>[<img><caption>Some caption inside the image.</caption></img>]</p>' );
 
@@ -94,7 +99,6 @@ describe( 'AttributeCommand', () => {
 
 		beforeEach( () => {
 			model.schema.register( 'x', { inheritAllFrom: '$block' } );
-			model.schema.disallow( { name: '$text', inside: 'x', attributes: 'link' } );
 		} );
 
 		describe( 'when selection is collapsed', () => {

+ 6 - 5
packages/ckeditor5-basic-styles/tests/bold.js

@@ -12,6 +12,8 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Bold', () => {
@@ -23,7 +25,7 @@ describe( 'Bold', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Bold ]
+				plugins: [ Paragraph, Bold ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -65,14 +67,13 @@ describe( 'Bold', () => {
 		const command = editor.commands.get( 'bold' );
 
 		expect( boldView.isOn ).to.be.false;
-
-		expect( boldView.isEnabled ).to.be.false;
+		expect( boldView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( boldView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( boldView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( boldView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {

+ 4 - 7
packages/ckeditor5-basic-styles/tests/boldengine.js

@@ -35,8 +35,7 @@ describe( 'BoldEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.checkAttribute( [ '$root', '$text' ], 'bold' ) ).to.be.false;
-		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'bold' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'bold' ) ).to.be.true;
 		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'bold' ) ).to.be.true;
 	} );
 
@@ -78,14 +77,12 @@ describe( 'BoldEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
-
 			editor.setData( '<strong>foo</strong>bar' );
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text bold="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><strong>foo</strong>bar</p>' );
 		} );
 	} );
 

+ 6 - 5
packages/ckeditor5-basic-styles/tests/code.js

@@ -11,6 +11,8 @@ import CodeEngine from '../src/codeengine';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Code', () => {
@@ -22,7 +24,7 @@ describe( 'Code', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Code ]
+				plugins: [ Paragraph, Code ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -63,13 +65,12 @@ describe( 'Code', () => {
 		const command = editor.commands.get( 'code' );
 
 		expect( codeView.isOn ).to.be.false;
-
-		expect( codeView.isEnabled ).to.be.false;
+		expect( codeView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( codeView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( codeView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( codeView.isEnabled ).to.be.false;
 	} );
 } );

+ 4 - 7
packages/ckeditor5-basic-styles/tests/codeengine.js

@@ -35,8 +35,7 @@ describe( 'CodeEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.checkAttribute( [ '$root', '$text' ], 'code' ) ).to.be.false;
-		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'code' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'code' ) ).to.be.true;
 		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'code' ) ).to.be.true;
 	} );
 
@@ -69,14 +68,12 @@ describe( 'CodeEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
-
 			editor.setData( '<code>foo</code>bar' );
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text code="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><code>foo</code>bar</p>' );
 		} );
 	} );
 

+ 6 - 5
packages/ckeditor5-basic-styles/tests/italic.js

@@ -12,6 +12,8 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Italic', () => {
@@ -23,7 +25,7 @@ describe( 'Italic', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Italic ]
+				plugins: [ Paragraph, Italic ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -65,14 +67,13 @@ describe( 'Italic', () => {
 		const command = editor.commands.get( 'italic' );
 
 		expect( italicView.isOn ).to.be.false;
-
-		expect( italicView.isEnabled ).to.be.false;
+		expect( italicView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( italicView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( italicView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( italicView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {

+ 5 - 8
packages/ckeditor5-basic-styles/tests/italicengine.js

@@ -35,8 +35,7 @@ describe( 'ItalicEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.checkAttribute( [ '$root', '$text' ], 'italic' ) ).to.be.false;
-		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'italic' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'italic' ) ).to.be.true;
 		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'italic' ) ).to.be.true;
 	} );
 
@@ -78,14 +77,12 @@ describe( 'ItalicEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
+			editor.setData( '<i>foo</i>bar' );
 
-			editor.setData( '<em>foo</em>bar' );
-
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><i>foo</i>bar</p>' );
 		} );
 	} );
 

+ 6 - 5
packages/ckeditor5-basic-styles/tests/strikethrough.js

@@ -12,6 +12,8 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Strikethrough', () => {
@@ -23,7 +25,7 @@ describe( 'Strikethrough', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Strikethrough ]
+				plugins: [ Paragraph, Strikethrough ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -65,14 +67,13 @@ describe( 'Strikethrough', () => {
 		const command = editor.commands.get( 'strikethrough' );
 
 		expect( strikeView.isOn ).to.be.false;
-
-		expect( strikeView.isEnabled ).to.be.false;
+		expect( strikeView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( strikeView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( strikeView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( strikeView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {

+ 4 - 7
packages/ckeditor5-basic-styles/tests/strikethroughengine.js

@@ -35,8 +35,7 @@ describe( 'StrikethroughEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.checkAttribute( [ '$root', '$text' ], 'strikethrough' ) ).to.be.false;
-		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'strikethrough' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'strikethrough' ) ).to.be.true;
 		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'strikethrough' ) ).to.be.true;
 	} );
 
@@ -86,14 +85,12 @@ describe( 'StrikethroughEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
-
 			editor.setData( '<s>foo</s>bar' );
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text strikethrough="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><s>foo</s>bar</p>' );
 		} );
 	} );
 

+ 6 - 5
packages/ckeditor5-basic-styles/tests/underline.js

@@ -12,6 +12,8 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
 testUtils.createSinonSandbox();
 
 describe( 'Underline', () => {
@@ -23,7 +25,7 @@ describe( 'Underline', () => {
 
 		return ClassicTestEditor
 			.create( editorElement, {
-				plugins: [ Underline ]
+				plugins: [ Paragraph, Underline ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -65,14 +67,13 @@ describe( 'Underline', () => {
 		const command = editor.commands.get( 'underline' );
 
 		expect( underlineView.isOn ).to.be.false;
-
-		expect( underlineView.isEnabled ).to.be.false;
+		expect( underlineView.isEnabled ).to.be.true;
 
 		command.value = true;
 		expect( underlineView.isOn ).to.be.true;
 
-		command.isEnabled = true;
-		expect( underlineView.isEnabled ).to.be.true;
+		command.isEnabled = false;
+		expect( underlineView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {

+ 4 - 7
packages/ckeditor5-basic-styles/tests/underlineengine.js

@@ -35,8 +35,7 @@ describe( 'UnderlineEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.checkAttribute( [ '$root', '$text' ], 'underline' ) ).to.be.false;
-		expect( model.schema.checkAttribute( [ '$block', '$text' ], 'underline' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', '$block', '$text' ], 'underline' ) ).to.be.true;
 		expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'underline' ) ).to.be.true;
 	} );
 
@@ -69,14 +68,12 @@ describe( 'UnderlineEngine', () => {
 		} );
 
 		it( 'should be integrated with autoparagraphing', () => {
-			// Incorrect results because autoparagraphing works incorrectly (issue in paragraph).
-			// https://github.com/ckeditor/ckeditor5-paragraph/issues/10
-
 			editor.setData( '<u>foo</u>bar' );
 
-			expect( getModelData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foobar</paragraph>' );
+			expect( getModelData( model, { withoutSelection: true } ) )
+				.to.equal( '<paragraph><$text underline="true">foo</$text>bar</paragraph>' );
 
-			expect( editor.getData() ).to.equal( '<p>foobar</p>' );
+			expect( editor.getData() ).to.equal( '<p><u>foo</u>bar</p>' );
 		} );
 	} );