<commit_before>import AbstractEvent from '../src/lib/AbstractEvent';
import {expect} from 'chai';

describe('AbstractEvent', () =>
{
	describe('subclass', () =>
	{
		it('should be ok', () =>
		{
			expect('test').not.to.equal('foo');
		});
	});
});<commit_msg>Add unit tests for AbstractEvent<commit_after>import AbstractEvent from '../src/lib/AbstractEvent';
import {expect} from 'chai';
import IEvent from "../src/lib/IEvent";
import CallListenerResult from "../src/lib/CallListenerResult";

describe('AbstractEvent', () =>
{
	describe('#callListener', () =>
	{
		describe('with a listener that calls event.stopPropagation()', () =>
		{
			class TestEvent extends AbstractEvent {
				public clone():TestEvent
				{
					return new TestEvent(this.type, this.bubbles, this.cancelable);
				}
			}
			const event = new TestEvent('test');
			const handler = (event:IEvent) =>
			{
				event.stopPropagation();
			};
			const result = event.callListener(handler);

			it('should return CallListenerResult.PROPAGATION_STOPPED', () =>
			{
				expect(result).to.equal(CallListenerResult.PROPAGATION_STOPPED);
			});
		});
		describe('with a listener that calls event.stopImmediatePropagation()', () =>
		{
			class TestEvent extends AbstractEvent {
				public clone():TestEvent
				{
					return new TestEvent(this.type, this.bubbles, this.cancelable);
				}
			}
			const event = new TestEvent('test');
			const handler = (event:IEvent) =>
			{
				event.stopImmediatePropagation();
			};
			const result = event.callListener(handler);

			it('should return CallListenerResult.IMMEDIATE_PROPAGATION_STOPPED', () =>
			{
				expect(result).to.equal(CallListenerResult.IMMEDIATE_PROPAGATION_STOPPED);
			});
		});
		describe('with a listener that calls event.stopPropagation() and event.stopImmediatePropagation()', () =>
		{
			class TestEvent extends AbstractEvent {
				public clone():TestEvent
				{
					return new TestEvent(this.type, this.bubbles, this.cancelable);
				}
			}
			const event = new TestEvent('test');
			const handler = (event:IEvent) =>
			{
				event.stopImmediatePropagation();
				event.stopPropagation();
			};
			const result = event.callListener(handler);

			it('should return CallListenerResult.IMMEDIATE_PROPAGATION_STOPPED', () =>
			{
				expect(result).to.equal(CallListenerResult.IMMEDIATE_PROPAGATION_STOPPED);
			});
		});
		describe('with a listener that doesn\'t call event.stopPropagation() or event.stopImmediatePropagation()', () =>
		{
			class TestEvent extends AbstractEvent {
				public clone():TestEvent
				{
					return new TestEvent(this.type, this.bubbles, this.cancelable);
				}
			}
			const event = new TestEvent('test');
			const handler = () => {};
			const result = event.callListener(handler);

			it('should return CallListenerResult.NONE', () =>
			{
				expect(result).to.equal(CallListenerResult.NONE);
			});
		});
	});

	describe('#preventDefault()', () =>
	{
		describe('on a cancellable event', () =>
		{
			class TestEvent extends AbstractEvent {
				public clone():TestEvent
				{
					return new TestEvent(this.type, this.bubbles, this.cancelable);
				}
			}
			const event = new TestEvent('test', false, true);

			it('should set defaultPrevented to true', () =>
			{
				event.preventDefault();
				expect(event.defaultPrevented).to.be.true;
			});
		});
		describe('on a non-cancellable event', () =>
		{
			class TestEvent extends AbstractEvent {
				public clone():TestEvent
				{
					return new TestEvent(this.type, this.bubbles, this.cancelable);
				}
			}
			const event = new TestEvent('test', false, false);

			it('should throw an error', () =>
			{
				expect(() => event.preventDefault()).to.throw(Error);
			});
		});
	});

});
{'fraction_non_alphanumeric': 0.1517520215633423, 'fraction_numerical': 0.0, 'mean_word_length': 3.715374841168996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7429236', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1138, 'n_words': 224}