8
0
Просмотр исходного кода

Tests for EditorUI and IconManagerView.

Aleksander Nowodzinski 9 лет назад
Родитель
Сommit
63ba69bde5

+ 5 - 3
packages/ckeditor5-ui/src/iconmanagerview.js

@@ -40,8 +40,10 @@ export default class IconManagerView extends View {
 	_setupSprite() {
 	_setupSprite() {
 		// Note: Creating SVG icons with with Template class is not possible
 		// Note: Creating SVG icons with with Template class is not possible
 		// because of CSS limitations of document.createEleentNS–created elements.
 		// because of CSS limitations of document.createEleentNS–created elements.
-		this.element.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="ck-sprite">
-				${ this.model.sprite }
-			</svg>`;
+		this.element.innerHTML = `<svg
+				xmlns="http://www.w3.org/2000/svg"
+				xmlns:xlink="http://www.w3.org/1999/xlink"
+				class="ck-icon-manager-sprite"
+			>${ this.model.sprite }</svg>`;
 	}
 	}
 }
 }

+ 29 - 0
packages/ckeditor5-ui/tests/editorui/editorui.js

@@ -5,11 +5,14 @@
 
 
 'use strict';
 'use strict';
 
 
+import testUtils from '/tests/ckeditor5/_utils/utils.js';
 import Editor from '/ckeditor5/editor.js';
 import Editor from '/ckeditor5/editor.js';
 import EditorUI from '/ckeditor5/ui/editorui/editorui.js';
 import EditorUI from '/ckeditor5/ui/editorui/editorui.js';
 import ComponentFactory from '/ckeditor5/ui/componentfactory.js';
 import ComponentFactory from '/ckeditor5/ui/componentfactory.js';
 import ControllerCollection from '/ckeditor5/ui/controllercollection.js';
 import ControllerCollection from '/ckeditor5/ui/controllercollection.js';
 
 
+testUtils.createSinonSandbox();
+
 describe( 'EditorUI', () => {
 describe( 'EditorUI', () => {
 	let editor, editorUI;
 	let editor, editorUI;
 
 
@@ -31,4 +34,30 @@ describe( 'EditorUI', () => {
 			expect( editor ).to.have.property( 'ui', editorUI );
 			expect( editor ).to.have.property( 'ui', editorUI );
 		} );
 		} );
 	} );
 	} );
+
+	describe( 'init', () => {
+		it( 'calls _setupIconManager when "icon" in model', () => {
+			const spy = testUtils.sinon.spy( editorUI, '_setupIconManager' );
+
+			return editorUI.init()
+				.then( () => {
+					expect( spy.calledOnce ).to.be.true;
+				} );
+		} );
+	} );
+
+	describe( '_setupIconManager', () => {
+		it( 'initializes icon manager and sets "iconManager" property', () => {
+			editorUI._setupIconManager();
+
+			expect( editorUI ).to.have.property( 'iconManager' );
+		} );
+
+		it( 'sets "icon" property', () => {
+			editorUI._setupIconManager();
+
+			expect( editorUI.icons ).to.be.an( 'array' );
+			expect( editorUI.icons ).to.not.be.empty;
+		} );
+	} );
 } );
 } );

+ 46 - 0
packages/ckeditor5-ui/tests/iconmanagerview.js

@@ -0,0 +1,46 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import testUtils from '/tests/ckeditor5/_utils/utils.js';
+import IconManagerView from '/ckeditor5/ui/iconmanagerview.js';
+import Model from '/ckeditor5/ui/model.js';
+
+testUtils.createSinonSandbox();
+
+describe( 'IconManagerView', () => {
+	let view;
+
+	beforeEach( () => {
+		view = new IconManagerView( new Model( {
+			sprite: 'foo'
+		} ) );
+	} );
+
+	describe( 'init', () => {
+		it( 'calls _setupSprite', () => {
+			const spy = testUtils.sinon.spy( view, '_setupSprite' );
+
+			view.init();
+			expect( spy.calledOnce ).to.be.true;
+		} );
+	} );
+
+	describe( '_setupSprite', () => {
+		it( 'initializes the sprite', () => {
+			view._setupSprite();
+
+			const el = view.element;
+			const svg = view.element.firstChild;
+
+			expect( el.tagName ).to.be.equal( 'DIV' );
+			expect( el.classList.item( 0 ) ).to.be.equal( 'ck-icon-manager' );
+			expect( svg.tagName ).to.be.equal( 'svg' );
+			expect( svg.innerHTML ).to.be.equal( 'foo' );
+			expect( svg.classList.item( 0 ) ).to.be.equal( 'ck-icon-manager-sprite' );
+		} );
+	} );
+} );