| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* globals document */
- import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
- import Bold from '../src/bold';
- import BoldEngine from '../src/boldengine';
- import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
- import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
- import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- testUtils.createSinonSandbox();
- describe( 'Bold', () => {
- let editor, boldView;
- beforeEach( () => {
- const editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
- return ClassicTestEditor
- .create( editorElement, {
- plugins: [ Paragraph, Bold ]
- } )
- .then( newEditor => {
- editor = newEditor;
- boldView = editor.ui.componentFactory.create( 'bold' );
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'should be loaded', () => {
- expect( editor.plugins.get( Bold ) ).to.be.instanceOf( Bold );
- } );
- it( 'should load BoldEngine', () => {
- expect( editor.plugins.get( BoldEngine ) ).to.be.instanceOf( BoldEngine );
- } );
- it( 'should register bold feature component', () => {
- expect( boldView ).to.be.instanceOf( ButtonView );
- expect( boldView.isOn ).to.be.false;
- expect( boldView.label ).to.equal( 'Bold' );
- expect( boldView.icon ).to.match( /<svg / );
- expect( boldView.keystroke ).to.equal( 'CTRL+B' );
- } );
- it( 'should execute bold command on model execute event', () => {
- const executeSpy = testUtils.sinon.spy( editor, 'execute' );
- boldView.fire( 'execute' );
- sinon.assert.calledOnce( executeSpy );
- sinon.assert.calledWithExactly( executeSpy, 'bold' );
- } );
- it( 'should bind model to bold command', () => {
- const command = editor.commands.get( 'bold' );
- expect( boldView.isOn ).to.be.false;
- expect( boldView.isEnabled ).to.be.true;
- command.value = true;
- expect( boldView.isOn ).to.be.true;
- command.isEnabled = false;
- expect( boldView.isEnabled ).to.be.false;
- } );
- it( 'should set keystroke in the model', () => {
- expect( boldView.keystroke ).to.equal( 'CTRL+B' );
- } );
- it( 'should set editor keystroke', () => {
- const spy = sinon.spy( editor, 'execute' );
- const keyEventData = {
- keyCode: keyCodes.b,
- ctrlKey: true,
- preventDefault: sinon.spy(),
- stopPropagation: sinon.spy()
- };
- const wasHandled = editor.keystrokes.press( keyEventData );
- expect( wasHandled ).to.be.true;
- expect( spy.calledOnce ).to.be.true;
- expect( keyEventData.preventDefault.calledOnce ).to.be.true;
- } );
- } );
|