Browse Source

Improved tests.

Szymon Kupś 9 years ago
parent
commit
9511cbe6f9

+ 39 - 0
packages/ckeditor5-basic-styles/tests/bold.js

@@ -9,6 +9,10 @@ import Editor from '/ckeditor5/editor.js';
 import Bold from '/ckeditor5/basic-styles/bold.js';
 import BoldEngine from '/ckeditor5/basic-styles/boldengine.js';
 import ClassicCreator from '/ckeditor5/creator-classic/classiccreator.js';
+import ButtonController from '/ckeditor5/ui/button/button.js';
+import testUtils from '/tests/ckeditor5/_utils/utils.js';
+
+testUtils.createSinonSandbox();
 
 describe( 'Bold', () => {
 	let editor;
@@ -30,4 +34,39 @@ describe( 'Bold', () => {
 	it( 'should load BoldEngine', () => {
 		expect( editor.plugins.get( BoldEngine ) ).to.be.instanceOf( BoldEngine );
 	} );
+
+	it( 'should register bold feature component', () => {
+		const controller = editor.ui.featureComponents.create( 'bold' );
+
+		expect( controller ).to.be.instanceOf( ButtonController );
+	} );
+
+	it( 'should execute bold command on model execute event', () => {
+		const executeSpy = testUtils.sinon.spy( editor, 'execute' );
+		const controller = editor.ui.featureComponents.create( 'bold' );
+		const model = controller.model;
+
+		model.fire( 'execute' );
+
+		sinon.assert.calledOnce( executeSpy );
+		sinon.assert.calledWithExactly( executeSpy, 'bold' );
+	} );
+
+	it( 'should bind model to bold command', () => {
+		const controller = editor.ui.featureComponents.create( 'bold' );
+		const model = controller.model;
+		const command = editor.commands.get( 'bold' );
+
+		expect( model.isOn ).to.be.false;
+		expect( command.value ).to.be.false;
+
+		expect( model.isEnabled ).to.be.true;
+		expect( command.isEnabled ).to.be.true;
+
+		command.value = true;
+		expect( model.isOn ).to.equal( true );
+
+		command.isEnabled = false;
+		expect( model.isEnabled ).to.equal( false );
+	} );
 } );

+ 8 - 0
packages/ckeditor5-basic-styles/tests/manual/bold.js

@@ -3,6 +3,8 @@
  * For licensing, see LICENSE.md.
  */
 
+/* global console:false */
+
 'use strict';
 
 import CKEDITOR from '/ckeditor.js';
@@ -13,4 +15,10 @@ CKEDITOR.create( '#editor1', {
 	creator: ClassicCreator,
 	features: [ Bold ],
 	toolbar: [ 'bold' ]
+} )
+.then( editor => {
+	window.editor = editor;
+} )
+.catch( err => {
+	console.error( err.stack );
 } );