浏览代码

Added tests for image styles utilities.

Szymon Kupś 9 年之前
父节点
当前提交
f9170608d9

+ 1 - 1
packages/ckeditor5-image/src/imagestyle/imagestyleengine.js

@@ -38,7 +38,7 @@ export default class ImageStyleEngine extends Plugin {
 
 		// Define default configuration.
 		editor.config.define( 'image.styles', [
-			// This option is equal to situation when no style is applied at all.
+			// This option is equal to situation when no style is applied.
 			{ name: 'imageStyleFull', title: 'Full size image', icon: 'object-center', value: null },
 
 			// This represents side image.

+ 48 - 0
packages/ckeditor5-image/tests/imagestyle/utils.js

@@ -0,0 +1,48 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import { isImage, getStyleByValue } from 'ckeditor5/image/imagestyle/utils.js';
+import ModelElement from 'ckeditor5/engine/model/element.js';
+
+describe( 'ImageStyle utils', () => {
+	describe( 'isImage', () => {
+		it( 'should return true for image element', () => {
+			const image = new ModelElement( 'image' );
+
+			expect( isImage( image ) ).to.be.true;
+		} );
+
+		it( 'should return true false for different elements', () => {
+			const image = new ModelElement( 'foo' );
+
+			expect( isImage( image ) ).to.be.false;
+		} );
+
+		it( 'should return true false for null and undefined', () => {
+			expect( isImage( null ) ).to.be.false;
+			expect( isImage( undefined ) ).to.be.false;
+		} );
+	} );
+
+	describe( 'getStyleByValue', () => {
+		const styles = [
+			{ name: 'style 1', title: 'title 1', icon: 'style1-icon', value: 'style1', className: 'style1-class' },
+			{ name: 'style 2', title: 'title 2', icon: 'style2-icon', value: 'style2', className: 'style2-class' }
+		];
+
+		it( 'should return proper styles for values', () => {
+			expect( getStyleByValue( 'style1', styles ) ).to.equal( styles[ 0 ] );
+			expect( getStyleByValue( 'style2', styles ) ).to.equal( styles[ 1 ] );
+		} );
+
+		it( 'should return undefined when style is not found', () => {
+			expect( getStyleByValue( 'foo', styles ) ).to.be.undefined;
+		} );
+
+		it( 'should return undefined when empty styles array is provided', () => {
+			expect( getStyleByValue( 'style1', [] ) ).to.be.undefined;
+		} );
+	} );
+} );