Sfoglia il codice sorgente

Tests: Test AlignmentCommand on model only.

Maciej Gołaszewski 8 anni fa
parent
commit
f439cbff70

+ 1 - 1
packages/ckeditor5-alignment/src/alignmentui.js

@@ -35,7 +35,7 @@ export default class AlignmentUI extends Plugin {
 	 * @inheritDoc
 	 */
 	static get pluginName() {
-		return 'Alignment';
+		return 'AlignmentUI';
 	}
 
 	/**

+ 9 - 26
packages/ckeditor5-alignment/tests/alignmentcommand.js

@@ -3,42 +3,29 @@
  * For licensing, see LICENSE.md.
  */
 
-import AlignmentEditing from '../src/alignmentediting';
 import AlignmentCommand from '../src/alignmentcommand';
 
-import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
-
-import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
+import ModelTestEditor from '../../ckeditor5-core/tests/_utils/modeltesteditor';
 
 describe( 'AlignmentCommand', () => {
 	let editor, doc, command;
 
 	beforeEach( () => {
-		return VirtualTestEditor
-			.create( {
-				plugins: [ AlignmentEditing ]
-			} )
+		return ModelTestEditor.create()
 			.then( newEditor => {
+				doc = newEditor.document;
+				command = new AlignmentCommand( newEditor, 'center' );
 				editor = newEditor;
 
-				doc = editor.document;
+				editor.commands.add( 'alignCenter', new AlignmentCommand( editor, 'center' ) );
 
 				doc.schema.registerItem( 'paragraph', '$block' );
 				doc.schema.registerItem( 'heading', '$block' );
 
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'paragraph' )
-					.toElement( 'p' );
-
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'heading' )
-					.toElement( 'h' );
-
-				command = editor.commands.get( 'alignLeft' );
+				doc.schema.allow( { name: '$block', inside: '$root', attributes: 'alignment' } );
 			} );
 	} );
 
@@ -68,18 +55,14 @@ describe( 'AlignmentCommand', () => {
 	} );
 
 	describe( 'execute()', () => {
-		describe( 'applying right alignment', () => {
+		describe( 'applying alignment', () => {
 			it( 'add alignment to block element', () => {
 				setModelData( doc, '<paragraph>x[]x</paragraph>' );
 
-				editor.execute( 'alignRight' );
+				editor.execute( 'alignCenter' );
 
 				expect( getModelData( doc ) ).to.equal(
-					'<paragraph alignment="right">x[]x</paragraph>'
-				);
-
-				expect( getViewData( editor.editing.view ) ).to.equal(
-					'<p style="text-align:right;">x{}x</p>'
+					'<paragraph alignment="center">x[]x</paragraph>'
 				);
 			} );
 		} );

+ 8 - 6
packages/ckeditor5-alignment/tests/alignmentediting.js

@@ -9,7 +9,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
-import AlignmentComment from '../src/alignmentcommand';
+import AlignmentCommand from '../src/alignmentcommand';
 
 describe( 'AlignmentEditing', () => {
 	let editor, doc;
@@ -30,17 +30,19 @@ describe( 'AlignmentEditing', () => {
 		editor.destroy();
 	} );
 
-	it( 'adds a alignment commands', () => {
-		expect( editor.commands.get( 'alignLeft' ) ).to.be.instanceOf( AlignmentComment );
-		expect( editor.commands.get( 'alignRight' ) ).to.be.instanceOf( AlignmentComment );
-		expect( editor.commands.get( 'alignCenter' ) ).to.be.instanceOf( AlignmentComment );
-		expect( editor.commands.get( 'alignJustify' ) ).to.be.instanceOf( AlignmentComment );
+	it( 'adds alignment commands', () => {
+		expect( editor.commands.get( 'alignLeft' ) ).to.be.instanceOf( AlignmentCommand );
+		expect( editor.commands.get( 'alignRight' ) ).to.be.instanceOf( AlignmentCommand );
+		expect( editor.commands.get( 'alignCenter' ) ).to.be.instanceOf( AlignmentCommand );
+		expect( editor.commands.get( 'alignJustify' ) ).to.be.instanceOf( AlignmentCommand );
 	} );
 
 	it( 'allows for alignment in the $blocks', () => {
 		expect( doc.schema.check( { name: '$block', inside: '$root', attributes: 'alignment' } ) ).to.be.true;
 	} );
 
+	// describe('alignLef')
+
 	it( 'adds converters to the data pipeline', () => {
 		const data = '<p style="text-align:center;">x</p>';