Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function testPanelAttach( spy ) {
sinon.assert.calledOnce( spy );
const options = spy.firstCall.args[ 0 ];
// Check if proper target element was used.
expect( options.target.tagName.toLowerCase() ).to.equal( 'figure' );
// Check if correct positions are used.
const [ north, south ] = options.positions;
expect( north ).to.equal( BalloonPanelView.defaultPositions.northArrowSouth );
expect( south ).to.equal( BalloonPanelView.defaultPositions.southArrowNorth );
}
} );
it( 'returns the position data', () => {
const defaultPositions = BalloonPanelView.defaultPositions;
setData( editor.model, '[<img src="">]' );
const data = getBalloonPositionData( editor );
expect( data ).to.deep.equal( {
target: editingView.domConverter.viewToDom( editingView.document.selection.getSelectedElement() ),
positions: [
defaultPositions.northArrowSouth,
defaultPositions.northArrowSouthWest,
defaultPositions.northArrowSouthEast,
defaultPositions.southArrowNorth,
defaultPositions.southArrowNorthWest,
defaultPositions.southArrowNorthEast
]
} );
} );
it( 'uses default position configuration if not specified', () => {
const spy = testUtils.sinon.stub( ContextualBalloon.prototype, 'add' );
const positionData = {};
setData( doc, '[<img src="">]' );
plugin.add( positionData );
sinon.assert.calledWithExactly( spy, {
position: {
target: editingView.domConverter.viewToDom( editingView.selection.getSelectedElement() ),
positions: [
BalloonPanelView.defaultPositions.northArrowSouth,
BalloonPanelView.defaultPositions.southArrowNorth
]
}
} );
expect( positionData.position ).to.be.undefined;
} );
it( 'should re-position the ContextualBalloon when the image is selected', () => {
const spy = sinon.spy( balloon, 'updatePosition' );
const defaultPositions = BalloonPanelView.defaultPositions;
const view = new View();
view.element = global.document.createElement( 'div' );
balloon.add( {
view,
position: {
target: global.document.body
}
} );
setData( editor.model, '[<img src="">]' );
repositionContextualBalloon( editor );
sinon.assert.calledWithExactly( spy, {
target: editingView.domConverter.viewToDom( editingView.document.selection.getSelectedElement() ),
it( 'uses default position configuration if not specified', () => {
const spy = testUtils.sinon.stub( ContextualBalloon.prototype, 'add' );
const positionData = {};
setData( doc, '[<img src="">]' );
plugin.add( positionData );
sinon.assert.calledWithExactly( spy, {
position: {
target: editingView.domConverter.viewToDom( editingView.selection.getSelectedElement() ),
positions: [
BalloonPanelView.defaultPositions.northArrowSouth,
BalloonPanelView.defaultPositions.southArrowNorth
]
}
} );
expect( positionData.position ).to.be.undefined;
} );
export function getBalloonPositionData( editor ) {
const editingView = editor.editing.view;
const defaultPositions = BalloonPanelView.defaultPositions;
const viewSelection = editingView.document.selection;
const parentTable = findAncestor( 'table', viewSelection.getFirstPosition() );
return {
target: editingView.domConverter.viewToDom( parentTable ),
positions: [
defaultPositions.northArrowSouth,
defaultPositions.northArrowSouthWest,
defaultPositions.northArrowSouthEast,
defaultPositions.southArrowNorth,
defaultPositions.southArrowNorthWest,
defaultPositions.southArrowNorthEast
]
};
}
export function getBalloonPositionData( editor ) {
const editingView = editor.editing.view;
const defaultPositions = BalloonPanelView.defaultPositions;
return {
target: editingView.domConverter.viewToDom( editingView.document.selection.getSelectedElement() ),
positions: [
defaultPositions.northArrowSouth,
defaultPositions.northArrowSouthWest,
defaultPositions.northArrowSouthEast,
defaultPositions.southArrowNorth,
defaultPositions.southArrowNorthWest,
defaultPositions.southArrowNorthEast
]
};
}
_attach() {
const editingView = this.editor.editing.view;
const defaultPositions = BalloonPanelView.defaultPositions;
this.attachTo( {
target: editingView.domConverter.viewToDom( editingView.selection.getSelectedElement() ),
positions: [ defaultPositions.northArrowSouth, defaultPositions.southArrowNorth ]
} );
}
}
export function getBalloonPositionData( editor ) {
const editingView = editor.editing.view;
const defaultPositions = BalloonPanelView.defaultPositions;
return {
target: editingView.domConverter.viewToDom( editingView.selection.getSelectedElement() ),
positions: [
defaultPositions.northArrowSouth,
defaultPositions.southArrowNorth
]
};
}
_getBalloonPositionData() {
const editingView = this.editor.editing.view;
const defaultPositions = BalloonPanelView.defaultPositions;
return {
target: editingView.domConverter.viewToDom( editingView.selection.getSelectedElement() ),
positions: [
defaultPositions.northArrowSouth,
defaultPositions.southArrowNorth
]
};
}
}