'
);
} );
} );
describe( 'inserting into image caption', () => {
it( 'should add view caption if insertion was made to model caption', () => {
setModelData( document, '
' );
const image = document.getRoot().getChild( 0 );
const caption = image.getChild( 0 );
// Check if there is no caption in the view
expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
''
);
document.enqueueChanges( () => {
const batch = document.batch();
const position = ModelPosition.createAt( caption );
batch.insert( position, 'foo bar baz' );
} );
// Check if data is inside model.
expect( getModelData( document, { withoutSelection: true } ) ).to.equal(
'
foo bar baz
'
);
// Check if view has caption.
expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
'' +
'' +
'foo bar baz' +
''
);
} );
} );
describe( 'editing view', () => {
it( 'image should have empty figcaption element when is selected', () => {
setModelData( document, '[
]' );
expect( getViewData( viewDocument ) ).to.equal(
'[' +
'' +
'' +
']'
);
} );
it( 'image should not have empty figcaption element when is not selected', () => {
setModelData( document, '[]
' );
expect( getViewData( viewDocument ) ).to.equal(
'[]' +
'' +
''
);
} );
it( 'should not add additional figcaption if one is already present', () => {
setModelData( document, '[
foo bar
]' );
expect( getViewData( viewDocument ) ).to.equal(
'[' +
'' +
'foo bar' +
']'
);
} );
it( 'should remove figcaption when caption is empty and image is no longer selected', () => {
setModelData( document, '[
]' );
document.enqueueChanges( () => {
document.selection.removeAllRanges();
} );
expect( getViewData( viewDocument ) ).to.equal(
'[]' +
'' +
''
);
} );
it( 'should not remove figcaption when selection is inside it even when it is empty', () => {
setModelData( document, '
[foo bar]
' );
document.enqueueChanges( () => {
document.batch().remove( document.selection.getFirstRange() );
} );
expect( getViewData( viewDocument ) ).to.equal(
'' +
'' +
'[]' +
''
);
} );
it( 'should not remove figcaption when selection is moved from it to its image', () => {
setModelData( document, '
[foo bar]
' );
const image = document.getRoot().getChild( 0 );
document.enqueueChanges( () => {
document.batch().remove( document.selection.getFirstRange() );
document.selection.setRanges( [ ModelRange.createOn( image ) ] );
} );
expect( getViewData( viewDocument ) ).to.equal(
'[' +
'' +
'' +
']'
);
} );
it( 'should not remove figcaption when selection is moved from it to other image', () => {
setModelData( document, '