/**
 * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
 */

import { EditingView } from '@ckeditor/ckeditor5-engine';
import { MouseEventsObserver } from '../../src/tablemouse/mouseeventsobserver.js';

describe( 'table selection', () => {
	describe( 'MouseEventsObserver', () => {
		let view, viewDocument, observer;

		beforeEach( () => {
			view = new EditingView();
			viewDocument = view.document;
			observer = view.addObserver( MouseEventsObserver );
		} );

		afterEach( () => {
			view.destroy();
		} );

		it( 'should define domEventTypes', () => {
			expect( observer.domEventType ).to.deep.equal( [
				'mousemove',
				'mouseleave'
			] );
		} );

		describe( 'onDomEvent', () => {
			for ( const eventName of [ 'mousemove', 'mouseleave' ] ) {
				it( `should fire ${ eventName } with the right event data`, () => {
					const spy = sinon.spy();

					viewDocument.on( eventName, spy );

					observer.onDomEvent( { type: eventName, target: document.body } );

					expect( spy.calledOnce ).to.be.true;

					const data = spy.args[ 0 ][ 1 ];
					expect( data.domTarget ).to.equal( document.body );
				} );
			}
		} );
	} );
} );
