瀏覽代碼

Tests: Add integration tests.

Maciej Gołaszewski 8 年之前
父節點
當前提交
f368922d9f

+ 19 - 24
packages/ckeditor5-alignment/tests/alignmentcommand.js

@@ -8,7 +8,7 @@ import AlignmentCommand from '../src/alignmentcommand';
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
-import ModelTestEditor from '../../ckeditor5-core/tests/_utils/modeltesteditor';
+import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 
 describe( 'AlignmentCommand', () => {
 	let editor, doc, command, defaultAlignmentCommand;
@@ -25,7 +25,6 @@ describe( 'AlignmentCommand', () => {
 				editor.commands.add( 'alignLeft', defaultAlignmentCommand );
 
 				doc.schema.registerItem( 'paragraph', '$block' );
-				doc.schema.registerItem( 'heading', '$block' );
 
 				doc.schema.allow( { name: '$block', inside: '$root', attributes: 'alignment' } );
 			} );
@@ -76,17 +75,15 @@ describe( 'AlignmentCommand', () => {
 
 	describe( 'execute()', () => {
 		describe( 'applying alignment', () => {
-			it( 'add should alignment to block element', () => {
+			it( 'adds alignment to block element', () => {
 				setModelData( doc, '<paragraph>x[]x</paragraph>' );
 
 				editor.execute( 'alignCenter' );
 
-				expect( getModelData( doc ) ).to.equal(
-					'<paragraph alignment="center">x[]x</paragraph>'
-				);
+				expect( getModelData( doc ) ).to.equal( '<paragraph alignment="center">x[]x</paragraph>' );
 			} );
 
-			it( 'add should alignment to all selected blocks', () => {
+			it( 'adds alignment to all selected blocks', () => {
 				setModelData( doc, '<paragraph>x[x</paragraph><paragraph>xx</paragraph><paragraph>x]x</paragraph>' );
 
 				editor.execute( 'alignCenter' );
@@ -97,29 +94,27 @@ describe( 'AlignmentCommand', () => {
 					'<paragraph alignment="center">x]x</paragraph>'
 				);
 			} );
+		} );
 
-			describe( 'applying default alignment', () => {
-				it( 'add should remove alignment from block element', () => {
-					setModelData( doc, '<paragraph alignment="justify">x[]x</paragraph>' );
+		describe( 'applying default alignment', () => {
+			it( 'removes alignment from block element', () => {
+				setModelData( doc, '<paragraph alignment="justify">x[]x</paragraph>' );
 
-					editor.execute( 'alignLeft' );
+				editor.execute( 'alignLeft' );
 
-					expect( getModelData( doc ) ).to.equal(
-						'<paragraph>x[]x</paragraph>'
-					);
-				} );
+				expect( getModelData( doc ) ).to.equal( '<paragraph>x[]x</paragraph>' );
+			} );
 
-				it( 'add remove alignment from all selected blocks', () => {
-					setModelData( doc, '<paragraph alignment="center">x[x</paragraph>' +
-						'<paragraph alignment="center">xx</paragraph>' +
-						'<paragraph alignment="center">x]x</paragraph>' );
+			it( 'removes alignment from all selected blocks', () => {
+				setModelData( doc, '<paragraph alignment="center">x[x</paragraph>' +
+					'<paragraph alignment="center">xx</paragraph>' +
+					'<paragraph alignment="center">x]x</paragraph>' );
 
-					editor.execute( 'alignLeft' );
+				editor.execute( 'alignLeft' );
 
-					expect( getModelData( doc ) ).to.equal(
-						'<paragraph>x[x</paragraph><paragraph>xx</paragraph><paragraph>x]x</paragraph>'
-					);
-				} );
+				expect( getModelData( doc ) ).to.equal(
+					'<paragraph>x[x</paragraph><paragraph>xx</paragraph><paragraph>x]x</paragraph>'
+				);
 			} );
 		} );
 	} );

+ 17 - 4
packages/ckeditor5-alignment/tests/alignmentediting.js

@@ -6,7 +6,8 @@
 import AlignmentEditing from '../src/alignmentediting';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import ImageCaptionEngine from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionengine';
-
+import ListEngine from '@ckeditor/ckeditor5-list/src/listengine';
+import HeadingEngine from '@ckeditor/ckeditor5-heading/src/headingengine';
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
@@ -46,7 +47,7 @@ describe( 'AlignmentEditing', () => {
 		beforeEach( () => {
 			return VirtualTestEditor
 				.create( {
-					plugins: [ AlignmentEditing, ImageCaptionEngine, Paragraph ]
+					plugins: [ AlignmentEditing, ImageCaptionEngine, Paragraph, ListEngine, HeadingEngine ]
 				} )
 				.then( newEditor => {
 					editor = newEditor;
@@ -55,8 +56,20 @@ describe( 'AlignmentEditing', () => {
 				} );
 		} );
 
-		it( 'disallows for alignment in the catpion', () => {
-			expect( doc.schema.check( { name: '$block', inside: 'figcaption', attributes: 'alignment' } ) ).to.be.true;
+		it( 'is allowed on paragraph', () => {
+			expect( doc.schema.check( { name: 'paragraph', attributes: 'alignment' } ) ).to.be.true;
+		} );
+
+		it( 'is allowed on listItem', () => {
+			expect( doc.schema.check( { name: 'listItem', attributes: [ 'type', 'indent', 'alignment' ] } ) ).to.be.true;
+		} );
+
+		it( 'is allowed on heading', () => {
+			expect( doc.schema.check( { name: 'heading1', attributes: 'alignment' } ) ).to.be.true;
+		} );
+
+		it( 'is disallowed on figcaption', () => {
+			expect( doc.schema.check( { name: 'figcaption', attributes: 'alignment' } ) ).to.be.false;
 		} );
 	} );
 

+ 81 - 0
packages/ckeditor5-alignment/tests/integration.js

@@ -0,0 +1,81 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global document */
+
+import Alignment from '../src/alignment';
+import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import Heading from '@ckeditor/ckeditor5-heading/src/heading';
+import Image from '@ckeditor/ckeditor5-image/src/image';
+import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
+import List from '@ckeditor/ckeditor5-list/src/list';
+import Enter from '@ckeditor/ckeditor5-enter/src/enter';
+import Delete from '@ckeditor/ckeditor5-typing/src/delete';
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+
+describe( 'Alignment', () => {
+	let editor, doc, element;
+
+	beforeEach( () => {
+		element = document.createElement( 'div' );
+		document.body.appendChild( element );
+
+		return ClassicTestEditor
+			.create( element, {
+				plugins: [ Alignment, BlockQuote, Paragraph, Heading, Image, ImageCaption, List, Enter, Delete ]
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+				doc = editor.document;
+			} );
+	} );
+
+	afterEach( () => {
+		element.remove();
+
+		return editor.destroy();
+	} );
+
+	describe( 'compatibility with images', () => {
+		it( 'does not work inside image caption', () => {
+			setModelData( doc, '<image src="foo.png"><caption>Foo[]</caption></image>' );
+
+			editor.execute( 'alignCenter' );
+
+			expect( getModelData( doc ) ).to.equal( '<image src="foo.png"><caption>Foo[]</caption></image>' );
+		} );
+	} );
+
+	describe( 'compatibility with blockQuote', () => {
+		it( 'does work inside BlockQuote on paragraph', () => {
+			setModelData( doc, '<blockQuote><paragraph>Foo[]</paragraph></blockQuote>' );
+
+			editor.execute( 'alignCenter' );
+
+			expect( getModelData( doc ) ).to.equal( '<blockQuote><paragraph alignment="center">Foo[]</paragraph></blockQuote>' );
+		} );
+
+		it( 'does work inside blockQuote on heading', () => {
+			setModelData( doc, '<blockQuote><heading1>Foo[]</heading1></blockQuote>' );
+
+			editor.execute( 'alignCenter' );
+
+			expect( getModelData( doc ) ).to.equal( '<blockQuote><heading1 alignment="center">Foo[]</heading1></blockQuote>' );
+		} );
+
+		it( 'does work inside blockQuote on listItem', () => {
+			setModelData( doc, '<blockQuote><listItem indent="0" type="numbered">Foo[]</listItem></blockQuote>' );
+
+			editor.execute( 'alignCenter' );
+
+			expect( getModelData( doc ) ).to.equal(
+				'<blockQuote><listItem alignment="center" indent="0" type="numbered">Foo[]</listItem></blockQuote>'
+			);
+		} );
+	} );
+} );