Browse Source

Added tests to ImageStyleCommand.

Szymon Kupś 9 years ago
parent
commit
df6d259634

+ 110 - 0
packages/ckeditor5-image/tests/imagestyle/imagestylecommand.js

@@ -0,0 +1,110 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import ModelTestEditor from 'tests/core/_utils/modeltesteditor.js';
+import ImageStyleCommand from 'ckeditor5/image/imagestyle/imagestylecommand.js';
+import { setData, getData } from 'ckeditor5/engine/dev-utils/model.js';
+
+describe( 'ImageStyleCommand', () => {
+	const styles = {
+		defaultStyle: { title: 'foo bar', icon: 'icon-1', value: null },
+		otherStyle: { title: 'baz', icon: 'icon-2', value: 'other', className: 'other-class-name' }
+	};
+
+	let document, command;
+
+	beforeEach( () => {
+		return ModelTestEditor.create()
+			.then( newEditor => {
+				document = newEditor.document;
+				command = new ImageStyleCommand( newEditor, styles );
+
+				document.schema.registerItem( 'p', '$block' );
+
+				document.schema.registerItem( 'image' );
+				document.schema.objects.add( 'image' );
+				document.schema.allow( { name: 'image', inside: '$root' } );
+				document.schema.allow( { name: 'image', inside: '$root', attributes: [ 'imageStyle' ] } );
+			} );
+	} );
+
+	it( 'should have false if image is not selected', () => {
+		setData( document, '[]<image></image>' );
+
+		expect( command.value ).to.be.false;
+	} );
+
+	it( 'should have null if image without style is selected', () => {
+		setData( document, '[<image></image>]' );
+
+		expect( command.value ).to.be.null;
+	} );
+
+	it( 'should have proper value if image with style is selected', () => {
+		setData( document, '[<image imageStyle="other"></image>]' );
+
+		expect( command.value ).to.equal( 'other' );
+	} );
+
+	it( 'should return false if value is not allowed', () => {
+		setData( document, '[<image imageStyle="foo"></image>]' );
+
+		expect( command.value ).to.be.false;
+	} );
+
+	it( 'should set proper value when executed', () => {
+		setData( document, '[<image></image>]' );
+
+		command._doExecute( { value: 'other' } );
+
+		expect( getData( document ) ).to.equal( '[<image imageStyle="other"></image>]' );
+	} );
+
+	it( 'should do nothing when executed with wrong value', () => {
+		setData( document, '[<image></image>]' );
+
+		command._doExecute( { value: 'foo' } );
+
+		expect( getData( document ) ).to.equal( '[<image></image>]' );
+	} );
+
+	it( 'should do nothing when executed with same value', () => {
+		setData( document, '[<image imageStyle="other"></image>]' );
+
+		command._doExecute( { value: 'other' } );
+
+		expect( getData( document ) ).to.equal( '[<image imageStyle="other"></image>]' );
+	} );
+
+	it( 'should allow to provide batch instance', () => {
+		const batch = document.batch();
+		const spy = sinon.spy( batch, 'setAttribute' );
+
+		setData( document, '[<image></image>]' );
+
+		command._doExecute( { value: 'other', batch } );
+
+		expect( getData( document ) ).to.equal( '[<image imageStyle="other"></image>]' );
+		sinon.assert.calledOnce( spy );
+	} );
+
+	it( 'should be enabled on image element', () => {
+		setData( document, '[<image></image>]' );
+
+		expect( command.isEnabled ).to.be.true;
+	} );
+
+	it( 'should be disabled when not placed on image', () => {
+		setData( document, '[<p></p>]' );
+
+		expect( command.isEnabled ).to.be.false;
+	} );
+
+	it( 'should be disabled when not placed directly on image', () => {
+		setData( document, '[<p></p><image></image>]' );
+
+		expect( command.isEnabled ).to.be.false;
+	} );
+} );

+ 1 - 0
packages/ckeditor5-image/theme/icons/object-center.svg

@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"><path d="M2,16l16,0l0,1l-16,0l0,-1Zm15,-2l-14,0l0,-8l14,0l0,8Zm-1,-7l-12,0l0,6l12,0l0,-6Zm-14,-4l16,0l0,1l-16,0l0,-1Z" style="fill:#343434;"/></svg>

File diff suppressed because it is too large
+ 1 - 0
packages/ckeditor5-image/theme/icons/object-left.svg


File diff suppressed because it is too large
+ 1 - 0
packages/ckeditor5-image/theme/icons/object-right.svg