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 be false when schema disallows image', () => {
model.schema.register( 'block', { inheritAllFrom: '$block' } );
model.schema.extend( 'paragraph', { allowIn: 'block' } );
// Block image in block.
model.schema.addChildCheck( ( context, childDefinition ) => {
if ( childDefinition.name === 'image' && context.last.name === 'block' ) {
return false;
}
} );
editor.conversion.for( 'downcast' ).elementToElement( { model: 'block', view: 'block' } );
setModelData( model, '[]' );
expect( command.isEnabled ).to.be.false;
} );
} );
it( 'should optimize the insertion position', () => {
const button = editor.ui.componentFactory.create( 'imageUpload' );
const files = [ createNativeFileMock() ];
setModelData( model, 'f[]oo' );
button.fire( 'done', files );
const id = fileRepository.getLoader( files[ 0 ] ).id;
expect( getModelData( model ) ).to.equal(
`[<img>]` +
'foo'
);
} );
it( 'should prevent default behaviour and stop event propagation', () => {
const keydownHandler = sinon.spy();
const domEventDataMock = {
keyCode: keyCodes.delete,
preventDefault: sinon.spy(),
};
setModelData( doc, 'foo[]' );
viewDocument.on( 'keydown', keydownHandler );
viewDocument.fire( 'keydown', domEventDataMock );
expect( getModelData( doc ) ).to.equal( 'foo[]' );
sinon.assert.calledOnce( domEventDataMock.preventDefault );
sinon.assert.notCalled( keydownHandler );
} );
} );
it( 'collapsed selection in non-empty parent', () => {
setData( modelDoc, '<p>x[]y</p>' );
modelDoc.on( 'changesDone', spy );
command.execute();
expect( spy.calledOnce ).to.be.true;
} );
it( 'should not convert from model to view if style is not present: remove attribute', () => {
setModelData( model, '<img src="/assets/sample.png">' );
const image = document.getRoot().getChild( 0 );
model.change( writer => {
writer.setAttribute( 'imageStyle', null, image );
} );
expect( editor.getData() ).to.equal( '<figure class="image"><img src="/assets/sample.png"></figure>' );
expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
'<figure class="ck-widget image"><img src="/assets/sample.png"></figure>'
);
} );
} );
it( 'should not remove figcaption when selection is moved from it to other image', () => {
setModelData( model, '<img src="">[foo bar]<img src="">' );
const image = doc.getRoot().getChild( 1 );
model.change( writer => {
writer.setSelection( writer.createRangeOn( image ) );
} );
expect( getViewData( view ) ).to.equal(
'<figure class="ck-widget image">' +
'<img src="">' +
'<figcaption data-placeholder="Enter image caption" class="ck-editor__editable ck-editor__nested-editable">foo bar</figcaption>' +
'</figure>' +
'[<figure class="ck-widget image">' +
'<img src="">' +
'<figcaption data-placeholder="Enter image caption" class="ck-editor__editable ck-editor__nested-editable ck-placeholder"></figcaption>' +</figure>
it( 'should match default style if no imageStyle attribute is present', () => {
setData( model, '[<img>]' );
expect( command.value ).to.equal( 'defaultStyle' );
} );
it( 'should be true when the selection directly in a paragraph', () => {
setModelData( model, 'foo[]' );
expect( command.isEnabled ).to.be.true;
} );
it( 'should return false if there are no nodes in selection that can have the attribute', () => {
setData( modelDoc, '[foo]' );
expect( command.isEnabled ).to.be.false;
} );
} );
beforeEach( () => {
setModelData(
model,
'' +
'' +
'' +
'foo' +
'' +
'<table></table>' +
''
);
tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
} );