Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it( 'should not fire `selectionChangeDone` event when observer will be destroyed', () => {
const clock = testUtils.sinon.useFakeTimers();
const spy = sinon.spy();
viewDocument.on( 'selectionChangeDone', spy );
// Change selection.
changeFakeSelectionPressing( keyCodes.arrowdown );
// Wait 100ms.
clock.tick( 100 );
// And destroy observer.
observer.destroy();
// Wait another 110ms.
clock.tick( 110 );
beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );
editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );
return ClassicTestEditor
.create( editorElement, {
plugins: [ Image, ImageToolbar, BalloonToolbar, Paragraph ]
} )
.then( editor => {
newEditor = editor;
balloon = newEditor.plugins.get( 'ContextualBalloon' );
balloonToolbar = newEditor.plugins.get( 'BalloonToolbar' );
const button = new View();
button.element = global.document.createElement( 'div' );
beforeEach( () => {
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );
} );
beforeEach( () => {
element = document.createElement( 'div' );
document.body.appendChild( element );
// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );
return ClassicTestEditor.create( element, { extraPlugins: [ Delete ] } )
.then( newEditor => {
editor = newEditor;
model = editor.model;
doc = model.document;
root = doc.getRoot( 'main' );
view = editor.editing.view;
defaultSchema( model.schema );
defaultConversion( editor.conversion, true );
editor.model.schema.register( 'block', {
inheritAllFrom: '$block'
} );
editor.conversion.elementToElement( { model: 'block', view: 'div' } );
it( 'should focus view after command execution', () => {
const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
const dropdown = editor.ui.componentFactory.create( 'fontFamily' );
dropdown.commandName = 'fontFamily';
dropdown.fire( 'execute' );
sinon.assert.calledOnce( focusSpy );
} );
it( 'should not add a range that is in graveyard', () => {
const spy = testUtils.sinon.stub( log, 'warn' );
selection.addRange( Range.createIn( doc.graveyard ) );
expect( selection._ranges.length ).to.equal( 0 );
expect( spy.calledOnce ).to.be.true;
} );
it( 'should focus view after command execution', () => {
const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
dropdown.buttonView.commandName = 'highlight';
dropdown.buttonView.fire( 'execute' );
sinon.assert.calledOnce( focusSpy );
} );
} );
it( 'should remove a view', () => {
const spy = testUtils.sinon.stub( ContextualBalloon.prototype, 'remove' );
const view = {};
plugin.remove( view );
sinon.assert.calledOnce( spy );
} );
} );
beforeEach( () => {
element = document.createElement( 'div' );
document.body.appendChild( element );
clock = testUtils.sinon.useFakeTimers();
return BalloonEditor.create( element, {
plugins: [ Paragraph, MediaEmbed, MediaEmbedToolbar, FakeButton, Bold ],
balloonToolbar: [ 'bold' ],
media: {
toolbar: [ 'fake_button' ]
}
} ).then( _editor => {
editor = _editor;
model = editor.model;
widgetToolbarRepository = editor.plugins.get( 'WidgetToolbarRepository' );
toolbar = widgetToolbarRepository._toolbarDefinitions.get( 'mediaEmbed' ).view;
balloon = editor.plugins.get( 'ContextualBalloon' );
balloonToolbar = editor.plugins.get( 'BalloonToolbar' );
} );
} );
beforeEach( () => {
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );
view = new TextAlternativeFormView( { t: () => {} } );
} );