From 3b4c3385bf7152ab2caf7bd27fc6855a2bee0eed Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Mon, 24 May 2021 11:56:07 +0200 Subject: [PATCH] Feature: Introduced `mouseover` and `mouseout` events in `MouseObserver`. --- .../src/view/observer/mouseobserver.js | 2 +- .../tests/view/observer/mouseobserver.js | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-engine/src/view/observer/mouseobserver.js b/packages/ckeditor5-engine/src/view/observer/mouseobserver.js index 2286a953811..bb798b27e79 100644 --- a/packages/ckeditor5-engine/src/view/observer/mouseobserver.js +++ b/packages/ckeditor5-engine/src/view/observer/mouseobserver.js @@ -21,7 +21,7 @@ export default class MouseObserver extends DomEventObserver { constructor( view ) { super( view ); - this.domEventType = [ 'mousedown', 'mouseup' ]; + this.domEventType = [ 'mousedown', 'mouseup', 'mouseover', 'mouseout' ]; } onDomEvent( domEvent ) { diff --git a/packages/ckeditor5-engine/tests/view/observer/mouseobserver.js b/packages/ckeditor5-engine/tests/view/observer/mouseobserver.js index ff89843f660..0df5a4f7a95 100644 --- a/packages/ckeditor5-engine/tests/view/observer/mouseobserver.js +++ b/packages/ckeditor5-engine/tests/view/observer/mouseobserver.js @@ -23,7 +23,7 @@ describe( 'MouseObserver', () => { } ); it( 'should define domEventType', () => { - expect( observer.domEventType ).to.deep.equal( [ 'mousedown', 'mouseup' ] ); + expect( observer.domEventType ).to.deep.equal( [ 'mousedown', 'mouseup', 'mouseover', 'mouseout' ] ); } ); describe( 'onDomEvent', () => { @@ -52,5 +52,31 @@ describe( 'MouseObserver', () => { const data = spy.args[ 0 ][ 1 ]; expect( data.domTarget ).to.equal( document.body ); } ); + + it( 'should fire mouseover with the right event data', () => { + const spy = sinon.spy(); + + viewDocument.on( 'mouseover', spy ); + + observer.onDomEvent( { type: 'mouseover', target: document.body } ); + + expect( spy.calledOnce ).to.be.true; + + const data = spy.args[ 0 ][ 1 ]; + expect( data.domTarget ).to.equal( document.body ); + } ); + + it( 'should fire mouseout with the right event data', () => { + const spy = sinon.spy(); + + viewDocument.on( 'mouseout', spy ); + + observer.onDomEvent( { type: 'mouseout', target: document.body } ); + + expect( spy.calledOnce ).to.be.true; + + const data = spy.args[ 0 ][ 1 ]; + expect( data.domTarget ).to.equal( document.body ); + } ); } ); } );