| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* global document */
- import BlockQuote from '../src/blockquote';
- import BlockQuoteEngine from '../src/blockquoteengine';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import List from '@ckeditor/ckeditor5-list/src/list';
- import Enter from '@ckeditor/ckeditor5-enter/src/enter';
- import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
- import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
- describe( 'BlockQuote', () => {
- let editor, doc, command, element;
- beforeEach( () => {
- element = document.createElement( 'div' );
- document.body.appendChild( element );
- return ClassicTestEditor.create( element, {
- plugins: [ BlockQuote, Paragraph, List, Enter ]
- } )
- .then( newEditor => {
- editor = newEditor;
- doc = editor.document;
- command = editor.commands.get( 'blockQuote' );
- } );
- } );
- afterEach( () => {
- element.remove();
- return editor.destroy();
- } );
- it( 'requires BlockQuoteEngine', () => {
- expect( BlockQuote.requires ).to.deep.equal( [ BlockQuoteEngine ] );
- } );
- describe( 'blockQuote button', () => {
- it( 'has the base properties', () => {
- const button = editor.ui.componentFactory.create( 'blockQuote' );
- expect( button ).to.have.property( 'label', 'Block quote' );
- expect( button ).to.have.property( 'icon' );
- expect( button ).to.have.property( 'tooltip', true );
- } );
- it( 'has isOn bound to command\'s value', () => {
- const button = editor.ui.componentFactory.create( 'blockQuote' );
- command.value = false;
- expect( button ).to.have.property( 'isOn', false );
- command.value = true;
- expect( button ).to.have.property( 'isOn', true );
- } );
- it( 'has isEnabled bound to command\'s isEnabled', () => {
- const button = editor.ui.componentFactory.create( 'blockQuote' );
- command.isEnabled = true;
- expect( button ).to.have.property( 'isEnabled', true );
- command.isEnabled = false;
- expect( button ).to.have.property( 'isEnabled', false );
- } );
- it( 'executes command when it\'s executed', () => {
- const button = editor.ui.componentFactory.create( 'blockQuote' );
- const spy = sinon.stub( editor, 'execute' );
- button.fire( 'execute' );
- expect( spy.calledOnce ).to.be.true;
- expect( spy.args[ 0 ][ 0 ] ).to.equal( 'blockQuote' );
- } );
- } );
- describe( 'enter key support', () => {
- function fakeEventData() {
- return {
- preventDefault: sinon.spy()
- };
- }
- it( 'does nothing if selection is in an empty block but not in a block quote', () => {
- const data = fakeEventData();
- const execSpy = sinon.spy( editor, 'execute' );
- setModelData( doc, '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>x</paragraph>' );
- editor.editing.view.fire( 'enter', data );
- // Only enter command should be executed.
- expect( data.preventDefault.called ).to.be.true;
- expect( execSpy.calledOnce ).to.be.true;
- expect( execSpy.args[ 0 ][ 0 ] ).to.equal( 'enter' );
- } );
- it( 'does nothing if selection is in a non-empty block (at the end) in a block quote', () => {
- const data = fakeEventData();
- const execSpy = sinon.spy( editor, 'execute' );
- setModelData( doc, '<blockQuote><paragraph>xx[]</paragraph></blockQuote>' );
- editor.editing.view.fire( 'enter', data );
- // Only enter command should be executed.
- expect( data.preventDefault.called ).to.be.true;
- expect( execSpy.calledOnce ).to.be.true;
- expect( execSpy.args[ 0 ][ 0 ] ).to.equal( 'enter' );
- } );
- it( 'does nothing if selection is in a non-empty block (at the beginning) in a block quote', () => {
- const data = fakeEventData();
- const execSpy = sinon.spy( editor, 'execute' );
- setModelData( doc, '<blockQuote><paragraph>[]xx</paragraph></blockQuote>' );
- editor.editing.view.fire( 'enter', data );
- // Only enter command should be executed.
- expect( data.preventDefault.called ).to.be.true;
- expect( execSpy.calledOnce ).to.be.true;
- expect( execSpy.args[ 0 ][ 0 ] ).to.equal( 'enter' );
- } );
- it( 'does nothing if selection is not collapsed', () => {
- const data = fakeEventData();
- const execSpy = sinon.spy( editor, 'execute' );
- setModelData( doc, '<blockQuote><paragraph>[</paragraph><paragraph>]</paragraph></blockQuote>' );
- editor.editing.view.fire( 'enter', data );
- // Only enter command should be executed.
- expect( data.preventDefault.called ).to.be.true;
- expect( execSpy.calledOnce ).to.be.true;
- expect( execSpy.args[ 0 ][ 0 ] ).to.equal( 'enter' );
- } );
- it( 'does not interfere with a similar handler in the list feature', () => {
- const data = fakeEventData();
- setModelData( doc,
- '<paragraph>x</paragraph>' +
- '<blockQuote>' +
- '<listItem indent="0" type="bulleted">a</listItem>' +
- '<listItem indent="0" type="bulleted">[]</listItem>' +
- '</blockQuote>' +
- '<paragraph>x</paragraph>'
- );
- editor.editing.view.fire( 'enter', data );
- expect( data.preventDefault.called ).to.be.true;
- expect( getModelData( doc ) ).to.equal(
- '<paragraph>x</paragraph>' +
- '<blockQuote>' +
- '<listItem indent="0" type="bulleted">a</listItem>' +
- '<paragraph>[]</paragraph>' +
- '</blockQuote>' +
- '<paragraph>x</paragraph>'
- );
- } );
- it( 'escapes block quote if selection is in an empty block in an empty block quote', () => {
- const data = fakeEventData();
- const execSpy = sinon.spy( editor, 'execute' );
- setModelData( doc, '<paragraph>x</paragraph><blockQuote><paragraph>[]</paragraph></blockQuote><paragraph>x</paragraph>' );
- editor.editing.view.fire( 'enter', data );
- expect( data.preventDefault.called ).to.be.true;
- expect( execSpy.calledOnce ).to.be.true;
- expect( execSpy.args[ 0 ][ 0 ] ).to.equal( 'blockQuote' );
- expect( getModelData( doc ) ).to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>x</paragraph>' );
- } );
- it( 'escapes block quote if selection is in an empty block in the middle of a block quote', () => {
- const data = fakeEventData();
- const execSpy = sinon.spy( editor, 'execute' );
- setModelData( doc,
- '<paragraph>x</paragraph>' +
- '<blockQuote><paragraph>a</paragraph><paragraph>[]</paragraph><paragraph>b</paragraph></blockQuote>' +
- '<paragraph>x</paragraph>'
- );
- editor.editing.view.fire( 'enter', data );
- expect( data.preventDefault.called ).to.be.true;
- expect( execSpy.calledOnce ).to.be.true;
- expect( execSpy.args[ 0 ][ 0 ] ).to.equal( 'blockQuote' );
- expect( getModelData( doc ) ).to.equal(
- '<paragraph>x</paragraph>' +
- '<blockQuote><paragraph>a</paragraph></blockQuote>' +
- '<paragraph>[]</paragraph>' +
- '<blockQuote><paragraph>b</paragraph></blockQuote>' +
- '<paragraph>x</paragraph>'
- );
- } );
- it( 'escapes block quote if selection is in an empty block at the end of a block quote', () => {
- const data = fakeEventData();
- const execSpy = sinon.spy( editor, 'execute' );
- setModelData( doc,
- '<paragraph>x</paragraph>' +
- '<blockQuote><paragraph>a</paragraph><paragraph>[]</paragraph></blockQuote>' +
- '<paragraph>x</paragraph>'
- );
- editor.editing.view.fire( 'enter', data );
- expect( data.preventDefault.called ).to.be.true;
- expect( execSpy.calledOnce ).to.be.true;
- expect( execSpy.args[ 0 ][ 0 ] ).to.equal( 'blockQuote' );
- expect( getModelData( doc ) ).to.equal(
- '<paragraph>x</paragraph>' +
- '<blockQuote><paragraph>a</paragraph></blockQuote>' +
- '<paragraph>[]</paragraph>' +
- '<paragraph>x</paragraph>'
- );
- } );
- } );
- } );
|