<commit_before>var MVVM = require('mvvm');

function triggerEvent(target, evt, process) {
	var e = document.createEvent('HTMLEvents');
	e.initEvent(evt, true, true);

	if (process) {
		process(e);
	}

	target.dispatchEvent(e);
}


describe("v-on >", function() {
	var element;

	beforeEach(function() {
		element = document.createElement('div');
		document.body.appendChild(element);
	});

	afterEach(function() {
		document.body.removeChild(element);
	});


	it('normal', function() {
		var count = 0;
		var cb = function() {
			count++;
		}

		element.innerHTML = '<span id="el" v-on:click="test"></span>';

		var vm = new MVVM(element, {
			'test': cb
		});
		var el = element.querySelector('#el');

		triggerEvent(el, 'click');
		expect(count).toBe(1);

		triggerEvent(el, 'click');
		triggerEvent(el, 'click');
		triggerEvent(el, 'click');
		expect(count).toBe(4);
	});


	it('a propagation situation', function() {
		element.innerHTML =
			'<div id="outer" v-on:click="outer">' +
				'<span id="inner" v-on:click="inner"></span>' +
			'</div>'

		var outerCount = 0, innerCount = 0;
		var vm = new MVVM(element, {
			'outer': function() {
				outerCount++;
			},
			'inner': function() {
				innerCount++;
			}
		});
		var outer = element.querySelector('#outer');
		var inner = element.querySelector('#inner');

		triggerEvent(outer, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(0);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(2);
		expect(innerCount).toBe(1);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(3);
		expect(innerCount).toBe(2);

		triggerEvent(outer, 'click');
		triggerEvent(inner, 'click');
		expect(outerCount).toBe(5); // outer+1 and bubbling by inner+1, so is 5
		expect(innerCount).toBe(3);
	});


	it('use .stop to stopPropagation', function() {
		element.innerHTML =
			'<div id="outer" v-on:click="outer">' +
				'<span id="inner" v-on:click.stop="inner"></span>' +
			'</div>'

		var outerCount = 0, innerCount = 0;
		var vm = new MVVM(element, {
			'outer': function() {
				outerCount++;
			},
			'inner': function() {
				innerCount++;
			}
		});
		var outer = element.querySelector('#outer');
		var inner = element.querySelector('#inner');

		triggerEvent(outer, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(0);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(1);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(2);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(3);

		triggerEvent(outer, 'click');
		triggerEvent(inner, 'click');
		expect(outerCount).toBe(2);
		expect(innerCount).toBe(4);
	});


	it('a default situation', function() {
		element.innerHTML = '<a id="el" href="#abc" v-on:click="test"></a>';

		var hasPrevent;
		var vm = new MVVM(element, {<commit_msg>Update v-on spec for .self<commit_after>var MVVM = require('mvvm');

function triggerEvent(target, evt, process) {
	var e = document.createEvent('HTMLEvents');
	e.initEvent(evt, true, true);

	if (process) {
		process(e);
	}

	target.dispatchEvent(e);
}


describe("v-on >", function() {
	var element;

	beforeEach(function() {
		element = document.createElement('div');
		document.body.appendChild(element);
	});

	afterEach(function() {
		document.body.removeChild(element);
	});


	it('normal', function() {
		var count = 0;
		var cb = function() {
			count++;
		}

		element.innerHTML = '<span id="el" v-on:click="test"></span>';

		var vm = new MVVM(element, {
			'test': cb
		});
		var el = element.querySelector('#el');

		triggerEvent(el, 'click');
		expect(count).toBe(1);

		triggerEvent(el, 'click');
		triggerEvent(el, 'click');
		triggerEvent(el, 'click');
		expect(count).toBe(4);
	});


	it('a propagation situation', function() {
		element.innerHTML =
			'<div id="outer" v-on:click="outer">' +
				'<span id="inner" v-on:click="inner"></span>' +
			'</div>'

		var outerCount = 0, innerCount = 0;
		var vm = new MVVM(element, {
			'outer': function() {
				outerCount++;
			},
			'inner': function() {
				innerCount++;
			}
		});
		var outer = element.querySelector('#outer');
		var inner = element.querySelector('#inner');

		triggerEvent(outer, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(0);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(2);
		expect(innerCount).toBe(1);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(3);
		expect(innerCount).toBe(2);

		triggerEvent(outer, 'click');
		triggerEvent(inner, 'click');
		expect(outerCount).toBe(5); // outer+1 and bubbling by inner+1, so is 5
		expect(innerCount).toBe(3);
	});


	it('use .stop to stopPropagation', function() {
		element.innerHTML =
			'<div id="outer" v-on:click="outer">' +
				'<span id="inner" v-on:click.stop="inner"></span>' +
			'</div>'

		var outerCount = 0, innerCount = 0;
		var vm = new MVVM(element, {
			'outer': function() {
				outerCount++;
			},
			'inner': function() {
				innerCount++;
			}
		});
		var outer = element.querySelector('#outer');
		var inner = element.querySelector('#inner');

		triggerEvent(outer, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(0);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(1);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(2);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(3);

		triggerEvent(outer, 'click');
		triggerEvent(inner, 'click');
		expect(outerCount).toBe(2);
		expect(innerCount).toBe(4);
	});


	it('use .self to trigger event on self node', function() {
		element.innerHTML =
			'<div id="outer" v-on:click.self="outer">' +
				'<span id="inner" v-on:click="inner"></span>' +
			'</div>'

		var outerCount = 0, innerCount = 0;
		var vm = new MVVM(element, {
			'outer': function() {
				outerCount++;
			},
			'inner': function() {
				innerCount++;
			}
		});
		var outer = element.querySelector('#outer');
		var inner = element.querySelector('#inner');

		triggerEvent(outer, 'click');
		expect(outerCount).toBe(1);
		expect(innerCount).toBe(0);

		triggerEvent(inner, 'click');
		expect(outerCount).toBe(1); // if not set .self, here should be 2 becasue propagation
		expect(innerCount).toBe(1);
	});


	it('a default situation', function() {
		element.innerHTML = '<a id="el" href="#abc" v-on:click="test"></a>';

		var hasPrevent;
		var vm = new MVVM(element, {
{'fraction_non_alphanumeric': 0.1975157184480908, 'fraction_numerical': 0.009661094924091397, 'mean_word_length': 4.280971659919028, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, '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': '7543328', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2223, 'n_words': 438}